Skip to content

Instantly share code, notes, and snippets.

@simmsy
Last active August 29, 2015 14:14
Show Gist options
  • Save simmsy/a6b94cd5ca802a0bc9e6 to your computer and use it in GitHub Desktop.
Save simmsy/a6b94cd5ca802a0bc9e6 to your computer and use it in GitHub Desktop.
#https://github.com/spree/spree/blob/master/core/app/models/spree/stock/coordinator.rb#L32:L40
def build_packages(packages = Array.new)
StockLocation.active.each do |stock_location|
next unless stock_location.stock_items.where(:variant_id => inventory_units.map(&:variant_id).uniq).exists?
packer = build_packer(stock_location, inventory_units)
packages += packer.packages
end
packages
end
# refactored to
def build_packages(packages = Array.new)
# OR StockLocation.for_variant_ids(inventory_units.map(&:variant_id).uniq)
StockLocation.active.joins(:stock_items).merge(StockItems.where(:variant_id => inventory_units.map(&:variant_id).uniq).each do |stock_location|
packer = build_packer(stock_location, inventory_units)
packages += packer.packages
end
packages
end
@simmsy
Copy link
Author

simmsy commented Feb 5, 2015

Yes mate, add to core please

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