Skip to content

Keep the account's checkout attributes when merging a guest cart at login - #935

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/login-merge-checkout-attributes
Oct 17, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/login-merge-checkout-attributes

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

When a customer logs in, ShoppingCartService.MigrateShoppingCart moves the guest cart onto the account and always overwrote the account's CheckoutAttributes user field with the guest's, even when the guest had none. Logging in from a fresh browser (or after clearing cookies) therefore cleared a saved checkout choice such as gift wrapping, and the next order showed "Gift wrapping: No".

To reproduce on develop:

  1. Log in, add a product to the cart, select a checkout attribute (e.g. gift wrapping = Yes), log out.
  2. Open a new private window and log in as the same customer.
  3. Open the cart: the checkout attribute is back to its default.

Solution

The guest's checkout attributes for the store move only when the guest has selected some. A guest with none leaves the account's own attributes untouched. When both have attributes, the guest's selection wins as before: it is the most recent one, while the account's stored attributes are only cleared when an order is placed and may come from a long-abandoned cart. Cart items and coupon codes are merged as before.

Breaking changes

None. The signature of MigrateShoppingCart is unchanged.

Testing

  1. Unit tests: dotnet test src/Tests/Grand.Business.Checkout.Tests (new cases in ShoppingCartServiceTests: empty guest keeps the account's attributes, guest's attributes replace the account's, attributes in another store don't block the move).
  2. Manual: follow the reproduce steps above; after step 3 the saved choice is still selected.
  3. Manual: as a guest, select a checkout attribute, then log in to an account; the guest's choice is carried over.

…ogin

MigrateShoppingCart always wrote the guest's checkout attributes onto the account, even when the guest had none, so logging in from a fresh browser cleared a saved choice such as gift wrapping. The guest's attributes now move only when the guest has some and the account has none in that store.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The account's stored checkout attributes are only cleared when an order is placed, so they can come from a cart abandoned long ago or point at attributes that no longer apply. Keeping them over a selection the customer just made as a guest applied stale choices to the order. The guest's selection now always moves when it has one; the account keeps its own only when the guest has none, which is what the login-from-a-fresh-browser case needs.

The tests register the type converters once per class and build stored values through the shipped converter.
@KrzysztofPajak
KrzysztofPajak merged commit bb78c53 into develop Oct 17, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/login-merge-checkout-attributes branch October 17, 2026 04:43
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.

2 participants