From b6beadb72c27d49eb54f11e6a504c156d9d4e8f2 Mon Sep 17 00:00:00 2001 From: Jesse Grant Date: Mon, 14 Jan 2013 16:51:14 -0500 Subject: [PATCH] made changes to Order model to reflect the fact that a site may use the new payment options component, resulting in orders of various dollar amounts, so revenue and goal percentage must be calculated differently --- app/models/order.rb | 11 +++++++---- app/models/payment_option.rb | 1 + app/views/preorder/homepage/_stats.html.erb | 6 +++--- config/settings.yml | 6 ++++-- spec/models/order_spec.rb | 6 +++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 24385e9..07b0193 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -54,22 +54,25 @@ class Order < ActiveRecord::Base end while Order.find_by_uuid(self.uuid).present? end - # Implement these three methods to + # goal is a dollar amount, not a number of backers, beause you may be using the multiple payment options component + # by setting Settings.use_payment_options == true def self.goal Settings.project_goal end def self.percent - (Order.current.to_f / Order.goal.to_f) * 100.to_f + (Order.revenue.to_f / Order.goal.to_f) * 100.to_f end # See what it looks like when you have some backers! Drop in a number instead of Order.count - def self.current + def self.backers Order.where("token != ? OR token != ?", "", nil).count end def self.revenue - Order.current.to_f * Settings.price + revenue = PaymentOption.joins(:orders).pluck('sum(amount)')[0] + return 0 if revenue.nil? + revenue end validates_presence_of :name, :price, :user_id diff --git a/app/models/payment_option.rb b/app/models/payment_option.rb index 7faf458..0904697 100644 --- a/app/models/payment_option.rb +++ b/app/models/payment_option.rb @@ -1,3 +1,4 @@ class PaymentOption < ActiveRecord::Base attr_accessible :amount, :amount_display, :delivery_desc, :description, :limit, :shipping_desc + has_many :orders end diff --git a/app/views/preorder/homepage/_stats.html.erb b/app/views/preorder/homepage/_stats.html.erb index dca0ba1..3fd852e 100644 --- a/app/views/preorder/homepage/_stats.html.erb +++ b/app/views/preorder/homepage/_stats.html.erb @@ -20,12 +20,12 @@
- <% if Order.current < Order.goal %> + <% if Order.revenue < Order.goal %>
diff --git a/config/settings.yml b/config/settings.yml index fd2e4d5..f35bcf5 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -5,8 +5,10 @@ # You should totally change the HTML and CSS though # Checkout app/assets/stylesheets/variables.css.scss to change around the CSS quickly -# Set your project goal here - if you manually want to adjust your progress to test the site, head over to the Order model (app/models/order.rb) -project_goal: 100 +# Set your project goal here - dollar amount +# NOTE: if you manually want to adjust your progress to test the site, head over to the Order model (app/models/order.rb) +project_goal: 100000 + # If you want to edit the FAQ, head over to app/views/preorder/homepage/_faqs.html.erb # This'll be both the page title () and the name in the header diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 1bd2655..2f40abf 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -184,14 +184,14 @@ describe Order do end end - describe ".current" do + describe ".backers" do it "returns the number of orders with valid token / that have been postfilled" do Order.delete_all order = Order.prefill!(name: 'marin', user_id: 1, price: 123.21) - Order.current.should == 0 + Order.backers.should == 0 Order.postfill!(callerReference: order.uuid, tokenID: '1232', expiry: '2015-12-24') - Order.current.should == 1 + Order.backers.should == 1 end end