Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree::Order.register_line_item_comparison_hook not implemented for Spree::Stock::Coordinator #8621

Open
sringling opened this issue Feb 20, 2018 · 0 comments · May be fixed by #11932
Open

Comments

@sringling
Copy link

sringling commented Feb 20, 2018

There is a feature to differentiate line items beyond only variant_id, useful if you add additional attributes to a line item that you want to make the same variant_id into a distinctive line item. However, that functionality is not extended into Spree::Stock::Coordinator.

Context

When using Spree::Order.register_line_item_comparison_hook to differentiate line items, on the delivery page of checkout, one of the line items will not be visible on the page because it won't be in the shipment. It isn't in the shipment because Spree::Stock::Coordinator "de-dupes" its InventoryUnits by index_by(&:variant_id), without taking into account additional comparators provided to spree via Spree::Order.register_line_item_comparison_hook.

Expected Behavior

When using Spree::Order.register_line_item_comparison_hook, line items are separate when those comparison hooks say they are separate, and are always treated as such. The checkout flow would always show 2+ items even for the same variant id on all pages when any hook has differentiated them.

Actual Behavior

The delivery page is missing items which have the same variant_id but which were treated as separate line items.

Possible Fix

All hooks provided to Spree::Order.register_line_item_comparison_hook should be taken into account in the Spree::Stock::Coordinator, so instead of simply doing index_of(&:variant_id) we should use the variant_id and use those comparators as well.

Additionally, Spree::Stock::Adjuster also will eliminate one of the line items with the same variant_id, because @adjusters is retained between InventoryUnits in Spree::Stock::Prioritizer, hashing by the result of hash_item(item) and again not taking into account things registered via Spree::Order.register_line_item_comparison_hook.

Steps to Reproduce

  1. Add a line item comparator using Spree::Order.register_line_item_comparison_hook
  2. Add two of the same variant_id to the cart, where the variants are differentiated based on a comparison hook you provided (for example, add my_custom_id to spree_line_items then add Spree::Order.register_line_item_comparison_hook(:same_custom_ids?)
  3. Go through checkout to delivery page
  4. Observe only one of the two line items you added listed

Your Environment

  • Version used: 3.4.4
@Tashows Tashows linked a pull request Sep 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants