@graphcommerce/magento-store 10.0.1-canary.0 → 10.0.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/components/StoreSwitcher/StoreSwitcherStoreSelector.tsx +0 -4
- package/components/StoreSwitcher/useStoreSwitcher.tsx +5 -1
- package/components/StoreSwitcherButton/StoreSwitcherFab.tsx +14 -10
- package/components/StoreSwitcherButton/useStoreSwitcherButton.ts +10 -4
- package/package.json +10 -10
- package/plugins/magentoStoreGraphqlConfig.ts +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 10.0.1-canary.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2571](https://github.com/graphcommerce-org/graphcommerce/pull/2571) [`d9c7545`](https://github.com/graphcommerce-org/graphcommerce/commit/d9c754570cd04da61ee3282bde465cc33395c8d9) - When switching stores unset the currency when there is no selection available for a given store. ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
- [#2571](https://github.com/graphcommerce-org/graphcommerce/pull/2571) [`6d5ff59`](https://github.com/graphcommerce-org/graphcommerce/commit/6d5ff59090b5fe37bf053a2540fcf13150331a27) - Do not send an unacceptable store currency due to a configuration error and make sure the correct currency is stored. Show a StoreSwitcherFab on mobile. ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
3
11
|
## 10.0.1-canary.0
|
|
4
12
|
|
|
5
13
|
## 10.0.0
|
|
@@ -52,10 +52,6 @@ export function StoreSwitcherStoreSelector(props: StoreSwitcherSelectorProps) {
|
|
|
52
52
|
),
|
|
53
53
|
value: store.store_code,
|
|
54
54
|
disabled: store.disabled,
|
|
55
|
-
slotProps: {
|
|
56
|
-
title: { sx: { typography: 'subtitle1' } },
|
|
57
|
-
details: { sx: { typography: 'body1', color: 'text.secondary' } },
|
|
58
|
-
},
|
|
59
55
|
}))}
|
|
60
56
|
{...actionCardProps}
|
|
61
57
|
/>
|
|
@@ -190,8 +190,12 @@ export function StoreSwitcherFormProvider(props: StoreSwitcherFormProviderProps)
|
|
|
190
190
|
const formStore = context.stores.find((s) => s.store_code === formValues.storeCode)
|
|
191
191
|
const isDefaultDisplayCurrency =
|
|
192
192
|
formValues.currency === formStore?.default_display_currency_code
|
|
193
|
+
const isCurrencyAvailable = formStore?.currency?.available_currency_codes?.includes(
|
|
194
|
+
formValues.currency,
|
|
195
|
+
)
|
|
193
196
|
|
|
194
|
-
|
|
197
|
+
// Clear cookie if using default currency or if the currency is not available for the target store
|
|
198
|
+
if (isDefaultDisplayCurrency || !isCurrencyAvailable) cookie('Magento-Content-Currency', null)
|
|
195
199
|
else cookie('Magento-Content-Currency', formValues.currency)
|
|
196
200
|
|
|
197
201
|
await onSubmit?.(formValues, event)
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fab,
|
|
3
|
-
import { StoreSwitcherText } from './StoreSwitcherText'
|
|
1
|
+
import type { FabProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { Fab, iconLanguage } from '@graphcommerce/next-ui'
|
|
4
3
|
import { useShowStoreSwitcherButton } from './useStoreSwitcherButton'
|
|
5
4
|
|
|
6
|
-
export
|
|
5
|
+
export type StoreSwitcherFabProps = Omit<FabProps, 'icon' | 'onClick'>
|
|
6
|
+
|
|
7
|
+
export function StoreSwitcherFab(props: StoreSwitcherFabProps) {
|
|
8
|
+
const { sx, ...fabProps } = props
|
|
7
9
|
const { show, onClick } = useShowStoreSwitcherButton()
|
|
10
|
+
|
|
8
11
|
if (!show) return null
|
|
9
12
|
|
|
10
13
|
return (
|
|
11
14
|
<Fab
|
|
12
|
-
|
|
15
|
+
color='inherit'
|
|
16
|
+
size='medium'
|
|
17
|
+
sx={sx}
|
|
18
|
+
icon={iconLanguage}
|
|
13
19
|
onClick={onClick}
|
|
14
|
-
|
|
15
|
-
{...
|
|
16
|
-
|
|
17
|
-
<IconSvg src={iconLanguage} /> <StoreSwitcherText />
|
|
18
|
-
</Fab>
|
|
20
|
+
slotProps={{ icon: { size: 'default' } }}
|
|
21
|
+
{...fabProps}
|
|
22
|
+
/>
|
|
19
23
|
)
|
|
20
24
|
}
|
|
@@ -8,17 +8,23 @@ export function useShowStoreSwitcherButton(options?: Record<string, never>) {
|
|
|
8
8
|
const country = config.data?.storeConfig?.locale?.split('_')?.[1]?.toLowerCase() ?? ''
|
|
9
9
|
const router = useRouter()
|
|
10
10
|
const multiLocale = (router.locales?.length ?? 0) > 1
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const availableCurrencies = config.data?.storeConfig?.currency?.available_currency_codes ?? []
|
|
12
|
+
const multiCurrency = new Set(availableCurrencies).size > 1
|
|
13
13
|
|
|
14
|
-
const [
|
|
14
|
+
const [cookieCurrency] = useCookie('Magento-Content-Currency')
|
|
15
|
+
|
|
16
|
+
// Validate cookie currency against available currencies
|
|
17
|
+
const currency =
|
|
18
|
+
cookieCurrency && availableCurrencies.includes(cookieCurrency)
|
|
19
|
+
? cookieCurrency
|
|
20
|
+
: config.data?.storeConfig?.default_display_currency_code
|
|
15
21
|
|
|
16
22
|
return {
|
|
17
23
|
show: multiLocale || multiCurrency,
|
|
18
24
|
multiCurrency,
|
|
19
25
|
country,
|
|
20
26
|
multiLocale,
|
|
21
|
-
currency
|
|
27
|
+
currency,
|
|
22
28
|
storeName: config.data?.storeConfig?.store_name,
|
|
23
29
|
onClick: () => router.push('/switch-stores'),
|
|
24
30
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-store",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.0.1-canary.
|
|
5
|
+
"version": "10.0.1-canary.1",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"./mesh/resolvers.ts": "./mesh/resolvers.ts"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@graphcommerce/ecommerce-ui": "^10.0.1-canary.
|
|
23
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.1-canary.
|
|
24
|
-
"@graphcommerce/framer-utils": "^10.0.1-canary.
|
|
25
|
-
"@graphcommerce/graphql": "^10.0.1-canary.
|
|
26
|
-
"@graphcommerce/graphql-mesh": "^10.0.1-canary.
|
|
27
|
-
"@graphcommerce/image": "^10.0.1-canary.
|
|
28
|
-
"@graphcommerce/next-ui": "^10.0.1-canary.
|
|
29
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.1-canary.
|
|
30
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.1-canary.
|
|
22
|
+
"@graphcommerce/ecommerce-ui": "^10.0.1-canary.1",
|
|
23
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.1-canary.1",
|
|
24
|
+
"@graphcommerce/framer-utils": "^10.0.1-canary.1",
|
|
25
|
+
"@graphcommerce/graphql": "^10.0.1-canary.1",
|
|
26
|
+
"@graphcommerce/graphql-mesh": "^10.0.1-canary.1",
|
|
27
|
+
"@graphcommerce/image": "^10.0.1-canary.1",
|
|
28
|
+
"@graphcommerce/next-ui": "^10.0.1-canary.1",
|
|
29
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.1-canary.1",
|
|
30
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.1-canary.1",
|
|
31
31
|
"@lingui/core": "^5",
|
|
32
32
|
"@lingui/macro": "^5",
|
|
33
33
|
"@lingui/react": "^5",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SetContextLink, type graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql'
|
|
2
2
|
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
3
|
import { cookie } from '@graphcommerce/next-ui'
|
|
4
|
+
import { StoreConfigDocument } from '../graphql/queries/StoreConfig.gql'
|
|
4
5
|
|
|
5
6
|
export const config: PluginConfig = {
|
|
6
7
|
type: 'function',
|
|
@@ -14,7 +15,7 @@ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, co
|
|
|
14
15
|
...results,
|
|
15
16
|
links: [
|
|
16
17
|
...results.links,
|
|
17
|
-
new SetContextLink((prevContext) => {
|
|
18
|
+
new SetContextLink((prevContext, operation) => {
|
|
18
19
|
const headers: Record<string, string> = { ...prevContext.headers }
|
|
19
20
|
|
|
20
21
|
if (!headers.store) {
|
|
@@ -22,8 +23,16 @@ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, co
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const contentCurrency = cookie('Magento-Content-Currency')
|
|
25
|
-
if (contentCurrency && typeof headers['content-currency'] === 'undefined')
|
|
26
|
-
|
|
26
|
+
if (contentCurrency && typeof headers['content-currency'] === 'undefined') {
|
|
27
|
+
// Validate currency against available currencies from StoreConfig cache
|
|
28
|
+
const storeConfig = operation.client.cache.readQuery({ query: StoreConfigDocument })
|
|
29
|
+
const availableCurrencies = storeConfig?.storeConfig?.currency?.available_currency_codes
|
|
30
|
+
|
|
31
|
+
if (!availableCurrencies || availableCurrencies.includes(contentCurrency)) {
|
|
32
|
+
headers['content-currency'] = contentCurrency
|
|
33
|
+
}
|
|
34
|
+
// If currency is not valid, don't set the header - backend will use default
|
|
35
|
+
}
|
|
27
36
|
|
|
28
37
|
if (conf.preview) {
|
|
29
38
|
// To disable caching from the backend, we provide a bogus cache ID.
|