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

Commit 2b900ac

Browse files
authored
Merge branch 'master' into develop
2 parents e1a9f44 + 3ddfacf commit 2b900ac

File tree

6 files changed

+352
-154
lines changed

6 files changed

+352
-154
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323

2424
- [ ] I read and followed [contribution rules](https://github.com/DivanteLtd/vue-storefront/blob/master/CONTRIBUTING.md)
2525
- [ ] I read the [TypeScript Action Plan](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/TypeScript%20Action%20Plan.md) and adjusted my PR according to it
26-
- [ ] I read about [Vue Storefront Modules](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/api-modules/about-modules.md) and [refactoring plan for them](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/api-modules/refactoring-to-modules.md)
26+
- [ ] I read about [Vue Storefront Modules](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/api-modules/about-modules.md) and I am aware that every new feature should be a module

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ Vue Storefront is a Community effort brought to You by our great Core Team and s
205205
<td align="center" valign="middle">
206206
<a href="https://divante.co/">
207207
<img
208-
src="https://divante.co/static/img/logo.svg"
208+
src="https://divante.co/about us/LOGO.png"
209209
alt="Divante"
210-
height="50"
210+
width="120"
211211
>
212212
</a>
213213
</td>
@@ -436,6 +436,53 @@ Vue Storefront is a Community effort brought to You by our great Core Team and s
436436
</a>
437437
</td>
438438
</tr>
439+
<tr>
440+
<td align="center" valign="middle">
441+
<a href="http://copex.io/">
442+
<img
443+
src="https://divante.co/partners/Vue-Storefront/copex-io-logo.png"
444+
alt="Copex.io"
445+
height="50"
446+
>
447+
</a>
448+
</td>
449+
<td align="center" valign="middle">
450+
<a href="https://www.badger.blue/">
451+
<img
452+
src="https://divante.co/partners/Vue-Storefront/BlueBadger-Logo.png"
453+
alt="Badger Blue"
454+
height="50"
455+
>
456+
</a>
457+
</td>
458+
<td align="center" valign="middle">
459+
<a href="">
460+
<img
461+
src=""
462+
alt=""
463+
height="50"
464+
>
465+
</a>
466+
</td>
467+
<td align="center" valign="middle">
468+
<a href="">
469+
<img
470+
src=""
471+
alt=""
472+
height="50"
473+
>
474+
</a>
475+
</td>
476+
<td align="center" valign="middle">
477+
<a href="">
478+
<img
479+
src=""
480+
alt=""
481+
height="50"
482+
>
483+
</a>
484+
</td>
485+
</tr>
439486
</tbody>
440487
</table>
441488

doc/api-modules/about-modules.md

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,124 @@ The purpose is well described in [this discussion](https://github.com/DivanteLtd
3939

4040
# How module should look like
4141

42-
Module by it's definition should encapsulate all logic required for the feature it represents. You can think about each module as a micro application that exposes it's parts to the outside world (Vue Storefront).
42+
43+
# Module config and capabilities
44+
45+
Module config is the object that is required to instantiate VS module. The config object you'll provide is later used to extend and hook into different parts of the application (like router, Vuex etc).
46+
Please use this object as the only part that is responsible for extending Vue Storefront. Otherwise it may stop working after some breaking core updates.
47+
48+
Vue Storefront module object with provided config should be exported in `index.ts` entry point. Ideally it should be a named export named the same as modules key.
49+
50+
This is how the signature of Vue Storefront Module looks like:
51+
```js
52+
interface VueStorefrontModuleConfig {
53+
key: string;
54+
store?: { module?: Module<any, any>, plugin?: Function };
55+
router?: { routes?: RouteConfig[], beforeEach?: NavigationGuard, afterEach?: NavigationGuard },
56+
beforeRegistration?: (Vue: VueConstructor, config: Object) => void,
57+
afterRegistration?: (Vue: VueConstructor, config: Object) => void,
58+
}
59+
```
60+
#### `key` (required)
61+
62+
Key is an ID of your module. It's used to identify your module and to set keys in all key-based extendings that module is doing (like creating namespaced store). This key should be unique. You can duplicate the keys of some other modules only if you want to extend them. Modules with the same keys will be merged.
63+
64+
#### `store`
65+
66+
Extension point for Vuex. It can be provided with vuex module and Vuex plugin object to subscribe for mutations. In case of conflicting module keys they are deep merged in favour of most recent instantiated one.
67+
68+
#### `router`
4369

4470
Normally module can (but not must) contain following folders:
4571

46-
- `components` - components related to this module (eg. Microcart for Cart module)
47-
- `store` - Vuex store associated to module
48-
- `helpers` - everything else that is meant to support modules behavior
49-
- `types` - TypeScript types associated with module
50-
- `test` - folder with unit tests which is *required* for every new or rewritten module. This folder can be placed outside of the module in 'tests' folder.
51-
- `extends` - code that you need to include into core files such as client/server entry, app entry, webpack config or service worker. If you need to extend, let's say `client-entry.js`just create a file with the same name and import it in the core `client-entry.js` by invoking files content with `import core/module/module-name/extends/client-entry.js
72+
#### `beforeRegistration`
73+
74+
Function that'll be called before registering the module both on server and client side. You have access to `Vue` and `config` objects inside.
75+
76+
#### `afterRegistration`
77+
78+
Function that'll be called after registering the module both on server and client side. You have access to `Vue` and `config` objects inside.
5279

80+
# Module file structure
5381

54-
[*] currently we are using `core/api/module_name` instead of `module/module_name` but it's about to change soon
82+
Below you can see recommended file structure for VS module. All of the core ones are organised in this way.
83+
Try to have similar file structure inside the ones that you create. If all of modules will implement similar architeture it'll be easier to maintain and understand them. If there is no purpose in organising some of it's parts differently try to avoid it.
84+
85+
Not all of this folders and files needs to be in every module. The only mandatory file is `index.ts` which is the entry point. The rest depends on your needs and module functionality.
86+
87+
- `components` - Components logic related to this module (eg. Microcart for Cart module). Normally it contains `.ts` files but you can also create `.vue` files and provide some baseline markup if it is required for the compoennt to work out of the box.
88+
- `pages` - If you want to provide full pages with your module palce them here. It's also a good practice to extend router configuration for this pages
89+
- `store` - Vuex Module associated to this module
90+
- `index.ts` - Entry point and main export of your Vuex Module. Ations/getters/mutations can be splitted into different files if logic is too complex to keep it in one file. Should be used in `store` config property.
91+
- `mutation-types.ts` - Mutation strings represented by variables to use instead of plain strings
92+
- `plugins.ts` - Good place to put vuex plugin. Should be used in `store.plugins` config object
93+
- `types` - TypeScript types associated with module
94+
- `test` - Folder with unit tests which is *required* for every new or rewritten module.
95+
- `hooks` - before/after hooks that are called before and after registration of module.
96+
- `beforeRegistration.ts` - Should be used in `beforeRegistration` config property.
97+
- `bafterRegistration.ts` - Should be used in `afterRegistration` config property.
98+
- `router` - routes and navigation guards associated to this module
99+
- `routes.ts`- array of route objects that will be added to current router configuration. Should be used in `router.routes` config property.
100+
- `beforeEach.ts` - beforEeach navigation guard. Should be used in `router.beforeEach` config property.
101+
- `afterEach.ts`- afterEach navigation guard. Should be used in `router.afterEach` config property.
102+
- `queries` - GraphQL queries
103+
- `helpers` - everything else that is meant to support modules behavior
104+
- `index.js` - entry point for the module. Should export VueStorefrontModule. It's also a good palce to instantiate cache storage.
105+
106+
# Rules and good practices
107+
108+
First take a look at module template. It cointains great examples, good practices and explainations for everything that can be putted in module.
109+
110+
1. **Try not to rely on any other data sources than `config`**. Use other stores only if it's the only way to achieve some functionality and import `rootStore` for this purposes. Modules should be standalone and rely only on themeselves
111+
2. Place all reusable features as a Vuex actions (e.g. `addToCart(product)`, `subscribeNewsletter()` etc) instead of placing them in components. try to use getters for modified or filtered values from state. We are trying to place most of the logic in Vuex stores to allow easier core updates. Here is a good example of such externalisation.
112+
````js
113+
export const Microcart = {
114+
name: 'Microcart',
115+
computed: {
116+
productsInCart () : Product[] {
117+
return this.$store.state.cart.cartItems
118+
},
119+
appliedCoupon () : AppliedCoupon | false {
120+
return this.$store.getters['cart/coupon']
121+
},
122+
totals () : CartTotalSegments {
123+
return this.$store.getters['cart/totals']
124+
},
125+
isMicrocartOpen () : boolean {
126+
return this.$store.state.ui.microcart
127+
}
128+
},
129+
methods: {
130+
applyCoupon (code: String) : Promise<boolean> {
131+
return this.$store.dispatch('cart/applyCoupon', code)
132+
},
133+
removeCoupon () : Promise<boolean> {
134+
return this.$store.dispatch('cart/removeCoupon')
135+
},
136+
toggleMicrocart () : void {
137+
this.$store.dispatch('ui/toggleMicrocart')
138+
}
139+
}
140+
}
141+
````
142+
3. Don't use EventBus.
143+
4. If you want to inform about success/failure of core component's method you can eaither use a callback or scoped event. Omit Promises if you thing that function can be called from the template and you'll need the resolved value. This is a good example of method that you can call either on `template` ot `script` section:
144+
````js
145+
addToCart(product, success, failure) {
146+
this.$store.dispatch('cart/addToCart').then(res =>
147+
success(res)
148+
).catch(err =>
149+
failure(err)
150+
)
151+
}
152+
````
153+
154+
Try to choose method basing on use case. [This](https://github.com/DivanteLtd/vue-storefront/blob/develop/core/modules/mailchimp/components/Subscribe.ts#L28) is a good example of using callbacks.
155+
156+
5. Create pure functions that can be easly called with different argument. Rely on `data` properties instead of arguments only if it's required (for example they are validated like [here](https://github.com/DivanteLtd/vue-storefront/blob/develop/core/modules/mailchimp/components/Subscribe.ts#L28).
157+
6. Document exported compoennts like in example: https://github.com/DivanteLtd/vue-storefront/blob/develop/core/modules/mailchimp/components/Subscribe.ts
158+
7. If your module core functionality is an integration with external service better name it the same as this service (for example `mailchimp`)
159+
8. Use named exports and typecheck.
55160

56161
# Contributions
57162

doc/api-modules/cart.md

Lines changed: 47 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,49 @@
11
# Cart module
22

3-
The cart module as name suggests is a set of mixins responsible for interacting with Cart. You can find methods responsible for adding/removing/getting cart items along with optional UI interactions for microcart.
4-
5-
## Content
6-
7-
#### addToCart
8-
- [method] addToCart(product)
9-
10-
#### removeFromCart
11-
- [method] removeFromCart(product)
12-
13-
#### applyCoupon
14-
- [method] applyCoupon(code)
15-
16-
#### removeCoupon
17-
- [method] removeCoupon()
18-
19-
#### productsInCart
20-
- [computed] productsInCart
21-
22-
#### cartTotals
23-
- [computed] cartTotals
24-
25-
#### cartShipping
26-
- [computed] cartShipping
27-
28-
#### cartPayment
29-
- [computed] cartPayment
30-
31-
#### appliedCoupon
32-
- [computed] appliedCoupon
33-
34-
## UI helpers
35-
36-
#### openMicrocart
37-
- [method] openMicrocart()
38-
39-
#### closeMicrocart
40-
- [method] openMicrocart()
41-
42-
#### isMicrocartOpen
43-
- [computed] isMicrocartOpen
44-
45-
## Example
46-
47-
````javascript
48-
// Inside Vue component
49-
import {
50-
addToCart,
51-
removeFromCart,
52-
applyCoupon,
53-
removeCoupon,
54-
productsInCart,
55-
appliedCoupon,
56-
totals,
57-
shipping,
58-
payment,
59-
closeMicrocart,
60-
openMicrocart,
61-
isMicrocartOpen
62-
} from '@vue-storefront/core/modules/cart/features'
63-
64-
export default {
65-
//...other properties
66-
mixins: [
67-
addToCart,
68-
removeFromCart,
69-
applyCoupon,
70-
removeCoupon,
71-
productsInCart,
72-
appliedCoupon,
73-
totals,
74-
shipping,
75-
payment,
76-
closeMicrocart,
77-
openMicrocart,
78-
isMicrocartOpen
79-
]
80-
}
81-
````
3+
This module contains all logic and components related to cart operations.
4+
5+
## Components
6+
7+
### AddToCart
8+
Component responsible for adding product to the cart
9+
10+
**Props**
11+
- `product` - product that'll be added to cart
12+
13+
**Methods**
14+
- `addToCart(product)` - adds passed product to the cart. By default correlates with `product` prop
15+
16+
### Microcart
17+
Microcart component.
18+
19+
**Computed**
20+
- `productsInCart` - array of products that are currently in the cart
21+
- `appliedCoupon` - return applied cart coupon or false if no coupon was applied
22+
-` totals` - cart totals
23+
- `isMicrocartOpen` - returns true if microcart is open
24+
25+
**Methods**
26+
- `applyCoupon(code)` - appies cart coupon
27+
- `removeCoupon()` removes currently applied cart coupon
28+
- 'toggleMicrocart' - open/close microcart
29+
30+
### MicrocartButton
31+
Component responsible for opening/closing Microcart
32+
33+
**Computed**
34+
- `quantity` - number of products in cart
35+
36+
**Methods**
37+
- `toggleMicrocart` - open/close microcart
38+
39+
### Product
40+
Component representing product in microcart. Allows to modify it's quantity or remove from cart.
41+
42+
**Compued**
43+
- `thumbnail` - returns src of products thumbnail
44+
45+
**Methods**
46+
- `removeFromCart` - removes current product (data property `product`) from cart
47+
- `updateQuantity` - updates cart quantity for current product (data property `product`)
48+
49+

docs/guide/installation/windows.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ docker-compose up
3939

4040
This step can take some minutes.
4141

42+
Note: If it appears that docker-compose is hanging, try opening a new terminal and continue to the next step using that terminal. Allow docker-compose to continue running in the background.
43+
4244
6. Restore products database and run latest migrations
4345

4446
```bash

0 commit comments

Comments
 (0)