Last active
August 29, 2015 14:14
-
-
Save simmsy/a6b94cd5ca802a0bc9e6 to your computer and use it in GitHub Desktop.
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
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes mate, add to core please