From 525a884c0e204f710e06f45a6b107f9b709b0459 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Thu, 2 Jan 2020 13:19:47 +0100 Subject: [PATCH 1/4] revert adding filters with app init --- core/app.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/app.ts b/core/app.ts index 052a0d9290..56ae807955 100755 --- a/core/app.ts +++ b/core/app.ts @@ -92,10 +92,10 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu Object.keys(coreMixins).forEach(key => { Vue.mixin(coreMixins[key]) }) + }) - Object.keys(coreFilters).forEach(key => { - Vue.filter(key, coreFilters[key]) - }) + Object.keys(coreFilters).forEach(key => { + Vue.filter(key, coreFilters[key]) }) // @todo remove this part when we'll get rid of global multistore mixin From 1b97d87c6412a329bf89b61bb0bd334f50855c98 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Fri, 24 Jan 2020 13:57:23 +0100 Subject: [PATCH 2/4] remove storeView as dependency from filters --- core/app.ts | 6 +++--- core/filters/date.js | 7 ++++--- core/filters/price.js | 12 ++++++------ core/lib/multistore.ts | 35 ++++++++++++++++++++++++++--------- core/mixins/multistore.js | 16 ++-------------- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/core/app.ts b/core/app.ts index 56ae807955..052a0d9290 100755 --- a/core/app.ts +++ b/core/app.ts @@ -92,10 +92,10 @@ const createApp = async (ssrContext, config, storeCode = null): Promise<{app: Vu Object.keys(coreMixins).forEach(key => { Vue.mixin(coreMixins[key]) }) - }) - Object.keys(coreFilters).forEach(key => { - Vue.filter(key, coreFilters[key]) + Object.keys(coreFilters).forEach(key => { + Vue.filter(key, coreFilters[key]) + }) }) // @todo remove this part when we'll get rid of global multistore mixin diff --git a/core/filters/date.js b/core/filters/date.js index 17ef6af253..16adde8b8c 100644 --- a/core/filters/date.js +++ b/core/filters/date.js @@ -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 diff --git a/core/filters/price.js b/core/filters/price.js index a9e44c7cba..377a220f2a 100644 --- a/core/filters/price.js +++ b/core/filters/price.js @@ -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) diff --git a/core/lib/multistore.ts b/core/lib/multistore.ts index dbf90e9550..6d53ac54f6 100644 --- a/core/lib/multistore.ts +++ b/core/lib/multistore.ts @@ -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 { - 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] @@ -38,6 +50,11 @@ export async function prepareStoreView (storeCode: string): Promise { } 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) { diff --git a/core/mixins/multistore.js b/core/mixins/multistore.js index 4f8135e186..8964566055 100644 --- a/core/mixins/multistore.js +++ b/core/mixins/multistore.js @@ -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) }, @@ -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) } From f234875472a44e213a909dd152e5bf72584527aa Mon Sep 17 00:00:00 2001 From: tkostuch Date: Fri, 24 Jan 2020 14:07:38 +0100 Subject: [PATCH 3/4] update filters in components --- docs/guide/cookbook/theme.md | 16 +++++++-------- .../components/core/ProductTile.vue | 12 ++++++++--- src/themes/default-amp/pages/Product.vue | 12 ++++++++--- .../default/components/core/ProductLinks.vue | 12 ++++++++--- .../default/components/core/ProductTile.vue | 10 +++++++--- .../core/blocks/Checkout/CartSummary.vue | 12 ++++++++--- .../blocks/Checkout/OrderConfirmation.vue | 10 ++++++++-- .../core/blocks/Checkout/Product.vue | 16 +++++++++------ .../core/blocks/Checkout/Shipping.vue | 8 ++++++-- .../core/blocks/Microcart/Microcart.vue | 10 ++++++++-- .../core/blocks/Microcart/Product.vue | 18 ++++++++++------- .../core/blocks/MyAccount/MyOrder.vue | 20 ++++++++++++------- .../core/blocks/MyAccount/MyOrders.vue | 10 ++++++++-- .../core/blocks/Wishlist/Product.vue | 10 +++++++--- src/themes/default/pages/Product.vue | 10 +++++++--- 15 files changed, 129 insertions(+), 57 deletions(-) diff --git a/docs/guide/cookbook/theme.md b/docs/guide/cookbook/theme.md index 4283dee3fc..f5d65eab82 100644 --- a/docs/guide/cookbook/theme.md +++ b/docs/guide/cookbook/theme.md @@ -762,7 +762,7 @@ Start with replacing _template_ at `2` as follows : diff --git a/src/themes/default/components/core/ProductTile.vue b/src/themes/default/components/core/ProductTile.vue index 8d2aba3aa5..0a941c6e90 100644 --- a/src/themes/default/components/core/ProductTile.vue +++ b/src/themes/default/components/core/ProductTile.vue @@ -28,21 +28,21 @@ class="price-original mr5 lh30 cl-secondary" v-if="product.special_price && parseFloat(product.originalPriceInclTax) > 0 && !onlyImage" > - {{ product.originalPriceInclTax | price }} + {{ product.originalPriceInclTax | price(storeView) }} - {{ product.priceInclTax | price }} + {{ product.priceInclTax | price(storeView) }} - {{ product.priceInclTax | price }} + {{ product.priceInclTax | price(storeView) }} @@ -53,6 +53,7 @@ import rootStore from '@vue-storefront/core/store' import { ProductTile } from '@vue-storefront/core/modules/catalog/components/ProductTile.ts' import config from 'config' import ProductImage from './ProductImage' +import { currentStoreView } from '@vue-storefront/core/lib/multistore' export default { mixins: [ProductTile], @@ -75,6 +76,9 @@ export default { src: this.thumbnail, loading: this.thumbnail } + }, + storeView () { + return currentStoreView() } }, methods: { diff --git a/src/themes/default/components/core/blocks/Checkout/CartSummary.vue b/src/themes/default/components/core/blocks/Checkout/CartSummary.vue index 2cac035558..1fc4158154 100644 --- a/src/themes/default/components/core/blocks/Checkout/CartSummary.vue +++ b/src/themes/default/components/core/blocks/Checkout/CartSummary.vue @@ -11,7 +11,7 @@ {{ segment.title }}
- {{ segment.value | price }} + {{ segment.value | price(storeView) }}
@@ -20,7 +20,7 @@ {{ segment.title }}
- {{ segment.value | price }} + {{ segment.value | price(storeView) }}
@@ -53,13 +53,19 @@ diff --git a/src/themes/default/components/core/blocks/Checkout/OrderConfirmation.vue b/src/themes/default/components/core/blocks/Checkout/OrderConfirmation.vue index a85b94395d..5d493aef3d 100644 --- a/src/themes/default/components/core/blocks/Checkout/OrderConfirmation.vue +++ b/src/themes/default/components/core/blocks/Checkout/OrderConfirmation.vue @@ -34,13 +34,13 @@ - {{ product.priceInclTax | price }} + {{ product.priceInclTax | price(storeView) }} {{ product.qty }} - {{ product.priceInclTax * product.qty | price }} + {{ product.priceInclTax * product.qty | price(storeView) }} @@ -65,6 +65,7 @@ import { ConfirmOrders } from '@vue-storefront/core/modules/offline-order/compon import { CancelOrders } from '@vue-storefront/core/modules/offline-order/components/CancelOrders' import Modal from 'theme/components/core/Modal' import ButtonFull from 'theme/components/theme/ButtonFull.vue' +import { currentStoreView } from '@vue-storefront/core/lib/multistore' export default { props: { @@ -79,6 +80,11 @@ export default { this.$bus.$emit('modal-show', 'modal-order-confirmation') }) }, + computed: { + storeView () { + return currentStoreView() + } + }, methods: { confirmOrders () { ConfirmOrders.methods.confirmOrders.call(this) diff --git a/src/themes/default/components/core/blocks/Checkout/Product.vue b/src/themes/default/components/core/blocks/Checkout/Product.vue index 4bdbdd2035..25da2dd030 100644 --- a/src/themes/default/components/core/blocks/Checkout/Product.vue +++ b/src/themes/default/components/core/blocks/Checkout/Product.vue @@ -40,14 +40,14 @@
- {{ product.totals.row_total - product.totals.discount_amount + product.totals.tax_amount | price }} - {{ product.totals.row_total_incl_tax | price }} - {{ product.totals.row_total_incl_tax | price }} + {{ product.totals.row_total - product.totals.discount_amount + product.totals.tax_amount | price(storeView) }} + {{ product.totals.row_total_incl_tax | price(storeView) }} + {{ product.totals.row_total_incl_tax | price(storeView) }}
- {{ product.priceInclTax * product.qty | price }} - {{ product.originalPriceInclTax * product.qty | price }} - {{ product.priceInclTax * product.qty | price }} + {{ product.priceInclTax * product.qty | price(storeView) }} + {{ product.originalPriceInclTax * product.qty | price(storeView) }} + {{ product.priceInclTax * product.qty | price(storeView) }}
@@ -59,6 +59,7 @@ import { Product } from '@vue-storefront/core/modules/checkout/components/Product' import { onlineHelper } from '@vue-storefront/core/helpers' import ProductImage from 'theme/components/core/ProductImage' +import { currentStoreView } from '@vue-storefront/core/lib/multistore' export default { computed: { @@ -70,6 +71,9 @@ export default { loading: this.thumbnail, src: this.thumbnail } + }, + storeView () { + return currentStoreView() } }, mixins: [Product], diff --git a/src/themes/default/components/core/blocks/Checkout/Shipping.vue b/src/themes/default/components/core/blocks/Checkout/Shipping.vue index 8d923e9f84..23259b3d0d 100644 --- a/src/themes/default/components/core/blocks/Checkout/Shipping.vue +++ b/src/themes/default/components/core/blocks/Checkout/Shipping.vue @@ -178,7 +178,7 @@ {{ $t('Shipping method') }}
-
-
- {{ segment.value | price }} + {{ segment.value | price(storeView) }}
@@ -91,7 +91,7 @@ {{ segment.title }}
- {{ segment.value | price }} + {{ segment.value | price(storeView) }}
@@ -123,6 +123,7 @@ diff --git a/src/themes/default/components/core/blocks/MyAccount/MyOrders.vue b/src/themes/default/components/core/blocks/MyAccount/MyOrders.vue index e21b789289..a858d64a34 100644 --- a/src/themes/default/components/core/blocks/MyAccount/MyOrders.vue +++ b/src/themes/default/components/core/blocks/MyAccount/MyOrders.vue @@ -49,7 +49,7 @@ {{ order.customer_firstname }} {{ order.customer_lastname }} - {{ order.grand_total | price }} + {{ order.grand_total | price(storeView) }} {{ $t('Purchase') }} @@ -81,9 +81,15 @@ diff --git a/src/themes/default/components/core/blocks/Wishlist/Product.vue b/src/themes/default/components/core/blocks/Wishlist/Product.vue index 11fe9f325e..2d1e7c6c58 100644 --- a/src/themes/default/components/core/blocks/Wishlist/Product.vue +++ b/src/themes/default/components/core/blocks/Wishlist/Product.vue @@ -27,11 +27,11 @@
- {{ product.priceInclTax | price }}  - {{ product.originalPriceInclTax | price }} + {{ product.priceInclTax | price(storeView) }}  + {{ product.originalPriceInclTax | price(storeView) }} - {{ product.priceInclTax | price }} + {{ product.priceInclTax | price(storeView) }}
@@ -47,6 +47,7 @@ import Product from '@vue-storefront/core/compatibility/components/blocks/Wishlist/Product' import RemoveButton from './RemoveButton' import ProductImage from 'theme/components/core/ProductImage' +import { currentStoreView } from '@vue-storefront/core/lib/multistore' export default { components: { @@ -60,6 +61,9 @@ export default { loading: this.thumbnail, src: this.thumbnail } + }, + storeView () { + return currentStoreView() } } } diff --git a/src/themes/default/pages/Product.vue b/src/themes/default/pages/Product.vue index d526e86487..c984b90566 100644 --- a/src/themes/default/pages/Product.vue +++ b/src/themes/default/pages/Product.vue @@ -38,17 +38,17 @@ v-if="product.special_price && product.priceInclTax && product.originalPriceInclTax" > - {{ product.priceInclTax * product.qty | price }} + {{ product.priceInclTax * product.qty | price(storeView) }}   - {{ product.originalPriceInclTax * product.qty | price }} + {{ product.originalPriceInclTax * product.qty | price(storeView) }}
- {{ product.qty > 0 ? product.priceInclTax * product.qty : product.priceInclTax | price }} + {{ product.qty > 0 ? product.priceInclTax * product.qty : product.priceInclTax | price(storeView) }}
Date: Fri, 24 Jan 2020 14:10:26 +0100 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a189992cc2..e04b77fd8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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) ## [1.10.5] - 28.11.2019