Skip to content

Instantly share code, notes, and snippets.

@jsqu99
Created August 29, 2014 19:52
Show Gist options
  • Save jsqu99/29164a082d2dfa3aed9b to your computer and use it in GitHub Desktop.
Save jsqu99/29164a082d2dfa3aed9b to your computer and use it in GitHub Desktop.
def process_monthly_crates(crate_date=DateTime.now)
# find the appropriate spree variant for this date / tshirt size. There could be more than one.
# let's create a hash of available variants and their available inventory
variants = {}
all_active_subscriptions = # find in batches
all_active_subscriptions.each do |sub|
begin
period=sub.current_period
end while !period.active? || period.nil?
if period
# we have an active period
# grab from the variants hash above and update the available quantiy. when it reaches 0, remove it from the hash and use the next key in the hash.
# in other words, if I have 100,000 of one sku, and 50,000 of another, run through 100,000 of one first
variant = #
sub_unit = period.subscription_units.create!(variant_id: variant.id)
# create a json represenation of this sub_unit and push it to wombat
# this will make use of some method i have laying around that generates a specific order # (see OrderNumberGenerator in lib/spree for the way it should work)
else
# this is an error condition - an active subscription w/ no active periods
# TODO: handle this
end
end
end
@jsqu99
Copy link
Author

jsqu99 commented Sep 1, 2014

I'd say this could/should be amended to accept the list of skus for "this month" (see comments ins https://lootcrate.atlassian.net/browse/LC-294)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment