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 @@
-
- <%= number_with_delimiter Order.current, :delimiter => "," %>
+ <%= number_with_delimiter Order.backers, :delimiter => "," %>
<%= Settings.primary_stat %>
-
<%= number_to_currency Order.revenue, :precision => 0 %>
- of <%= number_to_currency Settings.project_goal.to_f * Settings.price.to_f, :precision => 0 %>
+ of <%= number_to_currency Settings.project_goal.to_f, :precision => 0 %>
<% if Settings.expiration_date.present? %>
@@ -41,7 +41,7 @@
<% end %>
- <% 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