fix(#310): merge reordered one-time items by normalizing empty subscription option - #311
Open
chrismshea wants to merge 1 commit into
Open
fix(#310): merge reordered one-time items by normalizing empty subscription option#311chrismshea wants to merge 1 commit into
chrismshea wants to merge 1 commit into
Conversation
…iption option compareOptions keyed mergeability on the subscription_option value, treating an item with no option as distinct from one stamped option=onetime_purchase. On a second reorder, the persisted item (stamped by ReorderPlugin::afterExecute) was compared against a fresh, unstamped item, so they failed to merge and a duplicate line item was created. Normalize a missing/empty subscription option to onetime_purchase before comparing. This makes merge behavior independent of afterExecute stamping order and also covers the controller reorder path and repeated PLP/PDP one-time adds. Genuine subscription-vs-one-time and interval mismatches are unaffected. Adds a regression test case (stamped one-time vs unstamped item -> merge).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #310
Problem
Reordering the same one-time product twice from My Account → My Orders creates two separate quote line items instead of merging. Same duplicate-row behavior occurs when adding a subscription-enabled product as a one-time purchase from PLP/PDP repeatedly.
Root cause
Plugin\Quote\Item::compareOptionsdecided mergeability by thesubscription_optionvalue ininfo_buyRequest. A freshly reordered item's raw buyRequest has nosubscription_optionkey, whilePlugin\Sales\Model\Reorder\ReorderPluginstampsoption=onetime_purchaseonto items inafterExecute— i.e. afterMagento\Sales\Model\Reorder\Reorder::executehas already run the merge comparison and persisted the item.On the second reorder, the persisted item carries
option=onetime_purchasewhile the incoming item is still unstamped (null), socompareOptionsreturns "not equal" and Magento creates a new line item. This is a regression introduced alongside #191 (ReorderPlugin, 1.7.0); before it, reordered items had nosubscription_optionat all and merged as equal-empty.Fix
Normalize a missing/empty subscription option to
onetime_purchasebefore comparing. An item with no subscription option is semantically a one-time purchase. This makes merge behavior independent of theafterExecutestamping order and also covers the controller reorder path (AbstractController\Reorder) thatReorderPlugindoesn't hook, plus repeated PLP/PDP one-time adds.Genuine subscription-vs-one-time and interval mismatches are unaffected.
Tests
ItemTestdata-provider cases still pass under the new logic.onetime_purchaseitem vs unstamped item (nosubscription_optionkey) → must merge.Verification
vendor/bin/phpunit Test/Unit/Plugin/Quote/ItemTest.phpgreen