-
Notifications
You must be signed in to change notification settings - Fork 4
fix: add to cart support for other regions #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes Add to Cart functionality for non-US store views (e.g., /ca/fr_ca/) by implementing store-specific localStorage keys while preserving backward compatibility for the US store. The fix addresses issues where cart data was being shared across all store views and hardcoded paths were preventing proper cart operations in non-US regions.
Changes:
- Introduced store-specific localStorage keys for cart isolation (e.g.,
mage-cache-storage-ca-fr_cafor Canadian French) - Dynamically constructed locale/language paths in URLs for add-to-cart and affiliate coupon endpoints
- Added comprehensive test coverage for cart storage isolation across different store views
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| tests/cart/storage.spec.js | New comprehensive test suite verifying store-specific localStorage keys, cart isolation, and GraphQL Store header correctness |
| scripts/storage/util.js | Core implementation of store-specific localStorage key generation with helper functions, replacing hardcoded constants |
| scripts/scripts.js | Updated affiliate coupon URL to use dynamic locale/language instead of hardcoded /us/en_us/ |
| scripts/minicart/cart.js | Updated legacy add-to-cart URL construction to use dynamic locale/language, reducing code duplication |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (cartData && cartData['side-by-side']) { | ||
| expect(cartData['side-by-side'].cart_id).toBe('us-cart-abc123'); | ||
| console.log('✓ US cart stored in mage-cache-storage with correct cart_id'); | ||
| } |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test checks if cartData exists and has the expected cart_id, but if cartData is null or doesn't have the 'side-by-side' property, the test silently passes without asserting anything. Consider adding an assertion that cartData is not null before the conditional check, or restructure the test to fail if the expected data is not present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I restructured the test to fail if the expected data is not present.
| // Wait for the cart redirect or network request | ||
| await page.waitForTimeout(2000); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using page.waitForTimeout with hardcoded delays (2000ms) is generally considered an anti-pattern in Playwright tests. It makes tests slower and can lead to flaky tests. Consider using waitForResponse, waitForRequest, or waitForSelector with specific conditions instead.
| // Wait for the cart redirect or network request | |
| await page.waitForTimeout(2000); | |
| // Wait until mage-cache-storage has a side-by-side entry (up to 2000ms) | |
| await page | |
| .waitForFunction(() => { | |
| const storage = localStorage.getItem('mage-cache-storage'); | |
| if (!storage) return false; | |
| try { | |
| const data = JSON.parse(storage); | |
| return !!data['side-by-side']; | |
| } catch { | |
| return false; | |
| } | |
| }, { timeout: 2000 }) | |
| .catch(() => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I agree this is better or makes the test easier to reason about.. If the test becomes flaky and problem (which it's not) I will reconsider.
| JSON.stringify((new Date(new Date().getTime() + minutesToExpire * 60000)).toISOString()), | ||
| ); | ||
| window.dispatchEvent(new StorageEvent('storage', { key: COMMERCE_CACHE_STORAGE_KEY })); | ||
| window.dispatchEvent(new StorageEvent('storage', { key: cacheStorageKey })); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous arguments passed to function StorageEvent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's incorrect @Copilot.. These are valid arguments
https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent/StorageEvent
Also, why did you link go to the first pull request? ;)
Summary
/ca/fr_ca/) by using store-specific localStorage keys.mage-cache-storagekey for/us/en_us/.Problem
Add to Cart was failing on non-US stores because:
/us/en_us/paths in legacy add-to-cart and affiliate coupon URLsen_us. The commerce backend was receiving the wrong store context for non-US storesSolution
Store-specific localStorage keys
/us/en_us/->mage-cache-storage(unchanged)/ca/fr_ca/->mage-cache-storage-ca-fr_ca/ca/en_us/->mage-cache-storage-ca-en_usThis applies to all three Magento cache keys:
mage-cache-storage,mage-cache-timeout, andmage-cache-storage-section-invalidation.Dynamic locale/language in URLs
/${locale}/${language}/checkout/cart/add/...locale/languageWhy this won't break the US store
No hardcoded keys remain - All localStorage access goes through helper functions that respect the store-specific logic
Existing US carts preserved - US store continues using mage-cache-storage, so existing cart data is untouched
Test URLs: