Skip to content

Commit 2ddac26

Browse files
authored
Merge pull request #5038 from DivanteLtd/doc-multistore-refactor
Docs: last changes in multistore
2 parents 6c2562c + 3c60f42 commit 2ddac26

File tree

1 file changed

+115
-100
lines changed

1 file changed

+115
-100
lines changed

docs/guide/integrations/multistore.md

Lines changed: 115 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
Vue Storefront supports Magento Multistore installations
44

5+
## Limitations of Multistore in Vue Storefront 1
6+
- Multidomain support is possible to achieve right now but it requires tricky changes in core. It will be available in refactored Multistore which should be released in 1.13/1.14
7+
- Different theme for different store is not supported right now. If you want to achieve that - the easiest way would be to just run 2 instances with different configs. If you want to change only parts of theme based on current store then you can easily achieve it with helpers described below.
8+
- No support for multicurrency per store
9+
510
## Multiwebsite indexing
611

7-
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.
12+
Multiwebsite support starts with the Elasticsearch indexing. Basically, each store has its own Elasticsearch index and should be populated using the [Magento2 VSBridge Indexer](https://github.com/DivanteLtd/magento2-vsbridge-indexer) tool.
813

914
:::warning
1015

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)
16+
There is legacy node indexer which has been deprecated. You should not use `mage2vuestorefront` anymore in production! The only acceptable reason to using it - is to provide data to your local Elasticsearch cluster from development instance.
1317
:::
1418

15-
The simplest script to index multi site:
19+
The simplest script to provide data to your local Elasticsearch:
1620

1721
```bash
1822
export TIME_TO_EXIT=2000
@@ -60,7 +64,7 @@ In the result, you should get:
6064
- _vue_storefront_catalog_de_ - populated with the "it" store data
6165
- _vue_storefront_catalog_ - populated with the "default" store data
6266

63-
Then, to use these indexes in Vue Storefront, you should index the database schema using the `vue-storefront-api` db tool:
67+
Then, to use these indices in Vue Storefront, you should index the database schema using the `vue-storefront-api` db tool (use only if using mage2vuestorefront!):
6468

6569
```bash
6670
yarn db rebuild -- --indexName=vue_storefront_catalog_it
@@ -85,98 +89,99 @@ After this sequence of command, you may add the available ES index to your `vue-
8589
"vue_storefront_catalog_it"
8690
],
8791
"availableStores": [
88-
"de", "it"
92+
"de",
93+
"it"
8994
],
90-
95+
// ...
9196
```
9297

9398
The last thing is to change the `vue-storefront/config/local.json` to configure the storeViews that are available.
9499

95100
```json
96-
"storeViews": {
97-
"multistore": false,
98-
"mapStoreUrlsFor": ["de", "it"],
99-
"de": {
100-
"storeCode": "de",
101-
"storeId": 3,
102-
"name": "German Store",
103-
"url": "/de",
104-
"elasticsearch": {
105-
"host": "localhost:8080/api/catalog",
106-
"index": "vue_storefront_catalog_de"
107-
},
108-
"tax": {
109-
"defaultCountry": "DE",
110-
"defaultRegion": "",
111-
"sourcePriceIncludesTax": false,
112-
"calculateServerSide": true,
113-
"userGroupId": null,
114-
"useOnlyDefaultUserGroupId": false,
115-
"deprecatedPriceFieldsSupport": true,
116-
"finalPriceIncludesTax": false
117-
},
118-
"i18n": {
119-
"defaultCountry": "DE",
120-
"defaultLanguage": "DE",
121-
"availableLocale": [
122-
"de-DE"
123-
],
124-
"defaultLocale": "de-DE",
125-
"currencyCode": "EUR",
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
135-
}
136-
},
137-
"it": {
138-
"storeCode": "it",
139-
"storeId": 4,
140-
"name": "Italian Store",
141-
"url": "/it",
142-
"elasticsearch": {
143-
"host": "localhost:8080/api/catalog",
144-
"index": "vue_storefront_catalog_it"
145-
},
146-
"tax": {
147-
"defaultCountry": "IT",
148-
"defaultRegion": "",
149-
"sourcePriceIncludesTax": false,
150-
"calculateServerSide": true,
151-
"userGroupId": null,
152-
"useOnlyDefaultUserGroupId": false,
153-
"deprecatedPriceFieldsSupport": true,
154-
"finalPriceIncludesTax": false
155-
},
156-
"i18n": {
157-
"defaultCountry": "IT",
158-
"defaultLanguage": "IT",
159-
"availableLocale": [
160-
"it-IT"
161-
],
162-
"defaultLocale": "it-IT",
163-
"currencyCode": "EUR",
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
173-
}
174-
}
101+
"storeViews": {
102+
"multistore": false,
103+
"mapStoreUrlsFor": ["de", "it"],
104+
"de": {
105+
"storeCode": "de",
106+
"storeId": 3,
107+
"name": "German Store",
108+
"url": "/de",
109+
"elasticsearch": {
110+
"host": "localhost:8080/api/catalog",
111+
"index": "vue_storefront_catalog_de"
175112
},
113+
"tax": {
114+
"defaultCountry": "DE",
115+
"defaultRegion": "",
116+
"sourcePriceIncludesTax": false,
117+
"calculateServerSide": true,
118+
"userGroupId": null,
119+
"useOnlyDefaultUserGroupId": false,
120+
"deprecatedPriceFieldsSupport": true,
121+
"finalPriceIncludesTax": false
122+
},
123+
"i18n": {
124+
"defaultCountry": "DE",
125+
"defaultLanguage": "DE",
126+
"availableLocale": [
127+
"de-DE"
128+
],
129+
"defaultLocale": "de-DE",
130+
"currencyCode": "EUR",
131+
"currencySign": "",
132+
"currencyDecimal": "",
133+
"currencyGroup": "",
134+
"fractionDigits": 2,
135+
"priceFormat": "{sign}{amount}",
136+
"dateFormat": "HH:mm D/M/YYYY",
137+
"fullCountryName": "Deutschland",
138+
"fullLanguageName": "German",
139+
"bundleAllStoreviewLanguages": false
140+
}
141+
},
142+
"it": {
143+
"storeCode": "it",
144+
"storeId": 4,
145+
"name": "Italian Store",
146+
"url": "/it",
147+
"elasticsearch": {
148+
"host": "localhost:8080/api/catalog",
149+
"index": "vue_storefront_catalog_it"
150+
},
151+
"tax": {
152+
"defaultCountry": "IT",
153+
"defaultRegion": "",
154+
"sourcePriceIncludesTax": false,
155+
"calculateServerSide": true,
156+
"userGroupId": null,
157+
"useOnlyDefaultUserGroupId": false,
158+
"deprecatedPriceFieldsSupport": true,
159+
"finalPriceIncludesTax": false
160+
},
161+
"i18n": {
162+
"defaultCountry": "IT",
163+
"defaultLanguage": "IT",
164+
"availableLocale": [
165+
"it-IT"
166+
],
167+
"defaultLocale": "it-IT",
168+
"currencyCode": "EUR",
169+
"currencySign": "",
170+
"currencyDecimal": "",
171+
"currencyGroup": "",
172+
"fractionDigits": 2,
173+
"priceFormat": "{sign}{amount}",
174+
"dateFormat": "HH:mm D/M/YYYY",
175+
"fullCountryName": "Italy",
176+
"fullLanguageName": "Italian",
177+
"bundleAllStoreviewLanguages": false
178+
}
179+
}
180+
},
176181
```
177182

178183
:::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_.
184+
You can find more options available to _multistore_ in [store view](/guide/basics/configuration.html#store-views) section of _Configuration File Explained_.
180185
:::
181186

182187
After these changes, you'll have a `LanguageSwitcher` component visible on the bottom.
@@ -194,7 +199,7 @@ The storeCode may be switched by ENV variable set before running `yarn dev` / `y
194199

195200
- `export STORE_CODE=de && yarn dev` will run the shop with the `de` shop loaded
196201

197-
Another option, useful when using multistore mode with the NGINX/varnish mode, is to set the shop code by the `x-vs-store-code` http reqeuest header.
202+
Another option, useful when using multistore mode with the NGINX/varnish mode, is to set the store code by the `x-vs-store-code` HTTP header.
198203

199204
## Changing the UI for specific store views
200205

@@ -214,6 +219,21 @@ export default function(app, router, store) {
214219

215220
Another option is to create a separate theme for a specific storeview. Runtime theme changes are not possible, as themes are compiled in the JS bundles by webpack during the page build process. In that case, you should run separate instances of `vue-storefront` having the proper theme set in the `config/local.json` file.
216221

222+
## Multi Source Inventory (MSI) support
223+
To support this custom feature you should take care of 2 things. At first please install [Magento2 VSBridge Indexer MSI Extension](https://github.com/DivanteLtd/magento2-vsbridge-indexer-msi). Then in `config/local.json` of your VSF-API add part like:
224+
```js
225+
"msi": {
226+
"enabled": true,
227+
"defaultStockId": 1
228+
},
229+
```
230+
Where `defaultStockId` is your default stock ID. In each storeCode, which uses different stock ID you should add part like:
231+
```js
232+
"msi": {
233+
"stockId": 2
234+
},
235+
```
236+
217237
## Useful _Helpers_
218238

219239
### How to get current store view?
@@ -231,7 +251,7 @@ import { currentStoreView } from '@vue-storefront/core/lib/multistore'
231251
}
232252
```
233253

234-
`currentStoreView()` will return the object value you set in `local.json` - it should be type of StoreView or extended StoreView.
254+
`currentStoreView()` returns the object value you set in `local.json` - it is type of StoreView or extended StoreView.
235255
```ts
236256
interface StoreView {
237257
storeCode: string,
@@ -277,7 +297,7 @@ interface StoreView {
277297

278298
### How to remove store code from route
279299

280-
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 :
300+
When you need to remove `storeCode` from route, use `removeStoreCodeFromRoute` as following example :
281301

282302
```js
283303
import { removeStoreCodeFromRoute } from '@vue-storefront/core/lib/multistore'
@@ -304,7 +324,7 @@ const myUrl2 = adjustMultistoreApiUrl('https://example.com?a=b&storeCode=it'); /
304324
This feature is extra useful when you are sending a request to the VSF-API and you want VSF-API to use endpoint of certain storeCode.
305325

306326
### Using endpoint of certain storeCode in Vue Storefront API
307-
In `src/api/extensions/example-magento-api/index.js` we have example line that creates Magento 2 Client:
327+
In `src/api/extensions/example-magento-api/index.js` we have line that creates Magento 2 Client:
308328
```js
309329
const client = Magento2Client(config.magento2.api);
310330
```
@@ -314,12 +334,7 @@ If you want to support multistore for certain endpoint, you should make it this
314334
const client = Magento2Client(multiStoreConfig(config.magento2.api, req));
315335
```
316336

317-
Obviously, you could do the same in Magento 1:
318-
```js
319-
const client = Magento1Client(multiStoreConfig(config.magento2.api, req));
320-
```
321-
322-
It will use `storeCode` query parameter from the `req` to figure out which store to use. To make it work properly you should also configure different stores in your VSF-API's config. Check this example configuration for `de` and `it` store codes:
337+
It uses `storeCode` query parameter from the `req` to figure out which store to use. To make it work properly you should also configure different stores in your VSF-API's config. Check this example configuration for `de` and `it` store codes:
323338
```js
324339
"magento2": {
325340
"imgUrl": "http://demo-magento2.vuestorefront.io/media/catalog/product",
@@ -368,7 +383,7 @@ localizedRoute('/about'); // returns /de/about
368383
:::
369384

370385
:::warning
371-
`localizedRoute` is injected to each Vue's instance so you can access it in your component with `this.localizedRoute`. You could also use it in template without additional imports.
386+
`localizedRoute` is injected to each Vue's instance so you can access it in your component via `this.localizedRoute`. You could also use it in template without additional imports.
372387
:::
373388

374389
```vue
@@ -401,7 +416,7 @@ You can extract store code from route as follows :
401416
```js
402417
import storeCodeFromRoute from '@vue-storefront/core/lib/storeCodeFromRoute'
403418
// abridged
404-
const storeCode = storeCodeFromRoute(currentRoute)
419+
const storeCode = storeCodeFromRoute(currentRoute)
405420
```
406421

407-
You should get store code `gb` from route `https://example.com/gb/foo` where storeCode is `gb`
422+
You should get store code `gb` from route `https://example.com/gb/foo` if storeCode is `gb`

0 commit comments

Comments
 (0)