Skip to content

Instantly share code, notes, and snippets.

@suderman
Created August 8, 2013 20:43
Show Gist options
  • Save suderman/6188518 to your computer and use it in GitHub Desktop.
Save suderman/6188518 to your computer and use it in GitHub Desktop.
# Login to shopify console and copy-paste the following script:
order_count = ShopifyAPI::Order.count
nb_pages = (order_count / 250.0).ceil
# Looking for orders with only these products
PRODUCT_IDS = [144760487, 144107049]
# 10 minutes times 60 seconds per minute.
CYCLE = 5 * 60
# Initializing.
start_time = Time.now
1.upto(nb_pages) do |page|
unless page == 1
stop_time = Time.now
puts "Current batch processing started at #{start_time.strftime('%I:%M%p')}"
puts "The time is now #{stop_time.strftime('%I:%M%p')}"
processing_duration = stop_time - start_time
puts "The processing lasted #{processing_duration.to_i} seconds."
wait_time = (CYCLE - processing_duration).ceil
puts "We have to wait #{wait_time.to_i} seconds then we will resume."
sleep wait_time
start_time = Time.now
end
puts "Doing page #{page}/#{nb_pages}..."
orders = ShopifyAPI::Order.find( :all, :params => { :limit => 250, :page => page } )
orders.each do |order|
skip = false
if order.fulfillment_status == "fulfilled"
skip = true
else
order.line_items.each do |line_item|
if PRODUCT_IDS.include? line_item.product_id
skip = false
else
skip = true
break
end
end
end
if skip
# puts "Order #{order.id} doesn't qualify!!"
else
f = ShopifyAPI::Fulfillment.new(:order_id => order.id)
f.prefix_options = { :order_id => order.id }
f.save
puts "Order #{order.id} has been fulfilled"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment