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

Commit

Permalink
Merge pull request #4110 from DivanteLtd/hotfix/v1.10.6
Browse files Browse the repository at this point in the history
Hotfix/v1.10.6
  • Loading branch information
andrzejewsky authored Feb 21, 2020
2 parents 09c39c8 + d49c877 commit 14e3477
Show file tree
Hide file tree
Showing 46 changed files with 376 additions and 191 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.10.6] - 21.02.2020

## Added
- Add lazy create cart token - @gibkigonzo (#3994)
- Add server context to async data loader - @gibkigonzo (pr#4113)

### Fixed
- Fix low-quality images styles - @przspa (#3906)
- Fix page-not-found redirect in dispatcher - @gibkigonzo (#3956)
- Fix hiding overlay for newsletter modal - @gibkigonzo (#3970)
- Fix problem with storeView as dependency in filters - @gibkigonzo (#3968)
- Fix v-model not working in BaseRadioButton - @lukeromanowicz (#4035)
- add disconnect and sync options for clear/cart - @gibkigonzo (#4062)
- Fix current token invalidation with refresh token - @gibkigonzo (#3928, #3620, #3626)
- Disable overriding `route`, `config`, `storeView`, `version` state in __INITIAL_STATE__ - @gibkigonzo (pr#4095)
- Disable zoom image on hover in mobile - @gibkigonzo (pr#4115)

## [1.10.5] - 28.11.2019

### Fixed
Expand Down
1 change: 0 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
"width": 150,
"height": 150
},
"bypassCartLoaderForAuthorizedUsers": true,
"serverMergeByDefault": true,
"serverSyncCanRemoveLocalItems": false,
"serverSyncCanModifyLocalItems": false,
Expand Down
4 changes: 3 additions & 1 deletion core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AsyncDataLoader } from './lib/async-data-loader'
import { Logger } from '@vue-storefront/core/lib/logger'
import globalConfig from 'config'
import { RouterManager } from './lib/router-manager';
import omit from 'lodash-es/omit'
declare var window: any

const invokeClientEntry = async () => {
Expand All @@ -22,7 +23,8 @@ const invokeClientEntry = async () => {
const { app, router, store } = await createApp(null, dynamicRuntimeConfig, storeCode)

if (window.__INITIAL_STATE__) {
store.replaceState(Object.assign({}, store.state, window.__INITIAL_STATE__, { config: globalConfig }))
const initialState = omit(window.__INITIAL_STATE__, ['storeView', 'config', 'version', 'route'])
store.replaceState(Object.assign({}, store.state, initialState, { config: globalConfig }))
}

await store.dispatch('url/registerDynamicRoutes')
Expand Down
7 changes: 4 additions & 3 deletions core/filters/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ once('__VUE_EXTEND_DAYJS_LOCALIZED_FORMAT__', () => {
* @param {String} date
* @param {String} format
*/
export function date (date, format) {
const displayFormat = format || currentStoreView().i18n.dateFormat
let storeLocale = currentStoreView().i18n.defaultLocale.toLocaleLowerCase()
export function date (date, format, storeView) {
const _storeView = storeView || currentStoreView()
const displayFormat = format || _storeView.i18n.dateFormat
let storeLocale = _storeView.i18n.defaultLocale.toLocaleLowerCase()
const separatorIndex = storeLocale.indexOf('-')
const languageCode = separatorIndex ? storeLocale.substr(0, separatorIndex) : storeLocale

Expand Down
12 changes: 6 additions & 6 deletions core/filters/price.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { currentStoreView } from '@vue-storefront/core/lib/multistore'
* Converts number to price string
* @param {Number} value
*/
export function price (value) {
export function price (value, storeView) {
if (isNaN(value)) {
return value
}
let formattedVal = Math.abs(parseFloat(value)).toFixed(2)
const storeView = currentStoreView()
if (!storeView.i18n) {
const _storeView = storeView || currentStoreView();
if (!_storeView.i18n) {
return value;
}
const prependCurrency = (price) => {
return storeView.i18n.currencySign + price
return _storeView.i18n.currencySign + price
}

const appendCurrency = (price) => {
return price + storeView.i18n.currencySign
return price + _storeView.i18n.currencySign
}

if (storeView.i18n.currencySignPlacement === 'append') {
if (_storeView.i18n.currencySignPlacement === 'append') {
formattedVal = appendCurrency(formattedVal)
} else {
formattedVal = prependCurrency(formattedVal)
Expand Down
2 changes: 1 addition & 1 deletion core/i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-storefront/i18n",
"version": "1.10.5",
"version": "1.10.6",
"description": "Vue Storefront i18n",
"license": "MIT",
"main": "index.ts",
Expand Down
35 changes: 26 additions & 9 deletions core/lib/multistore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ import VueRouter, { RouteConfig, RawLocation } from 'vue-router'
import config from 'config'
import { LocalizedRoute, StoreView } from './types'
import storeCodeFromRoute from './storeCodeFromRoute'
import cloneDeep from 'lodash-es/cloneDeep'
import get from 'lodash-es/get'
import { isServer } from '@vue-storefront/core/helpers'

/**
* Returns base storeView object that can be created without storeCode
*/
function buildBaseStoreView (): StoreView {
return cloneDeep({
tax: config.tax,
i18n: config.i18n,
elasticsearch: config.elasticsearch,
storeCode: null,
storeId: config.defaultStoreCode && config.defaultStoreCode !== '' ? config.storeViews[config.defaultStoreCode].storeId : 1,
seo: config.seo
})
}

export function currentStoreView (): StoreView {
// TODO: Change to getter all along our code
return rootStore.state.storeView
const serverStoreView = get(global, 'process.storeView', undefined)
const clientStoreView = get(rootStore, 'state.storeView', undefined)
return (isServer ? serverStoreView : clientStoreView) || buildBaseStoreView()
}

export async function prepareStoreView (storeCode: string): Promise<StoreView> {
let storeView = { // current, default store
tax: Object.assign({}, config.tax),
i18n: Object.assign({}, config.i18n),
elasticsearch: Object.assign({}, config.elasticsearch),
storeCode: '',
storeId: config.defaultStoreCode && config.defaultStoreCode !== '' ? config.storeViews[config.defaultStoreCode].storeId : 1
}
let storeView: StoreView = buildBaseStoreView() // current, default store
const storeViewHasChanged = !rootStore.state.storeView || rootStore.state.storeView.storeCode !== storeCode
if (storeCode) { // current store code
const currentStoreView = config.storeViews[storeCode]
Expand All @@ -38,6 +50,11 @@ export async function prepareStoreView (storeCode: string): Promise<StoreView> {
}
if (storeViewHasChanged) {
rootStore.state.storeView = storeView

if (global && isServer) {
(global.process as any).storeView = storeView
}

await loadLanguageAsync(storeView.i18n.defaultLocale)
}
if (storeViewHasChanged || Vue.prototype.$db.currentStoreCode !== storeCode) {
Expand Down
31 changes: 31 additions & 0 deletions core/lib/sync/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const hasResponseError = (jsonResponse): boolean => {
if (typeof jsonResponse.result === 'string') {
return true
}

const hasMessage = jsonResponse.result.result || jsonResponse.result.message

return Boolean(hasMessage) && jsonResponse.result.code !== 'ENOTFOUND'
}

export const getResponseMessage = (jsonResponse): string => {
if (typeof jsonResponse.result === 'string') {
return jsonResponse.result
}

if (typeof jsonResponse.result.result === 'string') {
return jsonResponse.result.result
}

return jsonResponse.result.message
}

export const getResponseCode = (jsonResponse): number => {
let responseCode = null
if (jsonResponse.result && jsonResponse.result.code) {
responseCode = parseInt(jsonResponse.result.code)
} else {
responseCode = parseInt(jsonResponse.code)
}
return responseCode
}
16 changes: 7 additions & 9 deletions core/lib/sync/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Vue from 'vue'
import i18n from '@vue-storefront/i18n'
import isNaN from 'lodash-es/isNaN'
import isUndefined from 'lodash-es/isUndefined'
import toString from 'lodash-es/toString'
import fetch from 'isomorphic-fetch'
import * as localForage from 'localforage'
import rootStore from '@vue-storefront/core/store'
Expand All @@ -16,6 +15,7 @@ import { processURLAddress } from '@vue-storefront/core/helpers'
import { serial } from '@vue-storefront/core/helpers'
import config from 'config'
import { onlineHelper } from '@vue-storefront/core/helpers'
import { hasResponseError, getResponseMessage, getResponseCode } from '@vue-storefront/core/lib/sync/helpers'

const AUTO_REFRESH_MAX_ATTEMPTS = 20

Expand All @@ -33,7 +33,7 @@ function _sleep (time) {
}

function _internalExecute (resolve, reject, task: Task, currentToken, currentCartId) {
if (currentToken !== null && rootStore.state.userTokenInvalidateLock > 0) { // invalidate lock set
if (currentToken && rootStore.state.userTokenInvalidateLock > 0) { // invalidate lock set
Logger.log('Waiting for rootStore.state.userTokenInvalidateLock to release for ' + task.url, 'sync')()
_sleep(1000).then(() => {
Logger.log('Another try for rootStore.state.userTokenInvalidateLock for ' + task.url, 'sync')()
Expand All @@ -42,7 +42,7 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
return // return but not resolve
} else if (rootStore.state.userTokenInvalidateLock < 0) {
Logger.error('Aborting the network task' + task.url + rootStore.state.userTokenInvalidateLock, 'sync')()
resolve({ code: 401, message: i18n.t('Error refreshing user token. User is not authorized to access the resource') })()
resolve({ code: 401, result: i18n.t('Error refreshing user token. User is not authorized to access the resource') })()
return
} else {
if (rootStore.state.userTokenInvalidated) {
Expand Down Expand Up @@ -73,9 +73,9 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
}
}).then((jsonResponse) => {
if (jsonResponse) {
const responseCode = parseInt(jsonResponse.code)
const responseCode = getResponseCode(jsonResponse)
if (responseCode !== 200) {
if (responseCode === 401 /** unauthorized */ && currentToken !== null) { // the token is no longer valid, try to invalidate it
if (responseCode === 401 /** unauthorized */ && currentToken) { // the token is no longer valid, try to invalidate it
Logger.error('Invalid token - need to be revalidated' + currentToken + task.url + rootStore.state.userTokenInvalidateLock, 'sync')()
if (isNaN(rootStore.state.userTokenInvalidateAttemptsCount) || isUndefined(rootStore.state.userTokenInvalidateAttemptsCount)) rootStore.state.userTokenInvalidateAttemptsCount = 0
if (isNaN(rootStore.state.userTokenInvalidateLock) || isUndefined(rootStore.state.userTokenInvalidateLock)) rootStore.state.userTokenInvalidateLock = 0
Expand Down Expand Up @@ -128,12 +128,10 @@ function _internalExecute (resolve, reject, task: Task, currentToken, currentCar
}
}

if (!task.silent && jsonResponse.result && (typeof jsonResponse.result === 'string' || (((jsonResponse.result.result || jsonResponse.result.message) && jsonResponse.result.code !== 'ENOTFOUND') && !silentMode))) {
const message = typeof jsonResponse.result === 'string' ? jsonResponse.result : typeof jsonResponse.result.result === 'string' ? jsonResponse.result.result : jsonResponse.result.message

if (!task.silent && jsonResponse.result && hasResponseError(jsonResponse) && !silentMode) {
rootStore.dispatch('notification/spawnNotification', {
type: 'error',
message: i18n.t(message),
message: i18n.t(getResponseMessage(jsonResponse)),
action1: { label: i18n.t('OK') }
})
}
Expand Down
16 changes: 2 additions & 14 deletions core/mixins/multistore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ export const multistore = {
* @param {Int} height
*/
localizedRoute (routeObj) {
let storeView

if (isServer) {
storeView = this.$ssrContext.helpers.currentStoreView()
} else {
storeView = currentStoreView()
}
const storeView = currentStoreView()

return localizedRouteHelper(routeObj, storeView.storeCode)
},
Expand All @@ -27,13 +21,7 @@ export const multistore = {
* @param {Int} height
*/
localizedDispatcherRoute (routeObj) {
let storeView

if (isServer) {
storeView = this.$ssrContext.helpers.currentStoreView()
} else {
storeView = currentStoreView()
}
const storeView = currentStoreView()

return localizedDispatcherRouteHelper(routeObj, storeView.storeCode)
}
Expand Down
Loading

0 comments on commit 14e3477

Please sign in to comment.