Skip to content

fix(storefront): STRF-14923 Persist lang selector with items in cart - #2750

Open
Jwatzkin77 wants to merge 2 commits into
masterfrom
STRF-14923
Open

Jwatzkin77 wants to merge 2 commits into
masterfrom
STRF-14923

Conversation

@Jwatzkin77

@Jwatzkin77 Jwatzkin77 commented Nov 11, 2026 •

Copy link
Copy Markdown

What?

Currently the cart locale selector in stencil storefronts does not update the cart locale/language once a single item is in the cart. This is a recommended resolution to fix that behavior

Requirements

  • [ - templates/layout/base.html (line 43)

    • The gqlToken inject, right after the cartId inject on line 42
  • assets/js/theme/global.js (lines 8, 19, 24)

    • The cartLocaleSwitcher import (8)
    • gqlToken in the this.context destructuring (19)
    • The call after languageSelector() (24)
  • assets/js/theme/global/language-selector.js (lines 34–78)

    • The mutation string (35)
    • updateCartLocale() (45)
    • The exported cartLocaleSwitcher() (60)
    • The click handler on the a[data-locale-code][data-warning] links, starting at line 63 ] CHANGELOG.md entry added (required for code changes only)

Tickets / Documentation

Screenshots (if appropriate)

EN_IT.mov

Example Image

IT_EN.mov

Note

Medium Risk
Adds client-side GraphQL cart mutations using an injected Storefront API token; failed updates are ignored while navigation still proceeds, which could briefly desync cart locale from the selected language.

Overview
Persists the cart locale when shoppers change language while the cart has items. The layout now injects gqlToken so global init can run a new cartLocaleSwitcher alongside the existing language selector.

On clicks of language links that carry data-warning (locale switch warning), the handler calls the Storefront GraphQL updateCartLocale mutation with the current cartId, then redirects to the switch URL even if the request fails so the UI never blocks the language change.

Reviewed by Cursor Bugbot for commit a1a547e. Bugbot is set up for automated code reviews on this repo. Configure here.

@Jwatzkin77
Jwatzkin77 requested a review from a team as a code owner November 11, 2026 20:56

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit abec23f. Configure here.

* Updates the active cart's locale before following a language switch link
*/
export function cartLocaleSwitcher(cartId, token) {
if (!cartId) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cart locale not updated after add-to-cart

Medium Severity

cartLocaleSwitcher returns immediately when cartId is missing at page load, and it is only invoked from Global.onReady. After an AJAX add-to-cart, currencySelector is re-initialized with the new cart ID, but cartLocaleSwitcher is not, so the cart locale is not persisted if the shopper switches language on the same page.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit abec23f. Configure here.

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.

Can this situation realistically happen?

const { href } = event.currentTarget;
const locale = $(event.currentTarget).data('locale-code');

// Navigate regardless of the outcome so a failed update never blocks the switch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i like the idea, but it doesnt look like this has neither a timeout nor a loading state? looks like a slow request would just look like a frozen page that would sit indefinitely and with no ux

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.

@rtalvarez I'm not sure a loading state is really needed, because when you switch the locale via the switcher, the page already navigates/refreshes. This updateCartLocale call just happens in the background so that when the page finishes refreshing, the cart has the correct locale

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The language switcher remains uninitialized after the first AJAX cart addition, so switching languages leaves the cart locale unchanged.

1 open issue
What changed in this PR

This PR aims to persist the cart’s locale when shoppers change storefront language with items already in the cart.

Changes:

  • Injects the Storefront API token into the page context.
  • Initializes a cart locale switcher alongside the existing language selector.
  • Attempts a GraphQL locale update before navigation, proceeding even if the request fails.
File Description
templates/​layout/​base.html Exposes the Storefront API token to JavaScript.
assets/​js/​theme/​global/​language-selector.js Adds the cart locale mutation and language-link handler.
assets/​js/​theme/​global.js Initializes the switcher with the cart ID and API token.

Review effort: Balanced

* Updates the active cart's locale before following a language switch link
*/
export function cartLocaleSwitcher(cartId, token) {
if (!cartId) return;
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.

5 participants