Skip to content

Commit c18e0cf

Browse files
committed
doc: localizedRoute update & info about multiStoreConfig in VSF-API
1 parent 2daccba commit c18e0cf

File tree

1 file changed

+75
-28
lines changed

1 file changed

+75
-28
lines changed

docs/guide/integrations/multistore.md

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,33 +214,6 @@ export default function(app, router, store) {
214214

215215
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.
216216

217-
## Localized routes
218-
219-
The route switching mechanism by default works on the URL level. Please use the `localizedRoute` mixin:
220-
221-
```vue
222-
<router-link :to="localizedRoute(page.link)" class="cl-accent relative">{{
223-
page.title
224-
}}</router-link>
225-
```
226-
227-
or
228-
229-
```vue
230-
<router-link
231-
:to="
232-
localizedRoute({
233-
name: product.type_id + '-product',
234-
params: {
235-
parentSku: product.parentSku ? product.parentSku : product.sku,
236-
slug: product.slug,
237-
childSku: product.sku,
238-
},
239-
})
240-
"
241-
></router-link>
242-
```
243-
244217
## Useful _Helpers_
245218

246219
### How to get current store view?
@@ -316,7 +289,7 @@ import { removeStoreCodeFromRoute } from '@vue-storefront/core/lib/multistore'
316289
}); // should return '/home`
317290
```
318291

319-
### Update/append a store code to your URL
292+
### Update/append a storeCode to your URL
320293
If you need to append or update `storeCode` query parameter in provided URL you can do it by calling `adjustMultistoreApiUrl` function as following example:
321294

322295
```js
@@ -328,6 +301,53 @@ const myUrl1 = adjustMultistoreApiUrl('https://example.com?a=b'); // returns 'ht
328301
const myUrl2 = adjustMultistoreApiUrl('https://example.com?a=b&storeCode=it'); // returns 'https://example.com?a=b&storeCode=de'
329302
```
330303

304+
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.
305+
306+
### 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:
308+
```js
309+
const client = Magento2Client(config.magento2.api);
310+
```
311+
312+
If you want to support multistore for certain endpoint, you should make it this way:
313+
```js
314+
const client = Magento2Client(multiStoreConfig(config.magento2.api, req));
315+
```
316+
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:
323+
```js
324+
"magento2": {
325+
"imgUrl": "http://demo-magento2.vuestorefront.io/media/catalog/product",
326+
"assetPath": "/../var/magento2-sample-data/pub/media",
327+
"api": {
328+
"url": "https://my-magento.com/rest",
329+
"consumerKey": "******",
330+
"consumerSecret": "******",
331+
"accessToken": "******",
332+
"accessTokenSecret": "******"
333+
},
334+
"api_de": {
335+
"url": "https://my-magento.com/de/rest",
336+
"consumerKey": "******",
337+
"consumerSecret": "******",
338+
"accessToken": "******",
339+
"accessTokenSecret": "******"
340+
},
341+
"api_it": {
342+
"url": "https://my-magento.com/it/rest",
343+
"consumerKey": "******",
344+
"consumerSecret": "******",
345+
"accessToken": "******",
346+
"accessTokenSecret": "******"
347+
}
348+
},
349+
```
350+
331351
### Localize URL with correct store code
332352
:::tip
333353
Localized Route means denoting store code in URL by convention without a parameter.
@@ -347,6 +367,33 @@ localizedRoute('/about'); // returns /de/about
347367
`appendStoreCode` option of the store view configuration should be set to `true` to display store code as tip above
348368
:::
349369

370+
:::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.
372+
:::
373+
374+
```vue
375+
<router-link :to="localizedRoute(page.link)" class="cl-accent relative">{{
376+
page.title
377+
}}</router-link>
378+
```
379+
380+
or
381+
382+
```vue
383+
<router-link
384+
:to="
385+
localizedRoute({
386+
name: product.type_id + '-product',
387+
params: {
388+
parentSku: product.parentSku ? product.parentSku : product.sku,
389+
slug: product.slug,
390+
childSku: product.sku,
391+
},
392+
})
393+
"
394+
></router-link>
395+
```
396+
350397
### How to extract store code from route
351398

352399
You can extract store code from route as follows :

0 commit comments

Comments
 (0)