Created
December 1, 2010 20:06
-
-
Save resistorsoftware/724124 to your computer and use it in GitHub Desktop.
sum up orders for Shopify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sum = 0.0 | |
| page = 1 | |
| start_date = "2010-11-11" | |
| end_date = "2010-12-11" | |
| count = ShopifyAPI::Order.count({:fulfillment_status => 'unshipped', :created_at_max => "#{end_date} 23:59", :created_at_min => "#{start_date} 00:00"}) | |
| if count > 0 | |
| page += count.divmod(250).first | |
| while page > 0 | |
| orders = ShopifyAPI::Order.find(:all, :params => {:page => page, :fulfillment_status => 'unshipped', :limit => 250, :created_at_max => "#{end_date} 23:59", :created_at_min => "#{start_date} 00:00", :financial_status => 'paid'}) | |
| orders.each do |order| | |
| order.line_items.each do |item| | |
| sum += item.price.to_f | |
| end | |
| page -= 1 | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mcapewell,
Thx.. I ripped this out of some app with other things on my mind... then edited it for the "gist" and not to "run" as is.. obviously I messed up my quickie edit...
@vgkids, Shopify only gives you 250 at a time. So if you had 1000 orders... you'd want 4 pages of 250. The divmod is one cheesy way to get the number of pages. I am sure there are more elegant ways.