Skip to content

Commit 2daccba

Browse files
committed
docs: multistore refactor
1 parent 57c7bef commit 2daccba

File tree

1 file changed

+166
-12
lines changed

1 file changed

+166
-12
lines changed

docs/guide/integrations/multistore.md

Lines changed: 166 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Vue Storefront supports Magento Multistore installations
66

77
Multiwebsite support starts with the Elasticsearch indexing. Basically, each store has its own Elasticsearch index and should be populated separately using the [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront) tool.
88

9+
:::warning
10+
11+
Using node indexer to enable _multistore_ feature for _Vue Storefront_ has been deprecated.
12+
You can use _Bridge Indexer_ for the better performance and maintainability. For Magento 2, you can find it [here](https://github.com/DivanteLtd/magento2-vsbridge-indexer)
13+
:::
14+
915
The simplest script to index multi site:
1016

1117
```bash
@@ -102,17 +108,30 @@ The last thing is to change the `vue-storefront/config/local.json` to configure
102108
"tax": {
103109
"defaultCountry": "DE",
104110
"defaultRegion": "",
105-
"calculateServerSide": true
111+
"sourcePriceIncludesTax": false,
112+
"calculateServerSide": true,
113+
"userGroupId": null,
114+
"useOnlyDefaultUserGroupId": false,
115+
"deprecatedPriceFieldsSupport": true,
116+
"finalPriceIncludesTax": false
106117
},
107118
"i18n": {
108-
"fullCountryName": "Germany",
109-
"fullLanguageName": "German",
110-
"defaultLanguage": "DE",
111119
"defaultCountry": "DE",
120+
"defaultLanguage": "DE",
121+
"availableLocale": [
122+
"de-DE"
123+
],
112124
"defaultLocale": "de-DE",
113125
"currencyCode": "EUR",
114-
"currencySign": "EUR",
115-
"dateFormat": "HH:mm D-M-YYYY"
126+
"currencySign": "",
127+
"currencyDecimal": "",
128+
"currencyGroup": "",
129+
"fractionDigits": 2,
130+
"priceFormat": "{sign}{amount}",
131+
"dateFormat": "HH:mm D/M/YYYY",
132+
"fullCountryName": "Deutschland",
133+
"fullLanguageName": "German",
134+
"bundleAllStoreviewLanguages": false
116135
}
117136
},
118137
"it": {
@@ -125,24 +144,41 @@ The last thing is to change the `vue-storefront/config/local.json` to configure
125144
"index": "vue_storefront_catalog_it"
126145
},
127146
"tax": {
128-
"defaultCountry": "DE",
147+
"defaultCountry": "IT",
129148
"defaultRegion": "",
130-
"calculateServerSide": true
149+
"sourcePriceIncludesTax": false,
150+
"calculateServerSide": true,
151+
"userGroupId": null,
152+
"useOnlyDefaultUserGroupId": false,
153+
"deprecatedPriceFieldsSupport": true,
154+
"finalPriceIncludesTax": false
131155
},
132156
"i18n": {
133-
"fullCountryName": "Italy",
134-
"fullLanguageName": "Italian",
135157
"defaultCountry": "IT",
136158
"defaultLanguage": "IT",
159+
"availableLocale": [
160+
"it-IT"
161+
],
137162
"defaultLocale": "it-IT",
138163
"currencyCode": "EUR",
139-
"currencySign": "EUR",
140-
"dateFormat": "HH:mm D-M-YYYY"
164+
"currencySign": "",
165+
"currencyDecimal": "",
166+
"currencyGroup": "",
167+
"fractionDigits": 2,
168+
"priceFormat": "{sign}{amount}",
169+
"dateFormat": "HH:mm D/M/YYYY",
170+
"fullCountryName": "Italy",
171+
"fullLanguageName": "Italian",
172+
"bundleAllStoreviewLanguages": false
141173
}
142174
}
143175
},
144176
```
145177

178+
:::tip
179+
You can find more options available to _multistore_ features in [store view](/guide/basics/configuration.html#store-views) section of _Configuration File Explained_.
180+
:::
181+
146182
After these changes, you'll have a `LanguageSwitcher` component visible on the bottom.
147183

148184
By default, the language / store is switched by the URL prefix:
@@ -204,3 +240,121 @@ or
204240
"
205241
></router-link>
206242
```
243+
244+
## Useful _Helpers_
245+
246+
### How to get current store view?
247+
248+
Here is a helper method to get the value of current store view.
249+
250+
You just need to import `currentStoreView` function from `core/lib/multistore` as example follows:
251+
252+
```js
253+
import { currentStoreView } from '@vue-storefront/core/lib/multistore'
254+
// ... abridged
255+
return {
256+
currency: currentStoreView().i18n.currencyCode,
257+
value: method.price_incl_tax
258+
}
259+
```
260+
261+
`currentStoreView()` will return the object value you set in `local.json` - it should be type of StoreView or extended StoreView.
262+
```ts
263+
interface StoreView {
264+
storeCode: string,
265+
extend?: string,
266+
disabled?: boolean,
267+
storeId: any,
268+
name?: string,
269+
url?: string,
270+
appendStoreCode?: boolean,
271+
elasticsearch: {
272+
host: string,
273+
index: string
274+
},
275+
tax: {
276+
sourcePriceIncludesTax?: boolean,
277+
finalPriceIncludesTax?: boolean,
278+
deprecatedPriceFieldsSupport?: boolean,
279+
defaultCountry: string,
280+
defaultRegion: null | string,
281+
calculateServerSide: boolean,
282+
userGroupId?: number,
283+
useOnlyDefaultUserGroupId: boolean
284+
},
285+
i18n: {
286+
fullCountryName: string,
287+
fullLanguageName: string,
288+
defaultLanguage: string,
289+
defaultCountry: string,
290+
defaultLocale: string,
291+
currencyCode: string,
292+
currencySign: string,
293+
currencyDecimal: string,
294+
currencyGroup: string,
295+
fractionDigits: number,
296+
priceFormat: string,
297+
dateFormat: string
298+
},
299+
seo: {
300+
defaultTitle: string
301+
}
302+
}
303+
```
304+
305+
### How to remove store code from route
306+
307+
When you need to remove `storeCode` from route in such a case you want to route to default store by mapping fallback, use `removeStoreCodeFromRoute` as following example :
308+
309+
```js
310+
import { removeStoreCodeFromRoute } from '@vue-storefront/core/lib/multistore'
311+
// ... abridged
312+
const urlWithoutStorecode1 = removeStoreCodeFromRoute('/gb/home'); // should return '/home`
313+
const urlWithoutStorecode2 = removeStoreCodeFromRoute('gb/home'); // should return 'home`
314+
const urlWithoutStorecode3 = removeStoreCodeFromRoute({
315+
path: '/gb/home'
316+
}); // should return '/home`
317+
```
318+
319+
### Update/append a store code to your URL
320+
If you need to append or update `storeCode` query parameter in provided URL you can do it by calling `adjustMultistoreApiUrl` function as following example:
321+
322+
```js
323+
import { adjustMultistoreApiUrl } from '@vue-storefront/core/lib/multistore'
324+
325+
// ... abridged
326+
// Let's say current storeCode is `de`
327+
const myUrl1 = adjustMultistoreApiUrl('https://example.com?a=b'); // returns 'https://example.com?a=b&storeCode=de'
328+
const myUrl2 = adjustMultistoreApiUrl('https://example.com?a=b&storeCode=it'); // returns 'https://example.com?a=b&storeCode=de'
329+
```
330+
331+
### Localize URL with correct store code
332+
:::tip
333+
Localized Route means denoting store code in URL by convention without a parameter.
334+
335+
e.g. It's `de` in `https://example.com/de?a=b`
336+
:::
337+
338+
Method that allows use to do that is `localizedRoute`. Example transformations for `de` as a current storeCode:
339+
```js
340+
localizedRoute('http://example.com/'); // returns http://example.com/de
341+
localizedRoute('/'); // returns /de
342+
localizedRoute('/?a=b'); // returns /de?a=b
343+
localizedRoute('/about'); // returns /de/about
344+
```
345+
346+
:::warning
347+
`appendStoreCode` option of the store view configuration should be set to `true` to display store code as tip above
348+
:::
349+
350+
### How to extract store code from route
351+
352+
You can extract store code from route as follows :
353+
354+
```js
355+
import storeCodeFromRoute from '@vue-storefront/core/lib/storeCodeFromRoute'
356+
// abridged
357+
const storeCode = storeCodeFromRoute(currentRoute)
358+
```
359+
360+
You should get store code `gb` from route `https://example.com/gb/foo` where storeCode is `gb`

0 commit comments

Comments
 (0)