Skip to content

Commit

Permalink
extended best_sellers to take a date range as args
Browse files Browse the repository at this point in the history
defaults to start one week ago, finish now
  • Loading branch information
paulcc committed Feb 27, 2009
1 parent b7e34bb commit e9f7c30
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/promotions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ def self.random_subset(n)
promos.map {|p| p.product }
end

def self.best_sellers(n)
def self.best_sellers(n, start = 1.week.ago, finish = Time.now)
# most ordered items
# looks for completed orders from past week, then gets top N sellers by quantity
# looks for completed orders from date range (default: the past week)
# then gets top N sellers by quantity
# query: need to filter out cancelled orders?
best_n = Order.checkout_completed(true).
between(1.week.ago,Time.now).
between(start,finish).
find(:all,
:joins => "INNER JOIN line_items ON orders.id = line_items.order_id",
:select => "variant_id, SUM (quantity) sum",
Expand Down

0 comments on commit e9f7c30

Please sign in to comment.