Repository navigation
fix(storefront): STRF-14923 Persist lang selector with items in cart - #2750
Jwatzkin77 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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; |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit abec23f. Configure here.


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)gqlTokeninject, right after thecartIdinject on line 42assets/js/theme/global.js(lines 8, 19, 24)cartLocaleSwitcherimport (8)gqlTokenin thethis.contextdestructuring (19)languageSelector()(24)assets/js/theme/global/language-selector.js(lines 34–78)updateCartLocale()(45)cartLocaleSwitcher()(60)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
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
gqlTokenso global init can run a newcartLocaleSwitcheralongside the existing language selector.On clicks of language links that carry
data-warning(locale switch warning), the handler calls the Storefront GraphQLupdateCartLocalemutation with the currentcartId, 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.