Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


### Fixed
- Update eslint and fix code style. - @gibkigonzo (#4179 #4181)
- add missing cache tags for category and product - @gibkigonzo (#4173)

## [1.11.2] - 2020.03.10
Expand Down
6 changes: 3 additions & 3 deletions core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu
store.state.__DEMO_MODE__ = (config.demomode === true)
if (ssrContext) {
// @deprecated - we shouldn't share server context between requests
Vue.prototype.$ssrRequestContext = {output: {cacheTags: ssrContext.output.cacheTags}}
Vue.prototype.$ssrRequestContext = { output: { cacheTags: ssrContext.output.cacheTags } }

Vue.prototype.$cacheTags = ssrContext.output.cacheTags
}
Expand All @@ -60,7 +60,7 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu
// @deprecated from 2.0
once('__VUE_EXTEND__', () => {
Vue.use(Vuelidate)
Vue.use(VueLazyload, {attempt: 2, preLoad: 1.5})
Vue.use(VueLazyload, { attempt: 2, preLoad: 1.5 })
Vue.use(Meta)
Vue.use(VueObserveVisibility)

Expand All @@ -85,7 +85,7 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu
}

const apolloProvider = await getApolloProvider()
if (apolloProvider) Object.assign(vueOptions, {provider: apolloProvider})
if (apolloProvider) Object.assign(vueOptions, { provider: apolloProvider })

const app = new Vue(vueOptions)

Expand Down
4 changes: 2 additions & 2 deletions core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const invokeClientEntry = async () => {
const matched = router.getMatchedComponents(to)
if (to) { // this is from url
if (globalConfig.storeViews.multistore === true) {
const currentRoute = Object.assign({}, to, {host: window.location.host})
const currentRoute = Object.assign({}, to, { host: window.location.host })
const storeCode = storeCodeFromRoute(currentRoute)
const currentStore = currentStoreView()
if (storeCode !== '' && storeCode !== null) {
Expand All @@ -104,7 +104,7 @@ const invokeClientEntry = async () => {
return next()
}

store.dispatch('url/setCurrentRoute', {to, from})
store.dispatch('url/setCurrentRoute', { to, from })

Promise.all(matched.map((c: any) => { // TODO: update me for mixins support
const components = c.mixins && globalConfig.ssr.executeMixedinAsyncData ? Array.from(c.mixins) : []
Expand Down
14 changes: 7 additions & 7 deletions core/data-resolver/CategoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ const getCategories = async ({
}: DataResolver.CategorySearchOptions = {}): Promise<Category[]> => {
let searchQuery = new SearchQuery()
if (parentId) {
searchQuery = searchQuery.applyFilter({key: 'parent_id', value: {'eq': parentId}})
searchQuery = searchQuery.applyFilter({ key: 'parent_id', value: { 'eq': parentId } })
}
if (level) {
searchQuery = searchQuery.applyFilter({key: 'level', value: {'eq': level}})
searchQuery = searchQuery.applyFilter({ key: 'level', value: { 'eq': level } })
}

for (var [key, value] of Object.entries(filters)) {
if (value !== null) {
if (Array.isArray(value)) {
searchQuery = searchQuery.applyFilter({key: key, value: {'in': value}})
searchQuery = searchQuery.applyFilter({ key: key, value: { 'in': value } })
} else if (typeof value === 'object') {
searchQuery = searchQuery.applyFilter({key: key, value: value})
searchQuery = searchQuery.applyFilter({ key: key, value: value })
} else {
searchQuery = searchQuery.applyFilter({key: key, value: {'eq': value}})
searchQuery = searchQuery.applyFilter({ key: key, value: { 'eq': value } })
}
}
}

if (onlyActive === true) {
searchQuery = searchQuery.applyFilter({key: 'is_active', value: {'eq': true}})
searchQuery = searchQuery.applyFilter({ key: 'is_active', value: { 'eq': true } })
}

if (onlyNotEmpty === true) {
searchQuery = searchQuery.applyFilter({key: 'product_count', value: {'gt': 0}})
searchQuery = searchQuery.applyFilter({ key: 'product_count', value: { 'gt': 0 } })
}
const response = await quickSearchByQuery({ entityType: 'category', query: searchQuery, sort: sort, size: size, start: start, includeFields: includeFields, excludeFields: excludeFields })
return response.items as Category[]
Expand Down
16 changes: 8 additions & 8 deletions core/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ export function productThumbnailPath (product, ignoreConfig = false) {
export function baseFilterProductsQuery (parentCategory, filters = []) { // TODO add aggregation of color_options and size_options fields
let searchProductQuery = new SearchQuery()
searchProductQuery = searchProductQuery
.applyFilter({key: 'visibility', value: {'in': [2, 3, 4]}})
.applyFilter({key: 'status', value: {'in': [0, 1]}}) /* 2 = disabled, 4 = out of stock */
.applyFilter({ key: 'visibility', value: { 'in': [2, 3, 4] } })
.applyFilter({ key: 'status', value: { 'in': [0, 1] } }) /* 2 = disabled, 4 = out of stock */

if (config.products.listOutOfStockProducts === false) {
searchProductQuery = searchProductQuery.applyFilter({key: 'stock.is_in_stock', value: {'eq': true}})
searchProductQuery = searchProductQuery.applyFilter({ key: 'stock.is_in_stock', value: { 'eq': true } })
}
// Add available catalog filters
for (let attrToFilter of filters) {
searchProductQuery = searchProductQuery.addAvailableFilter({field: attrToFilter, scope: 'catalog'})
searchProductQuery = searchProductQuery.addAvailableFilter({ field: attrToFilter, scope: 'catalog' })
}

let childCats = [parentCategory.id]
Expand All @@ -145,7 +145,7 @@ export function baseFilterProductsQuery (parentCategory, filters = []) { // TODO
}
recurCatFinderBuilder(parentCategory)
}
searchProductQuery = searchProductQuery.applyFilter({key: 'category_ids', value: {'in': childCats}})
searchProductQuery = searchProductQuery.applyFilter({ key: 'category_ids', value: { 'in': childCats } })
return searchProductQuery
}

Expand All @@ -159,17 +159,17 @@ export function buildFilterProductsQuery (currentCategory, chosenFilters = {}, d

if (Array.isArray(filter) && attributeCode !== 'price') {
const values = filter.map(filter => filter.id)
filterQr = filterQr.applyFilter({key: attributeCode, value: {'in': values}, scope: 'catalog'})
filterQr = filterQr.applyFilter({ key: attributeCode, value: { 'in': values }, scope: 'catalog' })
} else if (attributeCode !== 'price') {
filterQr = filterQr.applyFilter({key: attributeCode, value: {'eq': filter.id}, scope: 'catalog'})
filterQr = filterQr.applyFilter({ key: attributeCode, value: { 'eq': filter.id }, scope: 'catalog' })
} else { // multi should be possible filter here?
const rangeqr = {}
const filterValues = Array.isArray(filter) ? filter : [filter]
filterValues.forEach(singleFilter => {
if (singleFilter.from) rangeqr['gte'] = singleFilter.from
if (singleFilter.to) rangeqr['lte'] = singleFilter.to
})
filterQr = filterQr.applyFilter({key: attributeCode, value: rangeqr, scope: 'catalog'})
filterQr = filterQr.applyFilter({ key: attributeCode, value: rangeqr, scope: 'catalog' })
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ const logger = new Logger(
buildTimeConfig.console.showErrorOnProduction
)

export {logger as Logger}
export { logger as Logger }
72 changes: 36 additions & 36 deletions core/lib/multistore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ export function localizedDispatcherRouteName (routeName: string, storeCode: stri
return routeName
}

/**
* Returns route path with proper language prefix
* @param path - route path
* @param storeCode - language prefix specified in global config
*/
export function localizedRoutePath (path: string, storeCode: string): string {
const _path = path.startsWith('/') ? path.slice(1) : path

return `/${storeCode}/${_path}`
}

/**
* Returns transformed route config with language
* @param route - route config object
* @param storeCode - language prefix specified in global config
* @param isChildRoute - determines if route config is for child route
*/
export function localizedRouteConfig (route: RouteConfig, storeCode: string, isChildRoute: boolean = false): RouteConfig {
// note: we need shallow copy to prevent modifications in provided route object
const _route = { ...route }

if (_route.name && storeCode) {
_route.name = `${storeCode}-${_route.name}`
}

if (_route.path && !isChildRoute) {
_route.path = localizedRoutePath(_route.path, storeCode)
}

if (_route.children) {
_route.children = _route.children.map(childRoute => localizedRouteConfig(childRoute, storeCode, true))
}

return _route
}

export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig | RawLocation, storeCode: string = null): any {
if (!storeCode) {
storeCode = currentStoreView().storeCode
Expand Down Expand Up @@ -198,39 +234,3 @@ export function setupMultistoreRoutes (config, router: VueRouter, routes: RouteC
}
router.addRoutes(allRoutes, true, priority)
}

/**
* Returns transformed route config with language
* @param route - route config object
* @param storeCode - language prefix specified in global config
* @param isChildRoute - determines if route config is for child route
*/
export function localizedRouteConfig (route: RouteConfig, storeCode: string, isChildRoute: boolean = false): RouteConfig {
// note: we need shallow copy to prevent modifications in provided route object
const _route = {...route}

if (_route.name && storeCode) {
_route.name = `${storeCode}-${_route.name}`
}

if (_route.path && !isChildRoute) {
_route.path = localizedRoutePath(_route.path, storeCode)
}

if (_route.children) {
_route.children = _route.children.map(childRoute => localizedRouteConfig(childRoute, storeCode, true))
}

return _route
}

/**
* Returns route path with proper language prefix
* @param path - route path
* @param storeCode - language prefix specified in global config
*/
export function localizedRoutePath (path: string, storeCode: string): string {
const _path = path.startsWith('/') ? path.slice(1) : path

return `/${storeCode}/${_path}`
}
2 changes: 1 addition & 1 deletion core/lib/search/adapter/api/elasticsearch/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function getFunctionScores () {
}
}
if (filter.length) {
return {'functions': filter,
return { 'functions': filter,
'score_mode': config.score_mode ? config.score_mode : 'multiply',
'boost_mode': config.boost_mode ? config.boost_mode : 'multiply',
'max_boost': config.max_boost ? config.max_boost : 100,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/search/adapter/api/elasticsearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function prepareElasticsearchQueryBody (searchQuery) {
}
// Get searchable fields based on user-defined config.
let getQueryBody = function (b) {
let searchableAttributes = config.elasticsearch.hasOwnProperty('searchableAttributes') ? config.elasticsearch.searchableAttributes : {'name': {'boost': 1}}
let searchableAttributes = config.elasticsearch.hasOwnProperty('searchableAttributes') ? config.elasticsearch.searchableAttributes : { 'name': { 'boost': 1 } }
let searchableFields = [
]
for (const attribute of Object.keys(searchableAttributes)) {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/search/adapter/graphql/searchAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prepareQueryVars } from './gqlQuery'
import { currentStoreView, prepareStoreView } from '../../../multistore'
import fetch from 'isomorphic-fetch'
import {processESResponseType, processProductsType, processCmsType} from './processor/processType'
import { processESResponseType, processProductsType, processCmsType } from './processor/processType'
import SearchQuery from '../../searchQuery'
import config from 'config'

Expand Down
10 changes: 5 additions & 5 deletions core/lib/search/adapter/test/unit/searchAdapterFactory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getSearchAdapter} from '@vue-storefront/core/lib/search/adapter/searchAdapterFactory'
import { getSearchAdapter } from '@vue-storefront/core/lib/search/adapter/searchAdapterFactory'

jest.mock('config', () => {
return {server: {api: 'api'}};
return { server: { api: 'api' } };
});
jest.mock('@vue-storefront/core/lib/logger', () => ({
Logger: {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Search adapter factory tests', () => {
() => {
return {};
},
{virtual: true}
{ virtual: true }
)

await expect(getSearchAdapter('virtual')).rejects.toThrowError(new Error('Search adapter class is not provided'))
Expand All @@ -60,7 +60,7 @@ describe('Search adapter factory tests', () => {
})
}
},
{virtual: true}
{ virtual: true }
)

await expect(getSearchAdapter('invalidSearchMethod'))
Expand All @@ -83,7 +83,7 @@ describe('Search adapter factory tests', () => {
})
}
},
{virtual: true}
{ virtual: true }
)

await expect(getSearchAdapter('invalidRegisterEntityTypeMethod'))
Expand Down
4 changes: 2 additions & 2 deletions core/lib/search/searchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SearchQuery {
* @param {Object}
* @return {Object}
*/
applyFilter ({key, value, scope = 'default', options = Object}) {
applyFilter ({ key, value, scope = 'default', options = Object }) {
this._appliedFilters.push({
attribute: key,
value: value,
Expand All @@ -47,7 +47,7 @@ class SearchQuery {
* @param {Object}
* @return {Object}
*/
addAvailableFilter ({field, scope = 'default', options = {}}) {
addAvailableFilter ({ field, scope = 'default', options = {} }) {
// value can has only String, Array or numeric type
this._availableFilters.push({
field: field,
Expand Down
4 changes: 2 additions & 2 deletions core/lib/test/unit/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ describe('Logger', () => {
jest.isolateModules(() => {
const Logger = require('../../logger').Logger

expect(Logger.convertToString({foo: 'bar'})).toBe('{"foo":"bar"}')
expect(Logger.convertToString({ foo: 'bar' })).toBe('{"foo":"bar"}')
})
})

it('extracts message from complex objects (i.e. error)', () => {
jest.isolateModules(() => {
const Logger = require('../../logger').Logger

expect(Logger.convertToString({message: 'foo'})).toBe('foo')
expect(Logger.convertToString({ message: 'foo' })).toBe('foo')
})
})
it('returns primitive payloads unchanged', () => {
Expand Down
6 changes: 3 additions & 3 deletions core/lib/test/unit/multistore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jest.mock('@vue-storefront/core/app', () => ({
}
}))
jest.mock('../../../store', () => ({}))
jest.mock('@vue-storefront/i18n', () => ({loadLanguageAsync: jest.fn()}))
jest.mock('../../sync/task', () => ({initializeSyncTaskStorage: jest.fn()}))
jest.mock('@vue-storefront/i18n', () => ({ loadLanguageAsync: jest.fn() }))
jest.mock('../../sync/task', () => ({ initializeSyncTaskStorage: jest.fn() }))
jest.mock('@vue-storefront/core/hooks', () => ({ coreHooksExecutors: {
beforeStoreViewChanged: jest.fn(args => args),
afterStoreViewChanged: jest.fn(args => args)
}}))
} }))
jest.mock('@vue-storefront/core/lib/logger', () => ({
Logger: {}
}))
Expand Down
2 changes: 1 addition & 1 deletion core/modules/breadcrumbs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { breadcrumbsStore } from './store'
import { StorefrontModule } from '@vue-storefront/core/lib/modules'

export const BreadcrumbsModule: StorefrontModule = function ({store}) {
export const BreadcrumbsModule: StorefrontModule = function ({ store }) {
store.registerModule('breadcrumbs', breadcrumbsStore)
}
4 changes: 2 additions & 2 deletions core/modules/breadcrumbs/test/unit/parseCategoryPath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('parseCategoryPath method', () => {

beforeEach(() => {
jest.clearAllMocks();
(currentStoreView as jest.Mock).mockImplementation(() => ({storeCode: ''}));
(currentStoreView as jest.Mock).mockImplementation(() => ({ storeCode: '' }));
categories = [
{
path: '1/2',
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('parseCategoryPath method', () => {

beforeEach(() => {
jest.clearAllMocks();
(currentStoreView as jest.Mock).mockImplementation(() => ({storeCode: ''}));
(currentStoreView as jest.Mock).mockImplementation(() => ({ storeCode: '' }));
categories = [
{
path: '1/2',
Expand Down
4 changes: 2 additions & 2 deletions core/modules/cart/helpers/syncCartWhenLocalStorageChange.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import rootStore from '@vue-storefront/core/store';

function getItemsFromStorage ({key}) {
function getItemsFromStorage ({ key }) {
if (key === 'shop/cart/current-cart') {
const storedItems = JSON.parse(localStorage[key])
rootStore.dispatch('cart/syncCartWhenLocalStorageChange', {items: storedItems})
rootStore.dispatch('cart/syncCartWhenLocalStorageChange', { items: storedItems })
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/modules/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isServer } from '@vue-storefront/core/helpers'
import Vue from 'vue'
import { StorageManager } from '@vue-storefront/core/lib/storage-manager'

export const CartModule: StorefrontModule = function ({store}) {
export const CartModule: StorefrontModule = function ({ store }) {
StorageManager.init('cart')

store.registerModule('cart', cartStore)
Expand Down
Loading