From 10cac7fb4b56f52f29156844050a2f60e370342c Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Fri, 6 Mar 2020 11:15:51 +0100 Subject: [PATCH 1/2] Option to always sync prices clientside and include the loggedin user's token --- config/default.json | 1 + core/modules/catalog/store/product/actions.ts | 4 ++++ docs/guide/basics/configuration.md | 6 ++++++ src/themes/default/pages/Product.vue | 6 +++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config/default.json b/config/default.json index d5ef6a0611..c313d8d053 100644 --- a/config/default.json +++ b/config/default.json @@ -337,6 +337,7 @@ "listOutOfStockProducts": true, "preventConfigurableChildrenDirectAccess": true, "alwaysSyncPlatformPricesOver": false, + "alwaysSyncPricesClientSide": false, "clearPricesBeforePlatformSync": false, "waitForPlatformSync": false, "setupVariantByAttributeCode": true, diff --git a/core/modules/catalog/store/product/actions.ts b/core/modules/catalog/store/product/actions.ts index 7476da61af..c69c8580c5 100644 --- a/core/modules/catalog/store/product/actions.ts +++ b/core/modules/catalog/store/product/actions.ts @@ -117,6 +117,10 @@ const actions: ActionTree = { url = `${url}&userGroupId=${rootGetters['tax/getUserTaxGroupId']}` } + if (rootGetters['user/getToken']) { + url = `${url}&token=${rootGetters['user/getToken']}` + } + return TaskQueue.execute({ url, // sync the cart payload: { method: 'GET', diff --git a/docs/guide/basics/configuration.md b/docs/guide/basics/configuration.md index 64c5fa9a0d..a7d0bc45ba 100644 --- a/docs/guide/basics/configuration.md +++ b/docs/guide/basics/configuration.md @@ -467,6 +467,12 @@ This is related to `alwaysSyncPlatformPricesOver` and when it's set to true, the This is related to `alwaysSyncPlatformPricesOver`. When true, Vue Storefront will wait for dynamic prices before rendering the page. Otherwise, the product and category pages will be rendered using the default (Elasticsearch-based) prices and then asynchronously override them with current ones. +```json + "alwaysSyncPricesClientSide": false, +``` + +This is related to `alwaysSyncPlatformPricesOver`. When true, Vue Storefront will force a refresh of the prices on the client side, including the token from the current logged in user, so customer specific pricing can be applied. + ```json "endpoint": "http://localhost:8080/api/product", diff --git a/src/themes/default/pages/Product.vue b/src/themes/default/pages/Product.vue index bf806474f5..872cfe9231 100644 --- a/src/themes/default/pages/Product.vue +++ b/src/themes/default/pages/Product.vue @@ -221,6 +221,7 @@ import { registerModule, isModuleRegistered } from '@vue-storefront/core/lib/mod import { onlineHelper, isServer, productJsonLd } from '@vue-storefront/core/helpers' import { catalogHooksExecutors } from '@vue-storefront/core/modules/catalog-next/hooks' import ProductPrice from 'theme/components/core/ProductPrice.vue' +import { doPlatformPricesSync } from '@vue-storefront/core/modules/catalog/helpers' export default { components: { @@ -324,7 +325,7 @@ export default { return currentStoreView() }, getJsonLd () { - return productJsonLd(this.getCurrentProduct, this.getCurrentProductConfiguration.color.label, this.$store.state.storeView.i18n.currencyCode, this.getCustomAttributes) + return productJsonLd(this.getCurrentProduct, this.getCurrentProductConfiguration.color && this.getCurrentProductConfiguration.color.label, this.$store.state.storeView.i18n.currencyCode, this.getCustomAttributes) } }, async mounted () { @@ -396,6 +397,9 @@ export default { if (this.isStockInfoLoading) return // stock info is already loading this.isStockInfoLoading = true try { + if (config.products.alwaysSyncPricesClientSide) { + doPlatformPricesSync([this.getCurrentProduct]); + } const res = await this.$store.dispatch('stock/check', { product: this.getCurrentProduct, qty: this.getCurrentProduct.qty From 1dfc2bd5281fa9f5bb307d4fdf8d11c9fca3299a Mon Sep 17 00:00:00 2001 From: Carlo Kok Date: Fri, 6 Mar 2020 11:24:36 +0100 Subject: [PATCH 2/2] 0: Update changelog with id. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 486dd383e9..c59b0677da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.12.0-rc1] - UNRELEASED ### Added +- Include token in pricing sync - @carlokok (#4156) - Separating endpoints for CSR/SSR - @Fifciu (#2861) - Added short hands for version and help flags - @jamesgeorge007 (#3946) - Add `or` operator for Elasticsearch filters in `quickSearchByQuery` and use exists if value is `null` - @cewald (#3960)