Skip to content

fix(#310): merge reordered one-time items by normalizing empty subscription option - #311

Open
chrismshea wants to merge 1 commit into
mainfrom
fix/310-reorder-onetime-merge
Open

fix(#310): merge reordered one-time items by normalizing empty subscription option#311
chrismshea wants to merge 1 commit into
mainfrom
fix/310-reorder-onetime-merge

Conversation

@chrismshea

Copy link
Copy Markdown

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::compareOptions decided mergeability by the subscription_option value in info_buyRequest. A freshly reordered item's raw buyRequest has no subscription_option key, while Plugin\Sales\Model\Reorder\ReorderPlugin stamps option=onetime_purchase onto items in afterExecute — i.e. after Magento\Sales\Model\Reorder\Reorder::execute has already run the merge comparison and persisted the item.

On the second reorder, the persisted item carries option=onetime_purchase while the incoming item is still unstamped (null), so compareOptions returns "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 no subscription_option at all and merged as equal-empty.

Fix

Normalize a missing/empty subscription option to onetime_purchase before comparing. An item with no subscription option is semantically a one-time purchase. This makes merge behavior independent of the afterExecute stamping order and also covers the controller reorder path (AbstractController\Reorder) that ReorderPlugin doesn't hook, plus repeated PLP/PDP one-time adds.

Genuine subscription-vs-one-time and interval mismatches are unaffected.

Tests

  • All 6 existing ItemTest data-provider cases still pass under the new logic.
  • Added a regression case: stamped onetime_purchase item vs unstamped item (no subscription_option key) → must merge.

Verification

  • vendor/bin/phpunit Test/Unit/Plugin/Quote/ItemTest.php green
  • Manual: place a one-time order → Reorder twice from My Orders → one merged line item (qty incremented), not two
  • Manual: add a subscription-enabled product as one-time from PDP/PLP repeatedly → merges
  • Regression: subscription add + interval selection still behaves as before

…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).
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 this pull request may close these issues.

Duplicate cart line items when reordering a one-time item (compareOptions asymmetry with ReorderPlugin)

1 participant