Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit f0d0b8b

Browse files
authored
Merge pull request #1887 from DivanteLtd/docs
Docs Update - 1.5.0
2 parents 36989bd + 8edff30 commit f0d0b8b

35 files changed

+3540
-81
lines changed

docs/.vuepress/config.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,52 @@ module.exports = {
3939
'basics/feature-list',
4040
'basics/recipes',
4141
'basics/typescript',
42+
'basics/graphql',
43+
'basics/ssr-cache',
4244
],
4345
},
44-
// {
45-
// title: 'Vue Storefront core and themes',
46-
// collapsable: false,
47-
// children: [
48-
// 'core-themes/themes',
49-
// 'core-themes/webpack',
50-
// 'core-themes/core-components',
51-
// 'core-themes/plugins',
52-
// 'core-themes/vuex',
53-
// 'core-themes/data',
54-
// 'core-themes/extensions',
55-
// ],
56-
// },
57-
// {
58-
// title: 'Data in Vue Storefront',
59-
// collapsable: false,
60-
// children: ['data/data'],
61-
// },
46+
{
47+
title: 'Core and themes',
48+
collapsable: false,
49+
children: [
50+
'core-themes/themes',
51+
'core-themes/layouts',
52+
'core-themes/core-components',
53+
'core-themes/ui-store',
54+
'core-themes/translations',
55+
'core-themes/service-workers',
56+
'core-themes/webpack',
57+
'core-themes/plugins',
58+
'core-themes/core-components-api',
59+
],
60+
},
61+
{
62+
title: 'Components',
63+
collapsable: false,
64+
children: [
65+
'components/home-page',
66+
'components/category-page',
67+
'components/product',
68+
'components/modal',
69+
],
70+
},
71+
{
72+
title: 'Data in Vue Storefront',
73+
collapsable: false,
74+
children: [
75+
'data/data',
76+
'data/elasticsearch',
77+
'data/data-migrations',
78+
'data/elastic-queries',
79+
'data/database-tool',
80+
'data/entity-types',
81+
],
82+
},
83+
{
84+
title: 'Working with Vuex',
85+
collapsable: false,
86+
children: ['vuex/introduction', 'vuex/product-store'],
87+
},
6288
// {
6389
// title: 'Working with extensions',
6490
// collapsable: false,
Loading
72.5 KB
Loading
Loading
87.7 KB
Loading
117 KB
Loading

docs/guide/basics/graphql.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# GraphQL Action Plan
2+
3+
Starting with Vue Storefront 1.4.0 (currently on develop branch) we're supporting two ways of getting data from the backend:
4+
5+
- existing `api` mode - which is using ElasticSearch DSL as a query language,
6+
- new `graphql` mode - which is using GraphQL queries.
7+
8+
You can set the desired API format in the `config/local.json` - and `vue-storefront-api` is supporting both of them, however [the default is still set to `api`](https://github.com/DivanteLtd/vue-storefront/blob/4cbf866ca93f917b04461d3ae139a2d26ddf552a/config/default.json#L6).
9+
10+
We've introduced an abstract [`SearchQuery`](https://github.com/DivanteLtd/vue-storefront/tree/develop/core/store/lib/search) interface with switchable Query Adapters to provide the abstraction layer. This is ultra cool feature especially when you're integrating Vue Storefront with custom backend application: you're able [to create your own adapter](https://github.com/DivanteLtd/vue-storefront/blob/develop/core/store/lib/search/adapter/factory.js) to customize the way data is gathered from the backend.
11+
12+
From now on the **bodybuilder** package is **deprecated** and you should start using the `SearchQuery` interface to build the search queries that will be translated to GraphQL / API queries.
13+
14+
Here is an example on how to build the Query:
15+
16+
```js
17+
export function prepareRelatedQuery(key, sku) {
18+
let relatedProductsQuery = new SearchQuery();
19+
20+
relatedProductsQuery = relatedProductsQuery.applyFilter({
21+
key: key,
22+
value: { in: sku },
23+
});
24+
25+
relatedProductsQuery = relatedProductsQuery
26+
.applyFilter({ key: 'visibility', value: { in: [2, 3, 4] } })
27+
.applyFilter({ key: 'status', value: { in: [0, 1, 2] } }); // @TODO Check if status 2 (disabled) was set not by occasion here
28+
29+
if (config.products.listOutOfStockProducts === false) {
30+
relatedProductsQuery = relatedProductsQuery.applyFilter({
31+
key: 'stock.is_in_stock',
32+
value: { eq: true },
33+
});
34+
}
35+
36+
return relatedProductsQuery;
37+
}
38+
39+
let relatedProductsQuery = prepareRelatedQuery(key, sku);
40+
41+
this.$store
42+
.dispatch('product/list', {
43+
query: relatedProductsQuery,
44+
size: 8,
45+
prefetchGroupProducts: false,
46+
updateState: false,
47+
})
48+
.then(response => {
49+
if (response) {
50+
this.$store.dispatch('product/related', {
51+
key: this.type,
52+
items: response.items,
53+
});
54+
this.$forceUpdate();
55+
}
56+
});
57+
```
58+
59+
[More information on how to query the data](https://github.com/DivanteLtd/vue-storefront/blob/develop/doc/data/ElasticSearch%20Queries.md).
60+
61+
**bodybuilder** queries are still supported by our backward-compatibility mode so if you've used bodybuilder in your theme, it's fine as long as you're using the `api` mode for the backend queries.
62+
63+
The **legacy queries** using bodybuilder will still work - and [here is an example](https://github.com/pkarw/vue-storefront/blob/28feb8e5dc30ec216353ef87a859212379901c57/src/extensions/template/index.js#L36).
64+
65+
You can also use direct **ApolloQuery** GraphQL queries thanks to `vue-apollo` support. Please find the example [in here](https://github.com/DivanteLtd/vue-storefront/blob/4cbf866ca93f917b04461d3ae139a2d26ddf552a/src/themes/default/components/core/blocks/SearchPanel/SearchPanel.gql.vue#L21).

docs/guide/basics/project-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Below you can find the Vue Storefront project structure with explanations and co
3131
- `router` - Core Vue Router setup. The definition of routes happens in `{themeroot}/index.js`
3232
- `scripts` - Core scripts like app installer, extension installer etc.
3333
- `service-worker` - Core service worker. It's merged with `sw-precache` data from `build` and `{theme}/service-worker-ext.js`
34-
- `store` - Core Vuex stores (related: [Working with Vuex](../data/vuex.md), [Working with data](../core-themes/data.md))
34+
- `store` - Core Vuex stores (related: [Working with Vuex](../vuex/introduction.md), [Working with data](../core-themes/data.md))
3535

3636
- `src` - Main project folder containing Vue Storefront core and themes. This is your app playground so you can modify this folder.
3737
- `extensions` - Custom extensions made for Vue Storefront like integration with MailChimp or support for Google Analytics) (see: [Working with extensions](../core-themes/extensions.md))

docs/guide/basics/recipes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ It's done via Database Tool schema changes. Please follow the instructions from
216216
Unfortunately, Magento extensions are not compliant with any PWA available solution yet. So if you would like to integrate some existing extensions, the simplest way is to:
217217

218218
- expose the data via some Magento2 REST api endpoints;
219-
- consume the endpoints in the VS using Vuex stores; [read more](../data/vuex.md) about Vuex in Vue Storefront;
219+
- consume the endpoints in the VS using Vuex stores; [read more](../vuex/introduction.md) about Vuex in Vue Storefront;
220220
- implement the UI in VS
221221

222222
If the extensions are not playing with the User Interface, probably they will work with VS out of the box, as we're using the standard Magento2 API calls for the integration part.

docs/guide/data/ssr-cache.md renamed to docs/guide/basics/ssr-cache.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SSR Cache
22

3-
Vue Storefront generates the Server Side rendered pages to improve the SEO results. In the latest version of Vue Storefront we've added the Output cache option (disabled by default) to improve the performance.
3+
Vue Storefront generates the Server Side rendered pages to improve the SEO results. In the latest version of Vue Storefront we've added the Output cache option (disabled by default) to improve performance.
44

55
The output cache is set by the following `config/local.json` variables:
66

@@ -23,7 +23,7 @@ The output cache is set by the following `config/local.json` variables:
2323

2424
## Dynamic tags
2525

26-
The dynamic tags config uption: `useOutputCacheTaging` - if set to true, Vue Storefront is generating the special HTTP Header `X-VS-Cache-Tags`
26+
The dynamic tags config option: `useOutputCacheTaging` - if set to `true`, Vue Storefront is generating the special HTTP Header `X-VS-Cache-Tags`
2727

2828
```js
2929
res.setHeader('X-VS-Cache-Tags', cacheTags);
@@ -35,24 +35,31 @@ Cache tags are assigned regarding the products and categories which are used on
3535
X-VS-Cache-Tags: P1852 P198 C20
3636
```
3737

38-
The tags can be used to invalidate the Varnish cache if You're using it. [Read more on that](https://www.drupal.org/docs/8/api/cache-api/cache-tags-varnish).
38+
The tags can be used to invalidate the Varnish cache if you're using it. [Read more on that](https://www.drupal.org/docs/8/api/cache-api/cache-tags-varnish).
3939

4040
## Redis
4141

42-
If both `useOutputCache` and `useOutputCacheTagging` options are set to `true` - Vue Storefront is using Output Cache stored in Redis (configured in the `redis` section of the config file). Cache is tagged with Dynamic tags and can be invalidated using special webhook:
42+
If both `useOutputCache` and `useOutputCacheTagging` options are set to `true` - Vue Storefront is using Output Cache stored in Redis (configured in the `redis` section of the config file). Cache is tagged with Dynamic tags and can be invalidated using a special webhook:
4343

4444
Example call to clear all pages containing specific product and category:
45-
`curl http://localhost:3000/invalidate?tag=P1852,C20`
45+
46+
```bash
47+
curl http://localhost:3000/invalidate?tag=P1852,C20
48+
```
4649

4750
Example call to clear all product, category and home pages:
48-
`curl http://localhost:3000/invalidate?tag=product,category,home`
4951

50-
**WARNING:**
51-
We strongly recommend You to NOT USE Output cache in the development mode. By using it You won't be able to refresh the UI changes after modyfing the Vue components etc.
52+
```bash
53+
curl http://localhost:3000/invalidate?tag=product,category,home
54+
```
55+
56+
:::danger Warning
57+
We strongly recommend you NOT TO USE Output cache in the development mode. By using it you won't be able to refresh the UI changes after modifying the Vue components etc.
58+
:::
5259

5360
## CLI cache clear
5461

55-
You can manualy clear Redis cache for specific tags by running the following command:
62+
You can manually clear Redis cache for specific tags by running the following command:
5663

5764
```bash
5865
npm run cache clear
@@ -63,25 +70,27 @@ npm run cache clear -- --tag=*
6370

6471
Available tag keys are set in the `config.server.availableCacheTags` (by default: `"product", "category", "home", "checkout", "page-not-found", "compare", "my-account", "P", "C"`)
6572

66-
**Dynamic cache invalidation:** Recent version of [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront) do support output cache invalidation. Output cache is being tagged with the product and categories id (products and categories used on specific page). Mage2vuestorefront can invalidate cache of product and category pages if You set the following ENV variables:
73+
**Dynamic cache invalidation:** Recent version of [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront) supports output cache invalidation. Output cache is being tagged with the product and categories id (products and categories used on specific page). Mage2vuestorefront can invalidate cache of a product and category pages if you set the following ENV variables:
6774

6875
```bash
6976
export VS_INVALIDATE_CACHE_URL=http://localhost:3000/invalidate?key=SECRETKEY&tag=
7077
export VS_INVALIDATE_CACHE=1
7178
```
7279

73-
**SECURITY NOTE:** Please note that `key=SECRETKEY` should be equal to `vue-storefront/config/local.json` value of `server.invalidateCacheKey`
80+
:::warning Security note
81+
Please note that `key=SECRETKEY` should be equal to `vue-storefront/config/local.json` value of `server.invalidateCacheKey`
82+
:::
7483

7584
## Adding new types / cache tags
7685

77-
If You're adding new type of page (`core/pages`) and `config.server.useOutputCache=true` - You should also extend the `config.server.availableCacheTags` of new general purpose tag that will be connected with the URLs connected with this new page.
86+
If you're adding a new type of page (`core/pages`) and `config.server.useOutputCache=true`, you should also extend the `config.server.availableCacheTags` of new general purpose tag that will be connected with the URLs connected with this new page.
7887

79-
After doing so, please add the `asyncData` method to Your page code assigning the right tag (please take a look at `core/pages/Home.js` for instance):
88+
After doing so, please add the `asyncData` method to your page code assigning the right tag (please take a look at `core/pages/Home.js` for instance):
8089

8190
```js
82-
asyncData ({ store, route }) { // this is for SSR purposes to prefetch data
91+
asyncData ({ store, route, context }) { // this is for SSR purposes to prefetch data
8392
return new Promise((resolve, reject) => {
84-
store.state.requestContext.outputCacheTags.add(`home`)
93+
if (context) context.output.cacheTags.add(`home`)
8594
console.log('Entering asyncData for Home root ' + new Date())
8695
EventBus.$emitFilter('home-after-load', { store: store, route: route }).then((results) => {
8796
return resolve()
@@ -96,7 +105,7 @@ After doing so, please add the `asyncData` method to Your page code assigning th
96105
This line:
97106

98107
```js
99-
store.state.requestContext.outputCacheTags.add(`home`);
108+
if (context) context.output.cacheTags.add(`home`);
100109
```
101110

102-
... is in charge of assigning the specific tag with current HTTP request output.
111+
is in charge of assigning the specific tag with current HTTP request output.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Core Category Page
2+
3+
## Props
4+
5+
No props
6+
7+
## Data
8+
9+
- `pagination` - an object that defines two settings:
10+
- `perPage` of product items to load per page, currently set to 50
11+
- `offset` that probably defines which page has been last loaded, currently set to 0 and isn't changed anywhere.
12+
- `enabled` - enables/disables paging. When it's disabled it lazy-loads other products on scroll
13+
- `filters.available`, `filters.chosen` - a set of filters that user has defined on Category page - there we have available filters and chosen filter values
14+
- `products` - computed property that returns a list of product items of current category from the Vuex store.
15+
- `isCategoryEmpty` - computed property that returns `true` if product list of current category is empty.
16+
- `category` - computed property that returns current category from the Vuex store.
17+
- `categoryName` - category name.
18+
- `categoryId` - category ID.
19+
- `breadcrumbs` - breadcrumbs for the current category from the Vuex store.
20+
- `productsCounter` - how many products are in the category.
21+
- `lazyLoadProductsOnscroll` - allows lazy-loading more products on scroll, by default it's true
22+
23+
## Methods
24+
25+
- `fetchData ({ store, route })` - prepares query for fetching a list of products of the current category and dispatches `product/list` action that extracts that list.
26+
27+
- `{ store, route }` - an object consisting of the Vuex store and global router references.
28+
29+
- `validateRoute ({ store, route })` - this method is called whenever the global `$route` object changes its value. It dispatches `'category/single'` action to load current category object and then calls `fetchData` method to load a list of products that relate to this category.
30+
- `{ store, route }` - an object consisting of the Vuex store and global router references.
31+
32+
## Events
33+
34+
### asyncData
35+
36+
Since the app is using SSR, this method prefetches and resolves the asynchronous data before rendering happens and saves it to Vuex store. Asynchronous data for Category page is a list of all categories, category attributes and list of products for each category.
37+
38+
### beforeMount
39+
40+
`filter-changed-category` event listener is initialized. The event is fired when user selects custom filter value.
41+
42+
### beforeDestroy
43+
44+
`filter-changed-category`event listener is removed.

docs/guide/components/home-page.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Core Home Page
2+
3+
:::tip Note
4+
Core page has almost zero functionality, everything is in theme component, which definitely needs be replaced to core.
5+
:::
6+
7+
## Props
8+
9+
No props
10+
11+
## Data
12+
13+
`rootCategories` category list to be used for your own custom home page
14+
15+
## Methods
16+
17+
No methods
18+
19+
## Events
20+
21+
`home-after-load` event can be used to populate the vuex `store` with additional data required by SSR.
22+
23+
### beforeMount
24+
25+
Clears Vuex store entries that define current category by dispatching `category/reset` action.

docs/guide/components/modal.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Modal component
2+
3+
Simple modal component. Visibility of modal container is based on internal state `isVisible`. We can set this state by `$emit` event on global `$bus` event.
4+
5+
## Basic usage
6+
7+
### Component markup
8+
9+
```html
10+
<modal name="modal-example">
11+
<div> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div>
12+
</modal>
13+
```
14+
15+
### Available events:
16+
17+
```html
18+
<button @click="$bus.$emit('modal-toggle', 'modal-example')">Example</button>
19+
<button @click="$bus.$emit('modal-show', 'modal-example')">Example</button>
20+
<button @click="$bus.$emit('modal-hide', 'modal-example')">Example</button>
21+
```
22+
23+
### Available props
24+
25+
| Prop | Type | Required | Default | Description |
26+
| ----- | ------ | -------- | ------- | --------------------- |
27+
| name | String | true | | Unique name of modal |
28+
| delay | Number | false | 300 | Timeout to show modal |
29+
30+
### Available Methods
31+
32+
| Method | Argument | Description |
33+
| ------ | -------------- | ---------------------------------------------------------- |
34+
| toggle | state: Boolean | Manually toggles a modal |
35+
| close | | Alias for manually hides a modal. Helpful for Close button |
36+
37+
### Styles
38+
39+
Core component doesn't have css styles. If you want to see an example of our implementation please look [here](https://github.com/DivanteLtd/vue-storefront/blob/master/src/themes/default/components/core/Modal.vue)

0 commit comments

Comments
 (0)