forked from spree-contrib/spree-product-assembly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes the issue with the prioritizer not taking the line item in…
…to consideration
- Loading branch information
1 parent
e13f419
commit a71f37d
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Spree | ||
module Stock | ||
module PackerDecorator | ||
# Overriding the default packager | ||
def default_package | ||
package = Package.new(stock_location) | ||
|
||
# Group by variant_id as grouping by variant fires cached query. | ||
inventory_units.index_by do |unit| | ||
{ variant_id: unit.variant_id, line_item_id: unit.line_item_id } | ||
end.each do |indices, inventory_unit| | ||
variant = Spree::Variant.find(indices[:variant_id]) | ||
unit = inventory_unit.dup # Can be used by others, do not use directly | ||
|
||
if variant.should_track_inventory? | ||
next unless stock_location.stocks? variant | ||
|
||
on_hand, backordered = stock_location.fill_status(variant, unit.quantity) | ||
package.add(InventoryUnit.split(unit, backordered), :backordered) if backordered.positive? | ||
package.add(InventoryUnit.split(unit, on_hand), :on_hand) if on_hand.positive? | ||
else | ||
package.add unit | ||
end | ||
end | ||
|
||
package | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::Stock::Packer.prepend Spree::Stock::PackerDecorator |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Spree | ||
module Stock | ||
module PrioritizerDecorator | ||
def hash_item(item) | ||
shipment = item.inventory_unit.shipment | ||
variant = item.inventory_unit.variant | ||
line_item = item.inventory_unit.line_item | ||
|
||
hash = if shipment.present? | ||
variant.hash ^ shipment.hash | ||
else | ||
variant.hash | ||
end | ||
|
||
hash ^ line_item.hash if line_item.present? | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::Stock::Prioritizer.prepend Spree::Stock::PrioritizerDecorator |
This file contains 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