Open johnboxall opened 1 year ago
Thanks for submitting this @johnboxall . I've added a ticket in the backlog for fixing this
Based on the discussion here https://sfcc-unofficial.slack.com/archives/CBB7YAAHW/p1676628824576879 and the response I got from SFCC Support, the OCAPI baskets endpoints do not respect the locale
parameter.
The relevant case number is 44187657.
What we did (maybe there's a better approach) is modify useBasket
's _productItemsDetail
into a localized object.
What we changed::
// import useMultiSite hook
// import {merge} from 'lodash-es'
......
export default function useBasket(opts = {}) {
...
const {locale} = useMultiSite()
.....
get _productItemsDetail() {
return basket?._productItemsDetail?.[locale]
},
.....
async getProductsInBasket(ids, options) {
.....
const newData = {
[locale]: itemDetail
}
const updatedBasket = {
...basket,
_productItemsDetail: merge(basket._productItemsDetail, newData)
}
.....
.....
Then getProductsInBasket
should run whenever the locale is changed (this is done for us by the OOTB useShooper
hook but our country selection logic may differ since our locale change is all done single page).
shopperProducts
in commerce-api/index
should also be configured to send the locale in API calls.
Currently, OCAPI calls to
baskets
do not include thelocale
parameter.In multi-locale sites, guests browsing a non-default locale will see incorrectly localized product descriptions when looking at their basket.
To reproduce:
Expect product details in German, but observe they are in English:
This issue also likely impacts
OcapiShopperOrders
, which may result in order confirmation emails being sent using the wrong locale.To resolve, we'll likely need to include
locale
information in all OCAPI basket calls: https://github.com/SalesforceCommerceCloud/pwa-kit/blob/a0c629acf3b64e680c04956cc145eafbea81b211/packages/template-retail-react-app/app/commerce-api/ocapi-shopper-baskets.js