Skip to content

Commit

Permalink
Merge branch 'develop' into vs-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
filrak authored Nov 29, 2018
2 parents 51a58aa + f31430e commit a44b86c
Show file tree
Hide file tree
Showing 47 changed files with 1,244 additions and 433 deletions.
12 changes: 10 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,17 @@
"localForage": {
"defaultDrivers": {
"user": "LOCALSTORAGE",
"cmspage": "INDEXEDDB",
"cmsblock": "INDEXEDDB",
"carts": "LOCALSTORAGE",
"orders": "LOCALSTORAGE",
"wishlist": "INDEXEDDB",
"categories": "INDEXEDDB",
"attributes": "INDEXEDDB",
"attributes": "LOCALSTORAGE",
"products": "INDEXEDDB",
"elasticCache": "INDEXEDDB",
"claims": "LOCALSTORAGE",
"syncTasks": "INDEXEDDB",
"syncTasks": "LOCALSTORAGE",
"ordersHistory": "INDEXEDDB",
"checkoutFieldValues": "LOCALSTORAGE"
}
Expand Down Expand Up @@ -300,6 +302,12 @@
"endpoint": "http://localhost:8080/api/ext/cms-data/cms{{type}}/{{cmsId}}",
"endpointIdentifier": "http://localhost:8080/api/ext/cms-data/cms{{type}}Identifier/{{cmsIdentifier}}/storeId/{{storeId}}"
},
"cms_block": {
"max_count": 500
},
"cms_page": {
"max_count": 500
},
"usePriceTiers": false,
"boost": {
"name": 3,
Expand Down
4 changes: 2 additions & 2 deletions core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function _commonErrorHandler (err, reject) {
if (err.message.indexOf('query returned empty result') > 0) {
rootStore.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t('The product or category is not available in Offline mode. Redirecting to Home.'),
message: i18n.t('The product, category or CMS page is not available in Offline mode. Redirecting to Home.'),
action1: { label: i18n.t('OK') }
})
router.push('/')
Expand Down Expand Up @@ -252,7 +252,7 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {
console.debug('Current User token = ' + currentToken)
console.debug('Current Cart token = ' + currentCartId)
syncTaskCollection.iterate((task, id, iterationNumber) => {
if (!task.transmited && !mutex[id]) { // not sent to the server yet
if (task && !task.transmited && !mutex[id]) { // not sent to the server yet
mutex[id] = true // mark this task as being processed
fetchQueue.push(() => {
return execute(task, currentToken, currentCartId).then(executedTask => {
Expand Down
2 changes: 1 addition & 1 deletion core/i18n/resource/i18n/en-US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
"login","login"
"to account","to account"
"Are you sure you would like to remove this item from the shopping cart?","Are you sure you would like to remove this item from the shopping cart?"
"The product or category is not available in Offline mode. Redirecting to Home.","The product or category is not available in Offline mode. Redirecting to Home."
"The product, category or CMS page is not available in Offline mode. Redirecting to Home.","The product, category or CMS page is not available in Offline mode. Redirecting to Home."
"Please configure product bundle options and fix the validation errors","Please configure product bundle options and fix the validation errors"
"Processing order...","Processing order..."
9 changes: 7 additions & 2 deletions core/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Module, Store } from 'vuex'
import { RouteConfig, NavigationGuard } from 'vue-router'
import Vue, { VueConstructor } from 'vue'
import merge from 'lodash-es/merge'
import RootState from '@vue-storefront/store/types/RootState';
import RootState from '@vue-storefront/store/types/RootState'
import rootStore from '@vue-storefront/store'
import { Logger } from '@vue-storefront/core/lib/logger'
import { setupMultistoreRoutes } from '@vue-storefront/store/lib/multistore'

export interface VueStorefrontModuleConfig {
key: string;
Expand Down Expand Up @@ -40,7 +42,10 @@ export class VueStorefrontModule {
}

private static _extendRouter (routerInstance, routes?: RouteConfig[], beforeEach?: NavigationGuard, afterEach?: NavigationGuard): void {
if (routes) routerInstance.addRoutes(routes)
if (routes) {
setupMultistoreRoutes(rootStore.state.config, routerInstance, routes)
routerInstance.addRoutes(routes)
}
if (beforeEach) routerInstance.beforeEach(beforeEach)
if (afterEach) routerInstance.afterEach(afterEach)
}
Expand Down
2 changes: 2 additions & 0 deletions core/modules-entry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

import { VueStorefrontModule } from '@vue-storefront/core/lib/module'
import { Wishlist } from './modules/wishlist'
import { Cms } from './modules/cms'
import { Order } from './modules/order'
import { User } from './modules/user'
import { registerModules } from 'src/modules'
import { Breadcrumbs } from './modules/breadcrumbs'
export const enabledModules: VueStorefrontModule[] = [
Breadcrumbs,
Wishlist,
Cms,
Order,
User,
...registerModules
Expand Down
45 changes: 24 additions & 21 deletions core/modules/catalog/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,36 @@ export function doPlatformPricesSync (products) {
const childSkus = flattenDeep(products.map((p) => { return (p.configurable_children) ? p.configurable_children.map((cc) => { return cc.sku }) : null }))
skus = union(skus, childSkus)
}
console.log('Starting platform prices sync for', skus) // TODO: add option for syncro and non syncro return

rootStore.dispatch('product/syncPlatformPricesOver', { skus: skus }, { root: true }).then((syncResult) => {
if (syncResult) {
syncResult = syncResult.items

for (let product of products) {
const backProduct = syncResult.find((itm) => { return itm.id === product.id })
if (backProduct) {
product.price_is_current = true // in case we're syncing up the prices we should mark if we do have current or not
product.price_refreshed_at = new Date()
product = syncProductPrice(product, backProduct)

if (product.configurable_children) {
for (let configurableChild of product.configurable_children) {
const backProductChild = syncResult.find((itm) => { return itm.id === configurableChild.id })
if (backProductChild) {
configurableChild = syncProductPrice(configurableChild, backProductChild)
if (skus && skus.length > 0) {
console.log('Starting platform prices sync for', skus) // TODO: add option for syncro and non syncro return
rootStore.dispatch('product/syncPlatformPricesOver', { skus: skus }, { root: true }).then((syncResult) => {
if (syncResult) {
syncResult = syncResult.items

for (let product of products) {
const backProduct = syncResult.find((itm) => { return itm.id === product.id })
if (backProduct) {
product.price_is_current = true // in case we're syncing up the prices we should mark if we do have current or not
product.price_refreshed_at = new Date()
product = syncProductPrice(product, backProduct)

if (product.configurable_children) {
for (let configurableChild of product.configurable_children) {
const backProductChild = syncResult.find((itm) => { return itm.id === configurableChild.id })
if (backProductChild) {
configurableChild = syncProductPrice(configurableChild, backProductChild)
}
}
}
// TODO: shall we update local storage here for the main product?
}
// TODO: shall we update local storage here for the main product?
}
}
}
resolve(products)
})
} else { // empty list of products
resolve(products)
})
}
if (!rootStore.state.config.products.waitForPlatformSync && !Vue.prototype.$isServer) {
console.log('Returning products, the prices yet to come from backend!')
for (let product of products) {
Expand Down
20 changes: 20 additions & 0 deletions core/modules/cms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { cmsPageModule } from './store/page'
import { cmsBlockModule } from './store/block'
import { cmsHierarchyModule } from './store/hierarchy'
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module'
import { plugin } from './store/plugin'
import { initCacheStorage } from '@vue-storefront/core/helpers/initCacheStorage';

export const KEY = 'cms'
export const cacheStorage = initCacheStorage(KEY)

const moduleConfig: VueStorefrontModuleConfig = {
key: KEY,
store: { modules: [
{ key: 'cmsPage', module: cmsPageModule },
{ key: 'cmsBlock', module: cmsBlockModule },
{ key: 'cmsHierarchy', module: cmsHierarchyModule }
], plugin },
}

export const Cms = new VueStorefrontModule(moduleConfig)
90 changes: 90 additions & 0 deletions core/modules/cms/store/block/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { ActionTree } from "vuex"
import { quickSearchByQuery } from '@vue-storefront/store/lib/search'
import * as types from './mutation-types'
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery'
import RootState from '@vue-storefront/store/types/RootState';
import CmsBlockState from "../../types/CmsBlockState"

const actions: ActionTree<CmsBlockState, RootState> = {

/**
* Retrieve cms blocks
*
* @param context
* @param {any} filterValues
* @param {any} filterField
* @param {any} size
* @param {any} start
* @param {any} excludeFields
* @param {any} includeFields
* @returns {Promise<T> & Promise<any>}
*/
list (context, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) {
let query = new SearchQuery()
if (filterValues) {
query = query.applyFilter({key: filterField, value: {'like': filterValues}})
}
if (skipCache || (!context.state.items || context.state.items.length === 0)) {
return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
.then((resp) => {
context.commit(types.CMS_BLOCK_UPDATE_CMS_BLOCKS, resp.items)
return resp.items
})
.catch(err => {
console.error(err)
})
} else {
return new Promise((resolve, reject) => {
let resp = context.state.items
resolve(resp)
})
}
},

/**
* Retrieve single cms block by key value
*
* @param context
* @param {any} key
* @param {any} value
* @param {any} excludeFields
* @param {any} includeFields
* @returns {Promise<T> & Promise<any>}
*/
single (context, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false }) {
const state = context.state
if (skipCache || (!state.items || state.items.length === 0)) {
let query = new SearchQuery()
if (value) {
query = query.applyFilter({key: key, value: {'like': value}})
}
return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
.then((resp) => {
context.commit(types.CMS_BLOCK_ADD_CMS_BLOCK, resp.items[0])
return resp.items[0]
})
.catch(err => {
console.error(err)
})
} else {
return new Promise((resolve, reject) => {
if (state.items.length > 0) {
let cmsBlock = state.items.find((itm) => { return itm[key] === value })
if (cmsBlock) {
resolve(cmsBlock)
} else {
reject(new Error('CMS block query returned empty result ' + key + ' = ' + value))
}
} else {
resolve()
}
})
}
},

addItem ({ commit }, block) {
commit(types.CMS_BLOCK_ADD_CMS_BLOCK, block )
}
}

export default actions
15 changes: 15 additions & 0 deletions core/modules/cms/store/block/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GetterTree } from 'vuex'
import CmsBlockState from '../../types/CmsBlockState'
import RootState from '@vue-storefront/store/types/RootState'

const getters: GetterTree<CmsBlockState, RootState> = {
cmsBlocks: (state) => state.items,
cmsBlockIdentifier: (state) => (identifier) => {
return state.items.find(item => item.identifier === identifier)
},
cmsBlockId: (state) => (id) => {
return state.items.find(item => item.id === id)
},
}

export default getters
18 changes: 18 additions & 0 deletions core/modules/cms/store/block/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Module } from 'vuex'
import actions from './actions'
import getters from './getters'
import mutations from './mutations'
import RootState from '@vue-storefront/store/types/RootState'
import CmsBlockState from '../../types/CmsBlockState'

export const cmsBlockStorageKey = 'cms-blocks'

export const cmsBlockModule: Module<CmsBlockState, RootState> = {
namespaced: true,
state: {
items: [],
},
getters,
actions,
mutations
}
3 changes: 3 additions & 0 deletions core/modules/cms/store/block/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SN_CMS_BLOCK = 'cmsBlock'
export const CMS_BLOCK_UPDATE_CMS_BLOCKS = SN_CMS_BLOCK + '/UPDATE_CMS_BLOCKS'
export const CMS_BLOCK_ADD_CMS_BLOCK = SN_CMS_BLOCK + '/ADD_CMS_BLOCK'
22 changes: 22 additions & 0 deletions core/modules/cms/store/block/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MutationTree } from 'vuex'
import * as types from './mutation-types'
import CmsBlockState from '../../types/CmsBlockState'

const mutations: MutationTree<CmsBlockState> = {
/**
* Store CMS Blocks by identifier in state and localForage
* @param {} state
* @param {Array} cmsBlocks
*/
[types.CMS_BLOCK_UPDATE_CMS_BLOCKS] (state, cmsBlocks) {
state.items = cmsBlocks || []
},
[types.CMS_BLOCK_ADD_CMS_BLOCK] (state, cmsBlock ) {
const record = state.items.find(c => c.id === cmsBlock.id)
if (!record) {
state.items.push(cmsBlock)
}
}
}

export default mutations
31 changes: 31 additions & 0 deletions core/modules/cms/store/hierarchy/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ActionTree } from "vuex"
import { quickSearchByQuery } from '@vue-storefront/store/lib/search'
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery'
import RootState from '@vue-storefront/store/types/RootState';
import CmsHierarchyState from "../../types/CmsHierarchyState"

const actions: ActionTree<CmsHierarchyState, RootState> = {
/**
* Retrieve cms hierarchy
*
* @param context
* @param {any} query
* @param {any} entityType
* @param {any} excludeFields
* @param {any} includeFields
* @returns {Promise<T> & Promise<any>}
*/
list (context, { id, entityType = 'cms_hierarchy', excludeFields = null, includeFields = null}) {
let query = new SearchQuery()

if (id) {
query = query.applyFilter({key: 'identifier', value: {'eq': id}})
}

return quickSearchByQuery({ query, entityType, excludeFields, includeFields }).catch(err => {
console.error(err)
})
}
}

export default actions
13 changes: 13 additions & 0 deletions core/modules/cms/store/hierarchy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from 'vuex'
import actions from './actions'
import RootState from '@vue-storefront/store/types/RootState'
import CmsHierarchyState from '../../types/CmsHierarchyState'

export const cmsHierarchyModule: Module<CmsHierarchyState, RootState> = {
namespaced: true,
state: {
items: [],
},
actions
}

2 changes: 2 additions & 0 deletions core/modules/cms/store/hierarchy/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SN_CMS_HIERARCHY = 'cms_hierarchy'
export const CMS_HIERARCHY_UPDATE_CMS_HIERARCHIES = SN_CMS_HIERARCHY + '/UPDATE_CMS_HIERARCHIES'
Loading

0 comments on commit a44b86c

Please sign in to comment.