From 98d7cf540819ee05193ad49d6bd3b8ca41aca2f0 Mon Sep 17 00:00:00 2001 From: Rain2o Date: Fri, 27 Sep 2019 18:29:44 +0200 Subject: [PATCH 01/99] save the payment methods returned on updateTotals to state. --- core/modules/cart/helpers/createOrderData.ts | 9 +++++++++ core/modules/cart/helpers/createShippingInfoData.ts | 3 +++ core/modules/cart/store/actions/totalsActions.ts | 10 ++++++++-- core/modules/cart/types/BillingAddress.ts | 8 ++++++++ core/modules/cart/types/CheckoutData.ts | 2 ++ core/modules/cart/types/OrderShippingDetails.ts | 4 +++- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 core/modules/cart/types/BillingAddress.ts diff --git a/core/modules/cart/helpers/createOrderData.ts b/core/modules/cart/helpers/createOrderData.ts index d79e382425..37c12e34ac 100644 --- a/core/modules/cart/helpers/createOrderData.ts +++ b/core/modules/cart/helpers/createOrderData.ts @@ -21,6 +21,7 @@ const createOrderData = ({ shippingDetails, shippingMethods, paymentMethods, + paymentDetails, taxCountry = currentStoreView().tax.defaultCountry }: CheckoutData): OrderShippingDetails => { const country = shippingDetails.country ? shippingDetails.country : taxCountry @@ -36,6 +37,14 @@ const createOrderData = ({ postcode: shippingDetails.zipCode, street: [shippingDetails.streetAddress] }, + billingAddress: { + firstname: paymentDetails.firstName, + lastname: paymentDetails.lastName, + city: paymentDetails.city, + postcode: paymentDetails.zipCode, + street: [paymentDetails.streetAddress], + countryId: paymentDetails.country + }, method_code: shipping && shipping.method_code ? shipping.method_code : null, carrier_code: shipping && shipping.carrier_code ? shipping.carrier_code : null, payment_method: payment && payment.code ? payment.code : null diff --git a/core/modules/cart/helpers/createShippingInfoData.ts b/core/modules/cart/helpers/createShippingInfoData.ts index 394cfc86ed..e42b0f19ff 100644 --- a/core/modules/cart/helpers/createShippingInfoData.ts +++ b/core/modules/cart/helpers/createShippingInfoData.ts @@ -3,6 +3,9 @@ const createShippingInfoData = (methodsData) => ({ countryId: methodsData.country, ...(methodsData.shippingAddress ? methodsData.shippingAddress : {}) }, + billingAddress: { + ...(methodsData.billingAddress ? methodsData.billingAddress : {}) + }, shippingCarrierCode: methodsData.carrier_code, shippingMethodCode: methodsData.method_code }); diff --git a/core/modules/cart/store/actions/totalsActions.ts b/core/modules/cart/store/actions/totalsActions.ts index a31379d674..ade4bd8344 100644 --- a/core/modules/cart/store/actions/totalsActions.ts +++ b/core/modules/cart/store/actions/totalsActions.ts @@ -15,7 +15,7 @@ const totalsActions = { return CartService.getTotals() }, - async overrideServerTotals ({ commit, dispatch }, { addressInformation, hasShippingInformation }) { + async overrideServerTotals ({ commit, getters, dispatch }, { addressInformation, hasShippingInformation }) { const { resultCode, result } = await dispatch('getTotals', { addressInformation, hasShippingInformation }) if (resultCode === 200) { @@ -32,6 +32,11 @@ const totalsActions = { commit(types.CART_UPD_TOTALS, { itemsAfterTotal, totals, platformTotalSegments: totals.total_segments }) commit(types.CART_SET_TOTALS_SYNC) + // we received payment methods as a result of this call, updating state + if (getters.canUpdateMethods) { + dispatch('checkout/replacePaymentMethods', result.payment_methods, { root: true }) + } + return } @@ -45,7 +50,8 @@ const totalsActions = { const shippingMethodsData = methodsData || createOrderData({ shippingDetails: rootGetters['checkout/getShippingDetails'], shippingMethods: rootGetters['checkout/getShippingMethods'], - paymentMethods: rootGetters['checkout/getPaymentMethods'] + paymentMethods: rootGetters['checkout/getPaymentMethods'], + paymentDetails: rootGetters['checkout/getPaymentDetails'] }) if (shippingMethodsData.country) { diff --git a/core/modules/cart/types/BillingAddress.ts b/core/modules/cart/types/BillingAddress.ts new file mode 100644 index 0000000000..18d17cc487 --- /dev/null +++ b/core/modules/cart/types/BillingAddress.ts @@ -0,0 +1,8 @@ +export default interface ShippingAddress { + firstname: string, + lastname: string, + city: string, + postcode: string, + street: string[], + countryId: string +} diff --git a/core/modules/cart/types/CheckoutData.ts b/core/modules/cart/types/CheckoutData.ts index feac99cb00..4e2c5c676e 100644 --- a/core/modules/cart/types/CheckoutData.ts +++ b/core/modules/cart/types/CheckoutData.ts @@ -1,10 +1,12 @@ import ShippingDetails from '@vue-storefront/core/modules/checkout/types/ShippingDetails' import ShippingMethod from './ShippingMethod' import PaymentMethod from './PaymentMethod' +import PaymentDetails from '@vue-storefront/core/modules/checkout/types/PaymentDetails' export default interface CheckoutData { shippingDetails: ShippingDetails, shippingMethods: ShippingMethod[], paymentMethods: PaymentMethod[], + paymentDetails: PaymentDetails, taxCountry?: string } diff --git a/core/modules/cart/types/OrderShippingDetails.ts b/core/modules/cart/types/OrderShippingDetails.ts index a455dda4d2..ebfc2005c5 100644 --- a/core/modules/cart/types/OrderShippingDetails.ts +++ b/core/modules/cart/types/OrderShippingDetails.ts @@ -1,9 +1,11 @@ import ShippingAddress from './ShippingAddress' +import BillingAddress from './BillingAddress' export default interface OrderShippingDetails { country?: string, method_code?: string, carrier_code?: string, payment_method?: string, - shippingAddress?: ShippingAddress + shippingAddress?: ShippingAddress, + billingAddress?: BillingAddress } From 103d231b7f1b2c7af58a2f9138bede0bea5c261a Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Sat, 28 Sep 2019 12:05:35 +0200 Subject: [PATCH 02/99] feat: moved trace logic to a server.onLoad hook --- core/scripts/server.ts | 9 +++++---- .../googleCloud => modules/google-cloud-trace}/index.js | 0 .../google-cloud-trace}/package.json | 0 src/modules/server.ts | 8 ++++++++ src/trace/index.js | 6 ------ 5 files changed, 13 insertions(+), 10 deletions(-) rename src/{trace/googleCloud => modules/google-cloud-trace}/index.js (100%) rename src/{trace/googleCloud => modules/google-cloud-trace}/package.json (100%) delete mode 100644 src/trace/index.js diff --git a/core/scripts/server.ts b/core/scripts/server.ts index fde457d835..7892c232f9 100755 --- a/core/scripts/server.ts +++ b/core/scripts/server.ts @@ -1,16 +1,17 @@ -require('../../src/trace').default() +import { serverHooksExecutors } from '@vue-storefront/core/server/hooks' const path = require('path') -const express = require('express') -const ms = require('ms') const rootPath = require('app-root-path').path const resolve = file => path.resolve(rootPath, file) +const serverExtensions = require(resolve('src/modules/server')) +serverHooksExecutors.onLoad() +const express = require('express') +const ms = require('ms') const request = require('request'); const cache = require('./utils/cache-instance') const apiStatus = require('./utils/api-status') const HTMLContent = require('../pages/Compilation') const ssr = require('./utils/ssr-renderer') -const serverExtensions = require(resolve('src/modules/server')) let config = require('config') const compileOptions = { diff --git a/src/trace/googleCloud/index.js b/src/modules/google-cloud-trace/index.js similarity index 100% rename from src/trace/googleCloud/index.js rename to src/modules/google-cloud-trace/index.js diff --git a/src/trace/googleCloud/package.json b/src/modules/google-cloud-trace/package.json similarity index 100% rename from src/trace/googleCloud/package.json rename to src/modules/google-cloud-trace/package.json diff --git a/src/modules/server.ts b/src/modules/server.ts index b2f626e4c3..da750abca1 100644 --- a/src/modules/server.ts +++ b/src/modules/server.ts @@ -1,5 +1,13 @@ +import { serverHooks } from '@vue-storefront/core/server/hooks' const isProd = process.env.NODE_ENV === 'production' +serverHooks.onLoad(() => { + /** + * example usage + * require('./google-cloud-trace') + */ +}) + export const serverModules = [ 'src/modules/robots' // ['src/modules/compress', { enabled: isProd }] diff --git a/src/trace/index.js b/src/trace/index.js deleted file mode 100644 index 9335b3646e..0000000000 --- a/src/trace/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports.default = () => { - /** - * example usage - * require('./googleCloud') - */ -} From cf1c8da11b5cb914d5eb9d977dee45cca94de446 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Sat, 28 Sep 2019 12:13:04 +0200 Subject: [PATCH 03/99] Added missing hooks file for the server --- core/server/hooks.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 core/server/hooks.ts diff --git a/core/server/hooks.ts b/core/server/hooks.ts new file mode 100644 index 0000000000..a31e24b026 --- /dev/null +++ b/core/server/hooks.ts @@ -0,0 +1,25 @@ +import { createListenerHook, createMutatorHook } from '@vue-storefront/core/lib/hooks' + +// beforeStartApp + +const { + hook: onLoadHook, + executor: onLoadExecutor +} = createListenerHook() + +/** Only for internal usage in this module */ +const serverHooksExecutors = { + onLoad: onLoadExecutor +} + +const serverHooks = { + /** Hook is fired right at the start of the app. + * @param void + */ + onLoad: onLoadHook +} + +export { + serverHooks, + serverHooksExecutors +} From f715faeb82b8d7c2bbfdbbdfb96510bb42effe0f Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Sun, 29 Sep 2019 13:08:33 +0200 Subject: [PATCH 04/99] Changed server extend logic to an server hook With this you only need to add an server.js or server.ts file to your module and in there you need to add it to the server trace/extend hook. --- core/scripts/server.ts | 20 +-- core/server/hooks.ts | 27 +++- package.json | 6 +- src/modules/compress/server.ts | 9 +- src/modules/google-cloud-trace/index.js | 5 - src/modules/google-cloud-trace/server.ts | 8 + src/modules/robots/server.ts | 5 +- src/modules/server.ts | 14 -- yarn.lock | 188 ++--------------------- 9 files changed, 63 insertions(+), 219 deletions(-) delete mode 100644 src/modules/google-cloud-trace/index.js create mode 100644 src/modules/google-cloud-trace/server.ts delete mode 100644 src/modules/server.ts diff --git a/core/scripts/server.ts b/core/scripts/server.ts index 7892c232f9..f846e7ccd0 100755 --- a/core/scripts/server.ts +++ b/core/scripts/server.ts @@ -1,9 +1,16 @@ import { serverHooksExecutors } from '@vue-storefront/core/server/hooks' +let config = require('config') const path = require('path') +const glob = require('glob') const rootPath = require('app-root-path').path const resolve = file => path.resolve(rootPath, file) -const serverExtensions = require(resolve('src/modules/server')) -serverHooksExecutors.onLoad() +const serverExtensions = glob.sync('src/modules/*/server.{ts,js}') + +serverExtensions.forEach(serverModule => { + require(resolve(serverModule)) +}) + +serverHooksExecutors.tracing(config.server) const express = require('express') const ms = require('ms') const request = require('request'); @@ -12,7 +19,6 @@ const cache = require('./utils/cache-instance') const apiStatus = require('./utils/api-status') const HTMLContent = require('../pages/Compilation') const ssr = require('./utils/ssr-renderer') -let config = require('config') const compileOptions = { escape: /{{([^{][\s\S]+?[^}])}}/g, @@ -25,13 +31,7 @@ process['noDeprecation'] = true const app = express() -serverExtensions.serverModules.forEach(serverModule => { - if (Array.isArray(serverModule)) { - require(resolve(serverModule[0] + '/server.ts'))(app, serverModule[1]) - } else { - require(resolve(serverModule + '/server.ts'))(app) - } -}) +serverHooksExecutors.extend({ app, config: config.server, isProd }) const templatesCache = ssr.initTemplatesCache(config, compileOptions) diff --git a/core/server/hooks.ts b/core/server/hooks.ts index a31e24b026..5026bcfb85 100644 --- a/core/server/hooks.ts +++ b/core/server/hooks.ts @@ -1,22 +1,39 @@ import { createListenerHook, createMutatorHook } from '@vue-storefront/core/lib/hooks' +import {Express} from 'express'; -// beforeStartApp +// To add tracing without adding it directly to the core const { - hook: onLoadHook, - executor: onLoadExecutor + hook: tracingHook, + executor: tracingExecutor } = createListenerHook() +// beforeStartApp +interface Extend { + app: Express, + config: any, + isProd: boolean +} +const { + hook: extendHook, + executor: extendExecutor +} = createListenerHook() + /** Only for internal usage in this module */ const serverHooksExecutors = { - onLoad: onLoadExecutor + tracing: tracingExecutor, + extend: extendExecutor } const serverHooks = { /** Hook is fired right at the start of the app. * @param void */ - onLoad: onLoadHook + tracing: tracingHook, + /** + * + */ + extend: extendHook } export { diff --git a/package.json b/package.json index a681cade98..82e6401517 100755 --- a/package.json +++ b/package.json @@ -50,7 +50,10 @@ }, "lint-staged": { "*.{js,vue,ts}": "eslint", - "**/i18n/*.csv": ["node ./core/scripts/utils/sort-translations.js", "git add"] + "**/i18n/*.csv": [ + "node ./core/scripts/utils/sort-translations.js", + "git add" + ] }, "husky": { "hooks": { @@ -72,6 +75,7 @@ "es6-promise": "^4.2.4", "express": "^4.14.0", "fs-extra": "^8.1.0", + "glob": "^7.1.4", "graphql": "^0.13.2", "graphql-tag": "^2.9.2", "isomorphic-fetch": "^2.2.1", diff --git a/src/modules/compress/server.ts b/src/modules/compress/server.ts index add229106f..df6b31e9cd 100644 --- a/src/modules/compress/server.ts +++ b/src/modules/compress/server.ts @@ -1,8 +1,9 @@ +import { serverHooks } from '@vue-storefront/core/server/hooks' const compression = require('compression') -module.exports = (app, moduleConfig) => { - if (moduleConfig.enabled) { +serverHooks.extend(({ app, isProd }) => { + if (isProd) { console.log('Output Compression is enabled') - app.use(compression(moduleConfig)) + app.use(compression({ enabled: isProd })) } -} +}) diff --git a/src/modules/google-cloud-trace/index.js b/src/modules/google-cloud-trace/index.js deleted file mode 100644 index 1ea33c72a8..0000000000 --- a/src/modules/google-cloud-trace/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const config = require('config') -let trace = require('@google-cloud/trace-agent') -if (config.server.trace.enabled) { - trace.start(config.server.trace.config) -} diff --git a/src/modules/google-cloud-trace/server.ts b/src/modules/google-cloud-trace/server.ts new file mode 100644 index 0000000000..222c4f55d1 --- /dev/null +++ b/src/modules/google-cloud-trace/server.ts @@ -0,0 +1,8 @@ +import { serverHooks } from '@vue-storefront/core/server/hooks' + +serverHooks.tracing((config) => { + let trace = require('@google-cloud/trace-agent') + if (config.has('trace') && config.get('trace.enabled')) { + trace.start(config.get('trace.config')) + } +}) diff --git a/src/modules/robots/server.ts b/src/modules/robots/server.ts index c79de50968..819a5f711f 100644 --- a/src/modules/robots/server.ts +++ b/src/modules/robots/server.ts @@ -1,6 +1,7 @@ +import { serverHooks } from '@vue-storefront/core/server/hooks' -module.exports = (app) => { +serverHooks.extend(({ app }) => { app.get('/robots.txt', (req, res) => { res.end('User-agent: *\nDisallow: ') }) -} +}) diff --git a/src/modules/server.ts b/src/modules/server.ts deleted file mode 100644 index da750abca1..0000000000 --- a/src/modules/server.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { serverHooks } from '@vue-storefront/core/server/hooks' -const isProd = process.env.NODE_ENV === 'production' - -serverHooks.onLoad(() => { - /** - * example usage - * require('./google-cloud-trace') - */ -}) - -export const serverModules = [ - 'src/modules/robots' - // ['src/modules/compress', { enabled: isProd }] -] diff --git a/yarn.lock b/yarn.lock index 3de0ff47e4..95ade87347 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2656,23 +2656,10 @@ ajv-errors@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d" -ajv-keywords@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762" - ajv-keywords@^3.0.0, ajv-keywords@^3.1.0: version "3.4.0" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.0.tgz#4b831e7b531415a7cc518cd404e73f6193c6349d" -ajv@^5.2.3, ajv@^5.3.0: - version "5.5.2" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965" - dependencies: - co "^4.6.0" - fast-deep-equal "^1.0.0" - fast-json-stable-stringify "^2.0.0" - json-schema-traverse "^0.3.0" - ajv@^6.0.1, ajv@^6.1.0, ajv@^6.5.5, ajv@^6.9.1: version "6.10.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.0.tgz#90d0d54439da587cd7e843bfb7045f50bd22bdf1" @@ -3074,7 +3061,7 @@ aws4@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" -babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: +babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" dependencies: @@ -4136,22 +4123,12 @@ caller-callsite@^2.0.0: dependencies: callsites "^2.0.0" -caller-path@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" - dependencies: - callsites "^0.2.0" - caller-path@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-2.0.0.tgz#468f83044e369ab2010fac5f06ceee15bb2cb1f4" dependencies: caller-callsite "^2.0.0" -callsites@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca" - callsites@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" @@ -4324,10 +4301,6 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: inherits "^2.0.1" safe-buffer "^5.0.1" -circular-json@^0.3.1: - version "0.3.3" - resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66" - clap@^1.0.9: version "1.2.3" resolved "https://registry.yarnpkg.com/clap/-/clap-1.2.3.tgz#4f36745b32008492557f46412d66d50cb99bce51" @@ -4602,7 +4575,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream@1.6.2, concat-stream@^1.5.0, concat-stream@^1.6.0: +concat-stream@1.6.2, concat-stream@^1.5.0: version "1.6.2" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34" dependencies: @@ -5472,12 +5445,6 @@ doctrine@1.5.0: esutils "^2.0.2" isarray "^1.0.0" -doctrine@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" - dependencies: - esutils "^2.0.2" - doctrine@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" @@ -5817,22 +5784,6 @@ eslint-module-utils@^2.4.0: debug "^2.6.8" pkg-dir "^2.0.0" -eslint-plugin-import@^2.12.0: - version "2.18.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.18.0.tgz#7a5ba8d32622fb35eb9c8db195c2090bd18a3678" - dependencies: - array-includes "^3.0.3" - contains-path "^0.1.0" - debug "^2.6.9" - doctrine "1.5.0" - eslint-import-resolver-node "^0.3.2" - eslint-module-utils "^2.4.0" - has "^1.0.3" - lodash "^4.17.11" - minimatch "^3.0.4" - read-pkg-up "^2.0.0" - resolve "^1.11.0" - eslint-plugin-import@^2.13.0: version "2.17.2" resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.17.2.tgz#d227d5c6dc67eca71eb590d2bb62fb38d86e9fcb" @@ -5872,12 +5823,6 @@ eslint-plugin-vue-storefront@^0.0.1: dependencies: requireindex "~1.2.0" -eslint-plugin-vue@^4.5.0: - version "4.7.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-4.7.1.tgz#c829b9fc62582c1897b5a0b94afd44ecca511e63" - dependencies: - vue-eslint-parser "^2.0.3" - eslint-plugin-vue@^5.2.2: version "5.2.2" resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-5.2.2.tgz#86601823b7721b70bc92d54f1728cfc03b36283c" @@ -5917,49 +5862,6 @@ eslint-visitor-keys@^1.0.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== -eslint@^4.16.0: - version "4.19.1" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.19.1.tgz#32d1d653e1d90408854bfb296f076ec7e186a300" - dependencies: - ajv "^5.3.0" - babel-code-frame "^6.22.0" - chalk "^2.1.0" - concat-stream "^1.6.0" - cross-spawn "^5.1.0" - debug "^3.1.0" - doctrine "^2.1.0" - eslint-scope "^3.7.1" - eslint-visitor-keys "^1.0.0" - espree "^3.5.4" - esquery "^1.0.0" - esutils "^2.0.2" - file-entry-cache "^2.0.0" - functional-red-black-tree "^1.0.1" - glob "^7.1.2" - globals "^11.0.1" - ignore "^3.3.3" - imurmurhash "^0.1.4" - inquirer "^3.0.6" - is-resolvable "^1.0.0" - js-yaml "^3.9.1" - json-stable-stringify-without-jsonify "^1.0.1" - levn "^0.3.0" - lodash "^4.17.4" - minimatch "^3.0.2" - mkdirp "^0.5.1" - natural-compare "^1.4.0" - optionator "^0.8.2" - path-is-inside "^1.0.2" - pluralize "^7.0.0" - progress "^2.0.0" - regexpp "^1.0.1" - require-uncached "^1.0.3" - semver "^5.3.0" - strip-ansi "^4.0.0" - strip-json-comments "~2.0.1" - table "4.0.2" - text-table "~0.2.0" - eslint@^5.0.0: version "5.16.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.16.0.tgz#a1e3ac1aae4a3fbd8296fcf8f7ab7314cbb6abea" @@ -6001,7 +5903,7 @@ eslint@^5.0.0: table "^5.2.3" text-table "^0.2.0" -espree@^3.5.2, espree@^3.5.4: +espree@^3.5.2: version "3.5.4" resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7" dependencies: @@ -6313,10 +6215,6 @@ eyes@0.1.x: version "0.1.8" resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" -fast-deep-equal@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614" - fast-deep-equal@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" @@ -6388,13 +6286,6 @@ figures@^2.0.0: dependencies: escape-string-regexp "^1.0.5" -file-entry-cache@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-2.0.0.tgz#c392990c3e684783d838b8c84a45d8a048458361" - dependencies: - flat-cache "^1.2.1" - object-assign "^4.0.1" - file-entry-cache@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c" @@ -6513,15 +6404,6 @@ findup-sync@^2.0.0: micromatch "^3.0.4" resolve-dir "^1.0.1" -flat-cache@^1.2.1: - version "1.3.4" - resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.4.tgz#2c2ef77525cc2929007dfffa1dd314aa9c9dee6f" - dependencies: - circular-json "^0.3.1" - graceful-fs "^4.1.2" - rimraf "~2.6.2" - write "^0.2.1" - flat-cache@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" @@ -6914,7 +6796,7 @@ glob@7.1.3, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glo once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.1.3: +glob@^7.1.3, glob@^7.1.4: version "7.1.4" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255" dependencies: @@ -6956,7 +6838,7 @@ global@^4.3.2: min-document "^2.19.0" process "~0.5.1" -globals@^11.0.1, globals@^11.1.0, globals@^11.7.0: +globals@^11.1.0, globals@^11.7.0: version "11.12.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" @@ -7425,7 +7307,7 @@ ignore-walk@^3.0.1: dependencies: minimatch "^3.0.4" -ignore@^3.3.3, ignore@^3.3.5, ignore@^3.3.6: +ignore@^3.3.5, ignore@^3.3.6: version "3.3.10" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043" @@ -7547,7 +7429,7 @@ init-package-json@^1.10.3: validate-npm-package-license "^3.0.1" validate-npm-package-name "^3.0.0" -inquirer@^3.0.6, inquirer@^3.3.0: +inquirer@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.3.0.tgz#9dd2f2ad765dcab1ff0443b491442a20ba227dc9" dependencies: @@ -7874,10 +7756,6 @@ is-regexp@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069" -is-resolvable@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88" - is-retry-allowed@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34" @@ -8456,7 +8334,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" -js-yaml@^3.11.0, js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.9.0, js-yaml@^3.9.1: +js-yaml@^3.11.0, js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.9.0: version "3.13.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" dependencies: @@ -8528,10 +8406,6 @@ json-parse-better-errors@^1.0.0, json-parse-better-errors@^1.0.1, json-parse-bet version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" -json-schema-traverse@^0.3.0: - version "0.3.1" - resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" - json-schema-traverse@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" @@ -10714,10 +10588,6 @@ please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1: dependencies: semver-compare "^1.0.0" -pluralize@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777" - pm2-axon-rpc@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/pm2-axon-rpc/-/pm2-axon-rpc-0.5.1.tgz#ad3c43c43811c71f13e5eee2821194d03ceb03fe" @@ -11660,10 +11530,6 @@ regexp-tree@^0.1.0: version "0.1.6" resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.6.tgz#84900fa12fdf428a2ac25f04300382a7c0148479" -regexpp@^1.0.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-1.1.0.tgz#0e3516dd0b7904f413d2d4193dce4618c3a689ab" - regexpp@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" @@ -11857,13 +11723,6 @@ require-main-filename@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" -require-uncached@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" - dependencies: - caller-path "^0.1.0" - resolve-from "^1.0.0" - requireindex@^1.2.0, requireindex@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef" @@ -11885,10 +11744,6 @@ resolve-dir@^1.0.0, resolve-dir@^1.0.1: expand-tilde "^2.0.0" global-modules "^1.0.0" -resolve-from@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" - resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" @@ -11918,12 +11773,6 @@ resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.2.0, resolve@^1.3.2, re dependencies: path-parse "^1.0.6" -resolve@^1.11.0: - version "1.11.1" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.1.tgz#ea10d8110376982fef578df8fc30b9ac30a07a3e" - dependencies: - path-parse "^1.0.6" - resolve@^1.12.0: version "1.12.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6" @@ -11961,7 +11810,7 @@ retry@^0.10.0: version "0.10.1" resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4" -rimraf@2, rimraf@2.6.3, rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.0, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@~2.6.2: +rimraf@2, rimraf@2.6.3, rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.0, rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.3" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" dependencies: @@ -12835,17 +12684,6 @@ synchronous-promise@^2.0.6: version "2.0.9" resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.9.tgz#b83db98e9e7ae826bf9c8261fd8ac859126c780a" -table@4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/table/-/table-4.0.2.tgz#a33447375391e766ad34d3486e6e2aedc84d2e36" - dependencies: - ajv "^5.2.3" - ajv-keywords "^2.1.0" - chalk "^2.1.0" - lodash "^4.17.4" - slice-ansi "1.0.0" - string-width "^2.1.1" - table@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/table/-/table-4.0.3.tgz#00b5e2b602f1794b9acaf9ca908a76386a7813bc" @@ -12956,7 +12794,7 @@ text-extensions@^1.0.0: version "1.9.0" resolved "https://registry.yarnpkg.com/text-extensions/-/text-extensions-1.9.0.tgz#1853e45fee39c945ce6f6c36b2d659b5aabc2a26" -text-table@^0.2.0, text-table@~0.2.0: +text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -14249,12 +14087,6 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -write@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/write/-/write-0.2.1.tgz#5fc03828e264cea3fe91455476f7a3c566cb0757" - dependencies: - mkdirp "^0.5.1" - ws@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/ws/-/ws-4.1.0.tgz#a979b5d7d4da68bf54efe0408967c324869a7289" From 09046188e7b97194a0c67c4a88c2152c09dec1cb Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Mon, 30 Sep 2019 06:58:06 +0200 Subject: [PATCH 05/99] Added more server hooks cache/output and renamed current hooks The new hooks are there to extend or change the current behavior of the core logic. Or to to do something before or after that. --- core/scripts/server.ts | 28 +++++++++++++-- core/server/hooks.ts | 46 +++++++++++++++++++----- src/modules/compress/server.ts | 2 +- src/modules/google-cloud-trace/server.ts | 2 +- src/modules/robots/server.ts | 2 +- 5 files changed, 66 insertions(+), 14 deletions(-) diff --git a/core/scripts/server.ts b/core/scripts/server.ts index f846e7ccd0..5a9d3a7489 100755 --- a/core/scripts/server.ts +++ b/core/scripts/server.ts @@ -10,7 +10,7 @@ serverExtensions.forEach(serverModule => { require(resolve(serverModule)) }) -serverHooksExecutors.tracing(config.server) +serverHooksExecutors.afterProcessStarted(config.server) const express = require('express') const ms = require('ms') const request = require('request'); @@ -31,7 +31,7 @@ process['noDeprecation'] = true const app = express() -serverHooksExecutors.extend({ app, config: config.server, isProd }) +serverHooksExecutors.afterApplicationInitialized({ app, config: config.server, isProd }) const templatesCache = ssr.initTemplatesCache(config, compileOptions) @@ -72,6 +72,9 @@ function invalidateCache (req, res) { tags = req.query.tag.split(',') } const subPromises = [] + + serverHooksExecutors.beforeCacheInvalidated() + tags.forEach(tag => { if (config.server.availableCacheTags.indexOf(tag) >= 0 || config.server.availableCacheTags.find(t => { return tag.indexOf(t) === 0 @@ -83,6 +86,9 @@ function invalidateCache (req, res) { console.error(`Invalid tag name ${tag}`) } }) + + serverHooksExecutors.afterCacheInvalidated() + Promise.all(subPromises).then(r => { apiStatus(res, `Tags invalidated successfully [${req.query.tag}]`, 200) }).catch(error => { @@ -179,6 +185,15 @@ app.get('*', (req, res, next) => { res.setHeader('X-VS-Cache-Tags', cacheTags) console.log(`cache tags for the request: ${cacheTags}`) } + + const hookResponse = serverHooksExecutors.beforeOutputRendered({ + req, + res, + context, + output, + isProd + }) + output = ssr.applyAdvancedOutputProcessing(context, output, templatesCache, isProd); if (config.server.useOutputCache && cache) { cache.set( @@ -187,6 +202,15 @@ app.get('*', (req, res, next) => { tagsArray ).catch(errorHandler) } + + const hookResponse2 = serverHooksExecutors.afterOutputRendered({ + req, + res, + context, + output, + isProd + }) + res.end(output) console.log(`whole request [${req.url}]: ${Date.now() - s}ms`) next() diff --git a/core/server/hooks.ts b/core/server/hooks.ts index 5026bcfb85..93ff377bea 100644 --- a/core/server/hooks.ts +++ b/core/server/hooks.ts @@ -1,11 +1,21 @@ import { createListenerHook, createMutatorHook } from '@vue-storefront/core/lib/hooks' import {Express} from 'express'; -// To add tracing without adding it directly to the core +// To add like tracing which needs to be done as early as possible const { - hook: tracingHook, - executor: tracingExecutor + hook: afterProcessStartedHook, + executor: afterProcessStartedExecutor +} = createListenerHook() + +const { + hook: beforeCacheInvalidatedHook, + executor: beforeCacheInvalidatedExecutor +} = createListenerHook() + +const { + hook: afterCacheInvalidatedHook, + executor: afterCacheInvalidatedExecutor } = createListenerHook() // beforeStartApp @@ -15,25 +25,43 @@ interface Extend { isProd: boolean } const { - hook: extendHook, - executor: extendExecutor + hook: afterApplicationInitializedHook, + executor: afterApplicationInitializedExecutor } = createListenerHook() +const { + hook: beforeOutputRenderedHook, + executor: beforeOutputRenderedExecutor +} = createMutatorHook() + +const { + hook: afterOutputRenderedHook, + executor: afterOutputRenderedExecutor +} = createMutatorHook() + /** Only for internal usage in this module */ const serverHooksExecutors = { - tracing: tracingExecutor, - extend: extendExecutor + afterProcessStarted: afterProcessStartedExecutor, + afterApplicationInitialized: afterApplicationInitializedExecutor, + beforeOutputRendered: beforeOutputRenderedExecutor, + afterOutputRendered: afterOutputRenderedExecutor, + beforeCacheInvalidated: beforeCacheInvalidatedExecutor, + afterCacheInvalidated: afterCacheInvalidatedExecutor } const serverHooks = { /** Hook is fired right at the start of the app. * @param void */ - tracing: tracingHook, + afterProcessStarted: afterProcessStartedHook, /** * */ - extend: extendHook + afterApplicationInitialized: afterApplicationInitializedHook, + beforeOutputRendered: beforeOutputRenderedHook, + afterOutputRendered: afterOutputRenderedHook, + beforeCacheInvalidated: beforeCacheInvalidatedHook, + afterCacheInvalidated: afterCacheInvalidatedHook } export { diff --git a/src/modules/compress/server.ts b/src/modules/compress/server.ts index df6b31e9cd..3ca3054bc7 100644 --- a/src/modules/compress/server.ts +++ b/src/modules/compress/server.ts @@ -1,7 +1,7 @@ import { serverHooks } from '@vue-storefront/core/server/hooks' const compression = require('compression') -serverHooks.extend(({ app, isProd }) => { +serverHooks.afterApplicationInitialized(({ app, isProd }) => { if (isProd) { console.log('Output Compression is enabled') app.use(compression({ enabled: isProd })) diff --git a/src/modules/google-cloud-trace/server.ts b/src/modules/google-cloud-trace/server.ts index 222c4f55d1..5e7db50b0b 100644 --- a/src/modules/google-cloud-trace/server.ts +++ b/src/modules/google-cloud-trace/server.ts @@ -1,6 +1,6 @@ import { serverHooks } from '@vue-storefront/core/server/hooks' -serverHooks.tracing((config) => { +serverHooks.afterProcessStarted((config) => { let trace = require('@google-cloud/trace-agent') if (config.has('trace') && config.get('trace.enabled')) { trace.start(config.get('trace.config')) diff --git a/src/modules/robots/server.ts b/src/modules/robots/server.ts index 819a5f711f..f245ca1240 100644 --- a/src/modules/robots/server.ts +++ b/src/modules/robots/server.ts @@ -1,6 +1,6 @@ import { serverHooks } from '@vue-storefront/core/server/hooks' -serverHooks.extend(({ app }) => { +serverHooks.afterApplicationInitialized(({ app }) => { app.get('/robots.txt', (req, res) => { res.end('User-agent: *\nDisallow: ') }) From 8e97a8a4f88815c1dfc9dd97ea1e9dd8dc680a35 Mon Sep 17 00:00:00 2001 From: Rain2o Date: Fri, 27 Sep 2019 18:29:44 +0200 Subject: [PATCH 06/99] save the payment methods returned on updateTotals to state. --- core/modules/cart/helpers/createOrderData.ts | 9 +++++++++ core/modules/cart/helpers/createShippingInfoData.ts | 3 +++ core/modules/cart/store/actions/totalsActions.ts | 10 ++++++++-- core/modules/cart/types/BillingAddress.ts | 8 ++++++++ core/modules/cart/types/CheckoutData.ts | 2 ++ core/modules/cart/types/OrderShippingDetails.ts | 4 +++- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 core/modules/cart/types/BillingAddress.ts diff --git a/core/modules/cart/helpers/createOrderData.ts b/core/modules/cart/helpers/createOrderData.ts index d79e382425..37c12e34ac 100644 --- a/core/modules/cart/helpers/createOrderData.ts +++ b/core/modules/cart/helpers/createOrderData.ts @@ -21,6 +21,7 @@ const createOrderData = ({ shippingDetails, shippingMethods, paymentMethods, + paymentDetails, taxCountry = currentStoreView().tax.defaultCountry }: CheckoutData): OrderShippingDetails => { const country = shippingDetails.country ? shippingDetails.country : taxCountry @@ -36,6 +37,14 @@ const createOrderData = ({ postcode: shippingDetails.zipCode, street: [shippingDetails.streetAddress] }, + billingAddress: { + firstname: paymentDetails.firstName, + lastname: paymentDetails.lastName, + city: paymentDetails.city, + postcode: paymentDetails.zipCode, + street: [paymentDetails.streetAddress], + countryId: paymentDetails.country + }, method_code: shipping && shipping.method_code ? shipping.method_code : null, carrier_code: shipping && shipping.carrier_code ? shipping.carrier_code : null, payment_method: payment && payment.code ? payment.code : null diff --git a/core/modules/cart/helpers/createShippingInfoData.ts b/core/modules/cart/helpers/createShippingInfoData.ts index 394cfc86ed..e42b0f19ff 100644 --- a/core/modules/cart/helpers/createShippingInfoData.ts +++ b/core/modules/cart/helpers/createShippingInfoData.ts @@ -3,6 +3,9 @@ const createShippingInfoData = (methodsData) => ({ countryId: methodsData.country, ...(methodsData.shippingAddress ? methodsData.shippingAddress : {}) }, + billingAddress: { + ...(methodsData.billingAddress ? methodsData.billingAddress : {}) + }, shippingCarrierCode: methodsData.carrier_code, shippingMethodCode: methodsData.method_code }); diff --git a/core/modules/cart/store/actions/totalsActions.ts b/core/modules/cart/store/actions/totalsActions.ts index a31379d674..16ae4f396c 100644 --- a/core/modules/cart/store/actions/totalsActions.ts +++ b/core/modules/cart/store/actions/totalsActions.ts @@ -15,7 +15,7 @@ const totalsActions = { return CartService.getTotals() }, - async overrideServerTotals ({ commit, dispatch }, { addressInformation, hasShippingInformation }) { + async overrideServerTotals ({ commit, getters, dispatch }, { addressInformation, hasShippingInformation }) { const { resultCode, result } = await dispatch('getTotals', { addressInformation, hasShippingInformation }) if (resultCode === 200) { @@ -32,6 +32,11 @@ const totalsActions = { commit(types.CART_UPD_TOTALS, { itemsAfterTotal, totals, platformTotalSegments: totals.total_segments }) commit(types.CART_SET_TOTALS_SYNC) + // we received payment methods as a result of this call, updating state + if (result.payment_methods && getters.canUpdateMethods) { + dispatch('checkout/replacePaymentMethods', result.payment_methods, { root: true }) + } + return } @@ -45,7 +50,8 @@ const totalsActions = { const shippingMethodsData = methodsData || createOrderData({ shippingDetails: rootGetters['checkout/getShippingDetails'], shippingMethods: rootGetters['checkout/getShippingMethods'], - paymentMethods: rootGetters['checkout/getPaymentMethods'] + paymentMethods: rootGetters['checkout/getPaymentMethods'], + paymentDetails: rootGetters['checkout/getPaymentDetails'] }) if (shippingMethodsData.country) { diff --git a/core/modules/cart/types/BillingAddress.ts b/core/modules/cart/types/BillingAddress.ts new file mode 100644 index 0000000000..18d17cc487 --- /dev/null +++ b/core/modules/cart/types/BillingAddress.ts @@ -0,0 +1,8 @@ +export default interface ShippingAddress { + firstname: string, + lastname: string, + city: string, + postcode: string, + street: string[], + countryId: string +} diff --git a/core/modules/cart/types/CheckoutData.ts b/core/modules/cart/types/CheckoutData.ts index feac99cb00..4e2c5c676e 100644 --- a/core/modules/cart/types/CheckoutData.ts +++ b/core/modules/cart/types/CheckoutData.ts @@ -1,10 +1,12 @@ import ShippingDetails from '@vue-storefront/core/modules/checkout/types/ShippingDetails' import ShippingMethod from './ShippingMethod' import PaymentMethod from './PaymentMethod' +import PaymentDetails from '@vue-storefront/core/modules/checkout/types/PaymentDetails' export default interface CheckoutData { shippingDetails: ShippingDetails, shippingMethods: ShippingMethod[], paymentMethods: PaymentMethod[], + paymentDetails: PaymentDetails, taxCountry?: string } diff --git a/core/modules/cart/types/OrderShippingDetails.ts b/core/modules/cart/types/OrderShippingDetails.ts index a455dda4d2..ebfc2005c5 100644 --- a/core/modules/cart/types/OrderShippingDetails.ts +++ b/core/modules/cart/types/OrderShippingDetails.ts @@ -1,9 +1,11 @@ import ShippingAddress from './ShippingAddress' +import BillingAddress from './BillingAddress' export default interface OrderShippingDetails { country?: string, method_code?: string, carrier_code?: string, payment_method?: string, - shippingAddress?: ShippingAddress + shippingAddress?: ShippingAddress, + billingAddress?: BillingAddress } From 4ac4c71b8ab65e3540f2b2a2f802512bcfe7ae27 Mon Sep 17 00:00:00 2001 From: Rain2o Date: Mon, 30 Sep 2019 11:31:27 +0200 Subject: [PATCH 07/99] Update payment methods on billing country change --- .../cart/store/actions/methodsActions.ts | 28 +++++++++++++++++-- core/modules/checkout/components/Payment.ts | 3 ++ core/pages/Checkout.js | 6 ++++ .../core/blocks/Checkout/Payment.vue | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/modules/cart/store/actions/methodsActions.ts b/core/modules/cart/store/actions/methodsActions.ts index 662e3ef472..8936c3fada 100644 --- a/core/modules/cart/store/actions/methodsActions.ts +++ b/core/modules/cart/store/actions/methodsActions.ts @@ -3,7 +3,8 @@ import { currentStoreView } from '@vue-storefront/core/lib/multistore' import { Logger } from '@vue-storefront/core/lib/logger' import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus' import { CartService } from '@vue-storefront/core/data-resolver' -import { preparePaymentMethodsToSync } from '@vue-storefront/core/modules/cart/helpers' +import { preparePaymentMethodsToSync, createOrderData, createShippingInfoData } from '@vue-storefront/core/modules/cart/helpers' +import PaymentMethod from '../../types/PaymentMethod' const methodsActions = { async pullMethods ({ getters, dispatch }, { forceServerSync }) { @@ -26,9 +27,30 @@ const methodsActions = { async syncPaymentMethods ({ getters, rootGetters, dispatch }, { forceServerSync = false }) { if (getters.canUpdateMethods && (getters.isTotalsSyncRequired || forceServerSync)) { Logger.debug('Refreshing payment methods', 'cart')() - const { result } = await CartService.getPaymentMethods() + let backendPaymentMethods: PaymentMethod[] + + const paymentDetails = rootGetters['checkout/getPaymentDetails'] + if (paymentDetails.country) { + // use shipping info endpoint to get payment methods using billing address + const shippingMethodsData = createOrderData({ + shippingDetails: rootGetters['checkout/getShippingDetails'], + shippingMethods: rootGetters['checkout/getShippingMethods'], + paymentMethods: rootGetters['checkout/getPaymentMethods'], + paymentDetails: rootGetters['checkout/getPaymentDetails'] + }) + + if (shippingMethodsData.country) { + const { result } = await CartService.setShippingInfo(createShippingInfoData(shippingMethodsData)) + backendPaymentMethods = result.payment_methods || [] + } + } + if (!backendPaymentMethods || backendPaymentMethods.length === 0) { + const { result } = await CartService.getPaymentMethods() + backendPaymentMethods = result + } + const { uniqueBackendMethods, paymentMethods } = preparePaymentMethodsToSync( - result, + backendPaymentMethods, rootGetters['checkout/getNotServerPaymentMethods'] ) await dispatch('checkout/replacePaymentMethods', paymentMethods, { root: true }) diff --git a/core/modules/checkout/components/Payment.ts b/core/modules/checkout/components/Payment.ts index d37a4f209d..11d86e1056 100644 --- a/core/modules/checkout/components/Payment.ts +++ b/core/modules/checkout/components/Payment.ts @@ -232,6 +232,9 @@ export const Payment = { // Let anyone listening know that we've changed payment method, usually a payment extension. this.$bus.$emit('checkout-payment-method-changed', this.payment.paymentMethod) + }, + changeCountry () { + this.$bus.$emit('checkout-before-paymentMethods') } } } diff --git a/core/pages/Checkout.js b/core/pages/Checkout.js index b4fb31ed88..53e50bef19 100644 --- a/core/pages/Checkout.js +++ b/core/pages/Checkout.js @@ -59,6 +59,7 @@ export default { this.$bus.$on('checkout-before-edit', this.onBeforeEdit) this.$bus.$on('order-after-placed', this.onAfterPlaceOrder) this.$bus.$on('checkout-before-shippingMethods', this.onBeforeShippingMethods) + this.$bus.$on('checkout-before-paymentMethods', this.onBeforePaymentMethods) this.$bus.$on('checkout-after-shippingMethodChanged', this.onAfterShippingMethodChanged) this.$bus.$on('checkout-after-validationError', this.focusField) if (!this.isThankYouPage) { @@ -118,6 +119,7 @@ export default { this.$bus.$off('checkout-before-edit', this.onBeforeEdit) this.$bus.$off('order-after-placed', this.onAfterPlaceOrder) this.$bus.$off('checkout-before-shippingMethods', this.onBeforeShippingMethods) + this.$bus.$off('checkout-before-paymentMethods', this.onBeforePaymentMethods) this.$bus.$off('checkout-after-shippingMethodChanged', this.onAfterShippingMethodChanged) this.$bus.$off('checkout-after-validationError', this.focusField) }, @@ -140,6 +142,10 @@ export default { this.$store.dispatch('cart/syncTotals', { forceServerSync: true }) this.$forceUpdate() }, + onBeforePaymentMethods () { + this.$store.dispatch('cart/syncPaymentMethods', { forceServerSync: true }) + this.$forceUpdate() + }, async onAfterPlaceOrder (payload) { this.confirmation = payload.confirmation if (this.$store.state.checkout.personalDetails.createAccount) { diff --git a/src/themes/default/components/core/blocks/Checkout/Payment.vue b/src/themes/default/components/core/blocks/Checkout/Payment.vue index 6084ad3e4c..ba81a82364 100644 --- a/src/themes/default/components/core/blocks/Checkout/Payment.vue +++ b/src/themes/default/components/core/blocks/Checkout/Payment.vue @@ -171,7 +171,7 @@ v-model="payment.country" autocomplete="country-name" @blur="$v.payment.country.$touch()" - @change="$v.payment.country.$touch()" + @change="$v.payment.country.$touch(); changeCountry();" /> Date: Mon, 30 Sep 2019 11:33:47 +0200 Subject: [PATCH 08/99] Updated changelog with payment method for billing address change. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a399d6048..71d3eaddd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Route Manager Queue for adding routes efficiently and with an optional priority - @grimasod (#3540) - Added tests for cart module actions - @andrzejewsky (#3023) - Fixed a problem with type changes in the state when extending a store - @resubaka (#3618) +- Get payment methods with billing address data - @rain2o (#2878) ### Fixed From 1b2e01c86819125eebb1e0419f84fe2f76e99432 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 2 Oct 2019 13:25:41 +0200 Subject: [PATCH 09/99] Renamed hooks and added use of return of MutatorHooks --- core/scripts/server.ts | 21 +++++++++++++++++---- core/server/hooks.ts | 25 +++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/core/scripts/server.ts b/core/scripts/server.ts index 5a9d3a7489..c6652e60b8 100755 --- a/core/scripts/server.ts +++ b/core/scripts/server.ts @@ -73,7 +73,7 @@ function invalidateCache (req, res) { } const subPromises = [] - serverHooksExecutors.beforeCacheInvalidated() + serverHooksExecutors.beforeCacheInvalidated({ tags, req }) tags.forEach(tag => { if (config.server.availableCacheTags.indexOf(tag) >= 0 || config.server.availableCacheTags.find(t => { @@ -186,7 +186,7 @@ app.get('*', (req, res, next) => { console.log(`cache tags for the request: ${cacheTags}`) } - const hookResponse = serverHooksExecutors.beforeOutputRendered({ + const beforeOutputRenderedResponse = serverHooksExecutors.beforeOutputRenderedResponse({ req, res, context, @@ -194,6 +194,12 @@ app.get('*', (req, res, next) => { isProd }) + if (typeof beforeOutputRenderedResponse.output === 'string') { + output = beforeOutputRenderedResponse.output + } else if (typeof beforeOutputRenderedResponse === 'string') { + output = beforeOutputRenderedResponse + } + output = ssr.applyAdvancedOutputProcessing(context, output, templatesCache, isProd); if (config.server.useOutputCache && cache) { cache.set( @@ -203,7 +209,7 @@ app.get('*', (req, res, next) => { ).catch(errorHandler) } - const hookResponse2 = serverHooksExecutors.afterOutputRendered({ + const afterOutputRenderedResponse = serverHooksExecutors.afterOutputRenderedResponse({ req, res, context, @@ -211,7 +217,14 @@ app.get('*', (req, res, next) => { isProd }) - res.end(output) + if (typeof afterOutputRenderedResponse.output === 'string') { + res.end(afterOutputRenderedResponse.output) + } else if (typeof afterOutputRenderedResponse === 'string') { + res.end(afterOutputRenderedResponse) + } else { + res.end(output) + } + console.log(`whole request [${req.url}]: ${Date.now() - s}ms`) next() }).catch(errorHandler) diff --git a/core/server/hooks.ts b/core/server/hooks.ts index 93ff377bea..f7941c7955 100644 --- a/core/server/hooks.ts +++ b/core/server/hooks.ts @@ -1,5 +1,5 @@ import { createListenerHook, createMutatorHook } from '@vue-storefront/core/lib/hooks' -import {Express} from 'express'; +import { Express, Request } from 'express'; // To add like tracing which needs to be done as early as possible @@ -8,10 +8,15 @@ const { executor: afterProcessStartedExecutor } = createListenerHook() +interface beforeCacheInvalidatedParamter { + tags: string[], + req: Request +} + const { hook: beforeCacheInvalidatedHook, executor: beforeCacheInvalidatedExecutor -} = createListenerHook() +} = createListenerHook() const { hook: afterCacheInvalidatedHook, @@ -30,21 +35,21 @@ const { } = createListenerHook() const { - hook: beforeOutputRenderedHook, - executor: beforeOutputRenderedExecutor + hook: beforeOutputRenderedResponseHook, + executor: beforeOutputRenderedResponseExecutor } = createMutatorHook() const { - hook: afterOutputRenderedHook, - executor: afterOutputRenderedExecutor + hook: afterOutputRenderedResponseHook, + executor: afterOutputRenderedResponseExecutor } = createMutatorHook() /** Only for internal usage in this module */ const serverHooksExecutors = { afterProcessStarted: afterProcessStartedExecutor, afterApplicationInitialized: afterApplicationInitializedExecutor, - beforeOutputRendered: beforeOutputRenderedExecutor, - afterOutputRendered: afterOutputRenderedExecutor, + beforeOutputRenderedResponse: beforeOutputRenderedResponseExecutor, + afterOutputRenderedResponse: afterOutputRenderedResponseExecutor, beforeCacheInvalidated: beforeCacheInvalidatedExecutor, afterCacheInvalidated: afterCacheInvalidatedExecutor } @@ -58,8 +63,8 @@ const serverHooks = { * */ afterApplicationInitialized: afterApplicationInitializedHook, - beforeOutputRendered: beforeOutputRenderedHook, - afterOutputRendered: afterOutputRenderedHook, + beforeOutputRenderedResponse: beforeOutputRenderedResponseHook, + afterOutputRenderedResponse: afterOutputRenderedResponseHook, beforeCacheInvalidated: beforeCacheInvalidatedHook, afterCacheInvalidated: afterCacheInvalidatedHook } From 9792535cfc5c9830b3bbee96024d0541297f7cba Mon Sep 17 00:00:00 2001 From: Rain2o Date: Thu, 3 Oct 2019 10:11:43 +0200 Subject: [PATCH 10/99] Fixed name of BillingAddress interface --- core/modules/cart/types/BillingAddress.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/cart/types/BillingAddress.ts b/core/modules/cart/types/BillingAddress.ts index 18d17cc487..be0bae3f4b 100644 --- a/core/modules/cart/types/BillingAddress.ts +++ b/core/modules/cart/types/BillingAddress.ts @@ -1,4 +1,4 @@ -export default interface ShippingAddress { +export default interface BillingAddress { firstname: string, lastname: string, city: string, From ac9ad425832ca96ff258e4ba9059ba1b5ec68462 Mon Sep 17 00:00:00 2001 From: Rain2o Date: Thu, 3 Oct 2019 10:12:18 +0200 Subject: [PATCH 11/99] Removed use of bus emit and dispatch cart/syncPaymentMethods directly. --- core/modules/checkout/components/Payment.ts | 2 +- core/pages/Checkout.js | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/modules/checkout/components/Payment.ts b/core/modules/checkout/components/Payment.ts index 81f79b33c1..a9895efdaa 100644 --- a/core/modules/checkout/components/Payment.ts +++ b/core/modules/checkout/components/Payment.ts @@ -235,7 +235,7 @@ export const Payment = { this.$bus.$emit('checkout-payment-method-changed', this.payment.paymentMethod) }, changeCountry () { - this.$bus.$emit('checkout-before-paymentMethods') + this.$store.dispatch('cart/syncPaymentMethods', { forceServerSync: true }) } } } diff --git a/core/pages/Checkout.js b/core/pages/Checkout.js index 53e50bef19..b4fb31ed88 100644 --- a/core/pages/Checkout.js +++ b/core/pages/Checkout.js @@ -59,7 +59,6 @@ export default { this.$bus.$on('checkout-before-edit', this.onBeforeEdit) this.$bus.$on('order-after-placed', this.onAfterPlaceOrder) this.$bus.$on('checkout-before-shippingMethods', this.onBeforeShippingMethods) - this.$bus.$on('checkout-before-paymentMethods', this.onBeforePaymentMethods) this.$bus.$on('checkout-after-shippingMethodChanged', this.onAfterShippingMethodChanged) this.$bus.$on('checkout-after-validationError', this.focusField) if (!this.isThankYouPage) { @@ -119,7 +118,6 @@ export default { this.$bus.$off('checkout-before-edit', this.onBeforeEdit) this.$bus.$off('order-after-placed', this.onAfterPlaceOrder) this.$bus.$off('checkout-before-shippingMethods', this.onBeforeShippingMethods) - this.$bus.$off('checkout-before-paymentMethods', this.onBeforePaymentMethods) this.$bus.$off('checkout-after-shippingMethodChanged', this.onAfterShippingMethodChanged) this.$bus.$off('checkout-after-validationError', this.focusField) }, @@ -142,10 +140,6 @@ export default { this.$store.dispatch('cart/syncTotals', { forceServerSync: true }) this.$forceUpdate() }, - onBeforePaymentMethods () { - this.$store.dispatch('cart/syncPaymentMethods', { forceServerSync: true }) - this.$forceUpdate() - }, async onAfterPlaceOrder (payload) { this.confirmation = payload.confirmation if (this.$store.state.checkout.personalDetails.createAccount) { From 16094a5727cd3648edac74eeb9f56227df59279f Mon Sep 17 00:00:00 2001 From: Rain2o Date: Thu, 3 Oct 2019 11:54:44 +0200 Subject: [PATCH 12/99] Removed redundant use of getter --- core/modules/cart/store/actions/methodsActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/cart/store/actions/methodsActions.ts b/core/modules/cart/store/actions/methodsActions.ts index 5e5bfd9779..5eb415925d 100644 --- a/core/modules/cart/store/actions/methodsActions.ts +++ b/core/modules/cart/store/actions/methodsActions.ts @@ -36,7 +36,7 @@ const methodsActions = { shippingDetails: rootGetters['checkout/getShippingDetails'], shippingMethods: rootGetters['checkout/getShippingMethods'], paymentMethods: rootGetters['checkout/getPaymentMethods'], - paymentDetails: rootGetters['checkout/getPaymentDetails'] + paymentDetails: paymentDetails }) if (shippingMethodsData.country) { From 2ce6f5b3d1879c33900922175e5dcda597c04bd3 Mon Sep 17 00:00:00 2001 From: Rain2o Date: Thu, 3 Oct 2019 11:55:34 +0200 Subject: [PATCH 13/99] unit test for payment methods for billing address updates. --- .../test/unit/helpers/createOrderData.spec.ts | 47 +++++++++++++++++-- .../helpers/createShippingInfoData.spec.ts | 32 +++++++++++++ .../test/unit/store/methodsActions.spec.ts | 9 ++-- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/core/modules/cart/test/unit/helpers/createOrderData.spec.ts b/core/modules/cart/test/unit/helpers/createOrderData.spec.ts index c81c876c74..411162be95 100644 --- a/core/modules/cart/test/unit/helpers/createOrderData.spec.ts +++ b/core/modules/cart/test/unit/helpers/createOrderData.spec.ts @@ -19,6 +19,23 @@ const shippingDetails = { shippingMethod: 'method' }; +const paymentDetails = { + country: 'UK', + firstName: 'John', + lastName: 'Doe', + city: 'London', + zipCode: 'EC123', + streetAddress: 'JohnDoe street', + region_id: 1, + apartmentNumber: '12', + state: 'xxxx', + phoneNumber: '123123123', + company: '', + taxId: '', + paymentMethod: '', + paymentMethodAdditional: [] +}; + describe('Cart createOrderData', () => { it('returns data with default shipping and default payment', async () => { const shippingMethods = [ @@ -47,7 +64,7 @@ describe('Cart createOrderData', () => { } ]; - const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, taxCountry: 'DE' }) + const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, paymentDetails, taxCountry: 'DE' }) expect(methodsData).toEqual({ carrier_code: 'CODE4', @@ -60,6 +77,14 @@ describe('Cart createOrderData', () => { lastname: 'Doe', postcode: 'EC123', street: ['JohnDoe street'] + }, + billingAddress: { + city: 'London', + countryId: 'UK', + firstname: 'John', + lastname: 'Doe', + postcode: 'EC123', + street: ['JohnDoe street'] } }); }); @@ -91,7 +116,7 @@ describe('Cart createOrderData', () => { } ]; - const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, taxCountry: 'DE' }) + const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, paymentDetails, taxCountry: 'DE' }) expect(methodsData).toEqual({ carrier_code: 'CODE2-first', @@ -104,6 +129,14 @@ describe('Cart createOrderData', () => { lastname: 'Doe', postcode: 'EC123', street: ['JohnDoe street'] + }, + billingAddress: { + city: 'London', + countryId: 'UK', + firstname: 'John', + lastname: 'Doe', + postcode: 'EC123', + street: ['JohnDoe street'] } }); }); @@ -111,7 +144,7 @@ describe('Cart createOrderData', () => { it('returns data without payment, carrier and method', async () => { const shippingMethods = []; const paymentMethods = []; - const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, taxCountry: 'DE' }); + const methodsData = createOrderData({ shippingDetails, shippingMethods, paymentMethods, paymentDetails, taxCountry: 'DE' }); expect(methodsData).toEqual({ carrier_code: null, @@ -124,6 +157,14 @@ describe('Cart createOrderData', () => { lastname: 'Doe', postcode: 'EC123', street: ['JohnDoe street'] + }, + billingAddress: { + city: 'London', + countryId: 'UK', + firstname: 'John', + lastname: 'Doe', + postcode: 'EC123', + street: ['JohnDoe street'] } }); }); diff --git a/core/modules/cart/test/unit/helpers/createShippingInfoData.spec.ts b/core/modules/cart/test/unit/helpers/createShippingInfoData.spec.ts index 277ae13103..ed2bfbfc80 100644 --- a/core/modules/cart/test/unit/helpers/createShippingInfoData.spec.ts +++ b/core/modules/cart/test/unit/helpers/createShippingInfoData.spec.ts @@ -9,6 +9,7 @@ describe('Cart createShippingInfoData', () => { }; const shippingInfoData = createShippingInfoData(methodsData); expect(shippingInfoData).toEqual({ + billingAddress: {}, shippingAddress: { countryId: 'UK' }, @@ -32,6 +33,7 @@ describe('Cart createShippingInfoData', () => { }; const shippingInfoData = createShippingInfoData(methodsData); expect(shippingInfoData).toEqual({ + billingAddress: {}, shippingAddress: { city: 'London', countryId: 'UK', @@ -44,4 +46,34 @@ describe('Cart createShippingInfoData', () => { shippingMethodCode: 'YY' }); }); + + it('returns methods data with billing address', async () => { + const methodsData = { + country: 'UK', + carrier_code: 'XX', + method_code: 'YY', + billingAddress: { + city: 'London', + countryId: 'UK', + firstname: 'John', + lastname: 'Doe', + postcode: 'EC123', + street: ['JohnDoe street'] + } + }; + const shippingInfoData = createShippingInfoData(methodsData); + expect(shippingInfoData).toEqual({ + shippingAddress: { countryId: 'UK' }, + billingAddress: { + city: 'London', + countryId: 'UK', + firstname: 'John', + lastname: 'Doe', + postcode: 'EC123', + street: ['JohnDoe street'] + }, + shippingCarrierCode: 'XX', + shippingMethodCode: 'YY' + }); + }); }); diff --git a/core/modules/cart/test/unit/store/methodsActions.spec.ts b/core/modules/cart/test/unit/store/methodsActions.spec.ts index 3980de6237..907410a941 100644 --- a/core/modules/cart/test/unit/store/methodsActions.spec.ts +++ b/core/modules/cart/test/unit/store/methodsActions.spec.ts @@ -1,6 +1,6 @@ import * as types from '@vue-storefront/core/modules/cart/store/mutation-types'; import { CartService } from '@vue-storefront/core/data-resolver'; -import { preparePaymentMethodsToSync } from '@vue-storefront/core/modules/cart/helpers'; +import { preparePaymentMethodsToSync, createOrderData } from '@vue-storefront/core/modules/cart/helpers'; import cartActions from '@vue-storefront/core/modules/cart/store/actions'; import { createContextMock } from '@vue-storefront/unit-tests/utils'; @@ -59,7 +59,8 @@ jest.mock('@vue-storefront/core/modules/cart/helpers', () => ({ merge: jest.fn(), isEmpty: jest.fn() })), - preparePaymentMethodsToSync: jest.fn() + preparePaymentMethodsToSync: jest.fn(), + createOrderData: jest.fn() })); jest.mock('@vue-storefront/core/helpers', () => ({ get isServer () { @@ -119,7 +120,8 @@ describe('Cart methodsActions', () => { it('synchronizes payment methods', async () => { const contextMock = createContextMock({ rootGetters: { - 'checkout/getNotServerPaymentMethods': [] + 'checkout/getNotServerPaymentMethods': [], + 'checkout/getPaymentDetails': { country: 'US' } }, getters: { canUpdateMethods: true, @@ -128,6 +130,7 @@ describe('Cart methodsActions', () => { }); (CartService.getPaymentMethods as jest.Mock).mockImplementation(() => Promise.resolve({ result: {} })); + (createOrderData as jest.Mock).mockImplementation(() => ({ shippingMethodsData: {} })); (preparePaymentMethodsToSync as jest.Mock).mockImplementation(() => ({ uniqueBackendMethods: [], paymentMethods: [] })); await (cartActions as any).syncPaymentMethods(contextMock, {}); From 525758924bc165fb3eaf5e3e22cabf1d5fdb4a1b Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 07:26:12 +0200 Subject: [PATCH 14/99] Fixed cmsBlock getter cmsBlockIdentifier which called it self This leads to an error. --- core/modules/cms/store/block/getters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/cms/store/block/getters.ts b/core/modules/cms/store/block/getters.ts index a6dea8c0d3..c70f5333f7 100644 --- a/core/modules/cms/store/block/getters.ts +++ b/core/modules/cms/store/block/getters.ts @@ -6,7 +6,7 @@ const getters: GetterTree = { // @deprecated cmsBlocks: (state, getters) => getters.getCmsBlocks, // @deprecated - cmsBlockIdentifier: (state, getters) => (identifier) => getters.cmsBlockIdentifier(identifier), + cmsBlockIdentifier: (state, getters) => (identifier) => getters.getCmsBlockByIdentifier(identifier), // @deprecated cmsBlockId: (state, getters) => (id) => getters.getCmsBlockById(id), getCmsBlockByIdentifier: (state) => (identifier) => From e4678a78ca84a1dbac0d58383593d4275742c8ec Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 07:36:12 +0200 Subject: [PATCH 15/99] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c64949d845..99c08e0863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.11.0-rc.2] - unreleased + +### Fixed + + - Fixed deprecated getter in cmsBlock store - @resubaka (#3683) + ## [1.11.0-rc.1] - 2019.10.03 ### Added From ce8dcaac9cf066e51a1f2faaef517b4bed4ae612 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:43:40 +0200 Subject: [PATCH 16/99] Fix: Dynamic urls name should only be prefixed when appendStoreCode is true This is a fix for when you have the baseStore set to an storeView store for example de and have appendStoreCode false and url as /. Then it currently does not work when multistore is active. With this is does work as the base url is now the de store with no prefix in the dynamic url name. --- core/lib/multistore.ts | 8 ++++++-- core/modules/catalog-next/store/category/actions.ts | 4 ++-- core/modules/catalog/store/category/actions.ts | 4 ++-- core/modules/catalog/store/product/actions.ts | 4 ++-- core/modules/url/store/actions.ts | 6 +++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/lib/multistore.ts b/core/lib/multistore.ts index e0b1244245..22ef790291 100644 --- a/core/lib/multistore.ts +++ b/core/lib/multistore.ts @@ -141,8 +141,11 @@ export function localizedDispatcherRoute (routeObj: LocalizedRoute | string, sto return routeObj } -export function localizedDispatcherRouteName (routeName: string, storeCode: string): string { - return storeCode ? `${storeCode}-${routeName}` : routeName +export function localizedDispatcherRouteName (routeName: string, storeCode: string, appendStoreCode: boolean = false): string { + if (appendStoreCode) { + return `${storeCode}-${routeName}` + } + return routeName } export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig | RawLocation, storeCode: string): any { @@ -170,6 +173,7 @@ export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig } export function setupMultistoreRoutes (config, router: VueRouter, routes: RouteConfig[], priority: number = 0): void { + debugger const allRoutes: RouteConfig[] = [] const { storeCode, appendStoreCode } = currentStoreView() if (storeCode && appendStoreCode) { diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index b9de48da1d..5a1a9a5f8e 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -109,14 +109,14 @@ const actions: ActionTree = { }) }, async registerCategoryProductsMapping ({ dispatch }, products = []) { - const storeCode = currentStoreView().storeCode + const { storeCode, appendStoreCode } = currentStoreView() await Promise.all(products.map(product => { const { url_path, sku, slug, type_id } = product return dispatch('url/registerMapping', { url: localizedDispatcherRoute(url_path, storeCode), routeData: { params: { parentSku: product.sku, slug }, - 'name': localizedDispatcherRouteName(type_id + '-product', storeCode) + 'name': localizedDispatcherRouteName(type_id + '-product', storeCode, appendStoreCode) } }, { root: true }) })) diff --git a/core/modules/catalog/store/category/actions.ts b/core/modules/catalog/store/category/actions.ts index a98f491cd6..9ac14abc9f 100644 --- a/core/modules/catalog/store/category/actions.ts +++ b/core/modules/catalog/store/category/actions.ts @@ -63,7 +63,7 @@ const actions: ActionTree = { return list }, async registerCategoryMapping ({ dispatch }, { categories }) { - const storeCode = currentStoreView().storeCode + const { storeCode, appendStoreCode } = currentStoreView() for (let category of categories) { if (category.url_path) { await dispatch('url/registerMapping', { @@ -72,7 +72,7 @@ const actions: ActionTree = { params: { 'slug': category.slug }, - 'name': localizedDispatcherRouteName('category', storeCode) + 'name': localizedDispatcherRouteName('category', storeCode, appendStoreCode) } }, { root: true }) } diff --git a/core/modules/catalog/store/product/actions.ts b/core/modules/catalog/store/product/actions.ts index 46e9b99590..49fd45011d 100644 --- a/core/modules/catalog/store/product/actions.ts +++ b/core/modules/catalog/store/product/actions.ts @@ -296,7 +296,7 @@ const actions: ActionTree = { return searchResult }, preConfigureAssociated (context, { searchResult, prefetchGroupProducts }) { - const storeCode = currentStoreView().storeCode + const { storeCode, appendStoreCode } = currentStoreView() for (let product of searchResult.items) { if (product.url_path) { const { parentSku, slug } = product @@ -305,7 +305,7 @@ const actions: ActionTree = { url: localizedDispatcherRoute(product.url_path, storeCode), routeData: { params: { parentSku, slug }, - 'name': localizedDispatcherRouteName(product.type_id + '-product', storeCode) + 'name': localizedDispatcherRouteName(product.type_id + '-product', storeCode, appendStoreCode) } }, { root: true }) } diff --git a/core/modules/url/store/actions.ts b/core/modules/url/store/actions.ts index 66568ccd9f..cb59ae9ca5 100644 --- a/core/modules/url/store/actions.ts +++ b/core/modules/url/store/actions.ts @@ -66,7 +66,7 @@ export const actions: ActionTree = { * This method could be overriden in custom module to provide custom URL mapping logic */ async mappingFallback ({ dispatch }, { url, params }: { url: string, params: any}) { - const storeCode = currentStoreView().storeCode + const { storeCode, appendStoreCode } = currentStoreView() const productQuery = new SearchQuery() url = (removeStoreCodeFromRoute(url.startsWith('/') ? url.slice(1) : url) as string) productQuery.applyFilter({key: 'url_path', value: {'eq': url}}) // Tees category @@ -74,7 +74,7 @@ export const actions: ActionTree = { if (products && products.items && products.items.length) { const product = products.items[0] return { - name: localizedDispatcherRouteName(product.type_id + '-product', storeCode), + name: localizedDispatcherRouteName(product.type_id + '-product', storeCode, appendStoreCode), params: { slug: product.slug, parentSku: product.sku, @@ -85,7 +85,7 @@ export const actions: ActionTree = { const category = await dispatch('category/single', { key: 'url_path', value: url }, { root: true }) if (category !== null) { return { - name: localizedDispatcherRouteName('category', storeCode), + name: localizedDispatcherRouteName('category', storeCode, appendStoreCode), params: { slug: category.slug } From a57d00bc6f8d1c45072c72d0f914fa72e5179b5b Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:50:29 +0200 Subject: [PATCH 17/99] Updated CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c64949d845..d4da8db453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.11.0-rc.2] - unreleased + +### Fixed + + - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) + ## [1.11.0-rc.1] - 2019.10.03 ### Added From 6f9d6cb98468cbfbbf1487a4f9d245ce02301588 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:53:39 +0200 Subject: [PATCH 18/99] removed debugger --- core/lib/multistore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/multistore.ts b/core/lib/multistore.ts index 22ef790291..249b45ee51 100644 --- a/core/lib/multistore.ts +++ b/core/lib/multistore.ts @@ -173,7 +173,6 @@ export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig } export function setupMultistoreRoutes (config, router: VueRouter, routes: RouteConfig[], priority: number = 0): void { - debugger const allRoutes: RouteConfig[] = [] const { storeCode, appendStoreCode } = currentStoreView() if (storeCode && appendStoreCode) { From b8ff716f6167b5799ec6734345770d8e2b377e75 Mon Sep 17 00:00:00 2001 From: patzick Date: Thu, 3 Oct 2019 11:01:52 +0200 Subject: [PATCH 19/99] update versioning --- core/i18n/package.json | 2 +- core/package.json | 2 +- docs/package.json | 2 +- package.json | 2 +- packages/cli/boilerplates/module/package.json | 4 ++-- src/themes/default-amp/package.json | 2 +- src/themes/default/package.json | 2 +- test/unit/package.json | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/i18n/package.json b/core/i18n/package.json index 64cba958ec..7b3313dc8e 100644 --- a/core/i18n/package.json +++ b/core/i18n/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/i18n", - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "description": "Vue Storefront i18n", "license": "MIT", "main": "index.ts", diff --git a/core/package.json b/core/package.json index dc7cea68f3..53d75e2c2a 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/core", - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "description": "Vue Storefront Core", "license": "MIT", "main": "app.js", diff --git a/docs/package.json b/docs/package.json index 7046b21434..0612ce0bfb 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,7 +1,7 @@ { "name": "@vue-storefront/docs", "private": true, - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "scripts": { "docs:dev": "vuepress dev", "docs:build": "vuepress build", diff --git a/package.json b/package.json index a681cade98..7421865ff4 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-storefront", - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "description": "A Vue.js, PWA eCommerce frontend", "private": true, "engines": { diff --git a/packages/cli/boilerplates/module/package.json b/packages/cli/boilerplates/module/package.json index 0506626c4f..77b385d0c2 100644 --- a/packages/cli/boilerplates/module/package.json +++ b/packages/cli/boilerplates/module/package.json @@ -12,13 +12,13 @@ "license": "MIT", "dependencies": {}, "devDependencies": { - "@vue-storefront/core": "^1.11.0-rc.1", + "@vue-storefront/core": "^1.11.0-rc.2", "ts-loader": "^6.0.4", "typescript": "^3.5.2", "webpack": "^4.35.2", "webpack-cli": "^3.3.5" }, "peerDependencies": { - "@vue-storefront/core": "^1.11.0-rc.1" + "@vue-storefront/core": "^1.11.0-rc.2" } } diff --git a/src/themes/default-amp/package.json b/src/themes/default-amp/package.json index f96a658fa8..53248b805c 100755 --- a/src/themes/default-amp/package.json +++ b/src/themes/default-amp/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default-amp", - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "description": "Default AMP theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/src/themes/default/package.json b/src/themes/default/package.json index 612803d26e..73ef55c8ca 100644 --- a/src/themes/default/package.json +++ b/src/themes/default/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default", - "version": "1.11.0-rc.1", + "version": "1.11.0-rc.2", "description": "Default theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/test/unit/package.json b/test/unit/package.json index cf5fa8c359..3df062b2ab 100644 --- a/test/unit/package.json +++ b/test/unit/package.json @@ -1,5 +1,5 @@ { "name": "@vue-storefront/unit-tests", "private": true, - "version": "1.11.0-rc.1" + "version": "1.11.0-rc.2" } From 6bc5007d494697d76fe36d355c41a711dfa88339 Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Sun, 6 Oct 2019 13:23:40 +0200 Subject: [PATCH 20/99] es7 support --- CHANGELOG.md | 6 +++++- core/i18n/package.json | 2 +- core/modules/catalog-next/store/category/actions.ts | 3 ++- core/modules/catalog-next/store/category/getters.ts | 7 ++++++- core/package.json | 2 +- docs/package.json | 2 +- package.json | 2 +- packages/cli/boilerplates/module/package.json | 4 ++-- src/themes/default-amp/package.json | 2 +- src/themes/default/package.json | 2 +- test/unit/package.json | 2 +- 11 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4da8db453..b8e6a15e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) +- Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) + +### Added + +- Added support for ES7 ## [1.11.0-rc.1] - 2019.10.03 diff --git a/core/i18n/package.json b/core/i18n/package.json index 7b3313dc8e..64cba958ec 100644 --- a/core/i18n/package.json +++ b/core/i18n/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/i18n", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Vue Storefront i18n", "license": "MIT", "main": "index.ts", diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index 5a1a9a5f8e..ec53f86148 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -47,7 +47,8 @@ const actions: ActionTree = { }, async loadMoreCategoryProducts ({ commit, getters, rootState, dispatch }) { const { perPage, start, total } = getters.getCategorySearchProductsStats - if (start >= total || total < perPage) return + const totalValue = typeof total === 'object' ? total.value : total + if (start >= totalValue || totalValue < perPage) return const searchQuery = getters.getCurrentSearchQuery let filterQr = buildFilterProductsQuery(getters.getCurrentCategory, searchQuery.filters) diff --git a/core/modules/catalog-next/store/category/getters.ts b/core/modules/catalog-next/store/category/getters.ts index 6f20defe19..dd54b83f2b 100644 --- a/core/modules/catalog-next/store/category/getters.ts +++ b/core/modules/catalog-next/store/category/getters.ts @@ -118,7 +118,12 @@ const getters: GetterTree = { return parseCategoryPath(resultCategoryList) }, getCategorySearchProductsStats: state => state.searchProductsStats || {}, - getCategoryProductsTotal: (state, getters) => getters.getCategorySearchProductsStats.total || 0 + getCategoryProductsTotal: (state, getters) => { + const { total } = getters.getCategorySearchProductsStats + const totalValue = typeof total === 'object' ? total.value : total + + return totalValue || 0 + } } export default getters diff --git a/core/package.json b/core/package.json index 53d75e2c2a..dc7cea68f3 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/core", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Vue Storefront Core", "license": "MIT", "main": "app.js", diff --git a/docs/package.json b/docs/package.json index 0612ce0bfb..7046b21434 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,7 +1,7 @@ { "name": "@vue-storefront/docs", "private": true, - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "scripts": { "docs:dev": "vuepress dev", "docs:build": "vuepress build", diff --git a/package.json b/package.json index 7421865ff4..a681cade98 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-storefront", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "A Vue.js, PWA eCommerce frontend", "private": true, "engines": { diff --git a/packages/cli/boilerplates/module/package.json b/packages/cli/boilerplates/module/package.json index 77b385d0c2..0506626c4f 100644 --- a/packages/cli/boilerplates/module/package.json +++ b/packages/cli/boilerplates/module/package.json @@ -12,13 +12,13 @@ "license": "MIT", "dependencies": {}, "devDependencies": { - "@vue-storefront/core": "^1.11.0-rc.2", + "@vue-storefront/core": "^1.11.0-rc.1", "ts-loader": "^6.0.4", "typescript": "^3.5.2", "webpack": "^4.35.2", "webpack-cli": "^3.3.5" }, "peerDependencies": { - "@vue-storefront/core": "^1.11.0-rc.2" + "@vue-storefront/core": "^1.11.0-rc.1" } } diff --git a/src/themes/default-amp/package.json b/src/themes/default-amp/package.json index 53248b805c..f96a658fa8 100755 --- a/src/themes/default-amp/package.json +++ b/src/themes/default-amp/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default-amp", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Default AMP theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/src/themes/default/package.json b/src/themes/default/package.json index 73ef55c8ca..612803d26e 100644 --- a/src/themes/default/package.json +++ b/src/themes/default/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Default theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/test/unit/package.json b/test/unit/package.json index 3df062b2ab..cf5fa8c359 100644 --- a/test/unit/package.json +++ b/test/unit/package.json @@ -1,5 +1,5 @@ { "name": "@vue-storefront/unit-tests", "private": true, - "version": "1.11.0-rc.2" + "version": "1.11.0-rc.1" } From 4b4a40b14f8ede77a030d199d452a6b1b33460d8 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 8 Oct 2019 14:34:08 +0200 Subject: [PATCH 21/99] Fix: bundle product with only one option --- .../catalog/components/ProductBundleOption.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/modules/catalog/components/ProductBundleOption.ts b/core/modules/catalog/components/ProductBundleOption.ts index bd770652bc..2abea7733f 100644 --- a/core/modules/catalog/components/ProductBundleOption.ts +++ b/core/modules/catalog/components/ProductBundleOption.ts @@ -29,7 +29,10 @@ export const ProductBundleOption = { return `bundleOptionQty_${this.option.option_id}` }, value () { - return this.option.product_links.find(product => product.id === this.productOptionId) + if (Array.isArray(this.option.product_links)) { + return this.option.product_links.find(product => product.id === this.productOptionId) + } + return this.option.product_links }, errorMessage () { return this.errorMessages ? this.errorMessages[this.quantityName] : '' @@ -57,7 +60,12 @@ export const ProductBundleOption = { methods: { setDefaultValues () { if (this.option.product_links) { - const defaultOption = this.option.product_links.find(pl => { return pl.is_default }) + let defaultOption + if (Array.isArray(this.option.product_links)) { + defaultOption = this.option.product_links.find(pl => { return pl.is_default }) + } else { + defaultOption = this.option.product_links + } this.productOptionId = defaultOption ? defaultOption.id : this.option.product_links[0].id this.quantity = defaultOption ? defaultOption.qty : 1 } From 9a61e6f8502276280bc81ce2de679de7812a6d22 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 8 Oct 2019 14:35:11 +0200 Subject: [PATCH 22/99] Fix: possible problem with event that is not working because of casing for bundle products --- core/modules/catalog/components/ProductBundleOption.ts | 2 +- src/themes/default/components/core/ProductBundleOptions.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/catalog/components/ProductBundleOption.ts b/core/modules/catalog/components/ProductBundleOption.ts index 2abea7733f..9f9aba4c86 100644 --- a/core/modules/catalog/components/ProductBundleOption.ts +++ b/core/modules/catalog/components/ProductBundleOption.ts @@ -71,7 +71,7 @@ export const ProductBundleOption = { } }, bundleOptionChanged () { - this.$emit('optionChanged', { + this.$emit('option-changed', { option: this.option, fieldName: this.productBundleOption, qty: this.quantity, diff --git a/src/themes/default/components/core/ProductBundleOptions.vue b/src/themes/default/components/core/ProductBundleOptions.vue index 3d12c8a8ea..d36f910e3f 100644 --- a/src/themes/default/components/core/ProductBundleOptions.vue +++ b/src/themes/default/components/core/ProductBundleOptions.vue @@ -1,7 +1,7 @@ From 4992a7ee247bb5f73456ccab6da56e0283eb801f Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 8 Oct 2019 14:37:46 +0200 Subject: [PATCH 23/99] Fix: possible problem when two products have no server_item_id and item_id This is a problem because then they are equal but should not so now we check if one is undefined and then return false in that case. --- core/modules/cart/helpers/productsEquals.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/modules/cart/helpers/productsEquals.ts b/core/modules/cart/helpers/productsEquals.ts index e354ee4765..0a1698138f 100644 --- a/core/modules/cart/helpers/productsEquals.ts +++ b/core/modules/cart/helpers/productsEquals.ts @@ -15,8 +15,12 @@ const getProductType = (product: CartItem): string => const getServerItemId = (product: CartItem): string | number => product.server_item_id || product.item_id -const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean => - getServerItemId(product1) === getServerItemId(product2) +const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean => { + if (getServerItemId(product1) === undefined || getServerItemId(product2) === undefined) { + return false + } + return getServerItemId(product1) === getServerItemId(product2) +} const isChecksumEquals = (product1: CartItem, product2: CartItem): boolean => getChecksum(product1) === getChecksum(product2) From f659bdfd004e04d44c62a953cf3546e43f0e7366 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 8 Oct 2019 14:50:33 +0200 Subject: [PATCH 24/99] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4da8db453..02dbc8a50d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) + - Fixed three problems you can run into when you have bundle products - @resubaka (#3692) ## [1.11.0-rc.1] - 2019.10.03 From 1f997e6c65db1c60a0eb44d29971c1a87c0337f8 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 9 Oct 2019 06:10:16 +0200 Subject: [PATCH 25/99] Cosmetic changes in ProductBundleOption.ts and productsEquals.ts --- core/modules/cart/helpers/productsEquals.ts | 9 ++++---- .../catalog/components/ProductBundleOption.ts | 21 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/modules/cart/helpers/productsEquals.ts b/core/modules/cart/helpers/productsEquals.ts index 0a1698138f..92e8870fc9 100644 --- a/core/modules/cart/helpers/productsEquals.ts +++ b/core/modules/cart/helpers/productsEquals.ts @@ -16,10 +16,11 @@ const getServerItemId = (product: CartItem): string | number => product.server_item_id || product.item_id const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean => { - if (getServerItemId(product1) === undefined || getServerItemId(product2) === undefined) { - return false - } - return getServerItemId(product1) === getServerItemId(product2) + const product1ItemId = getServerItemId(product1) + const product2ItemId = getServerItemId(product2) + const areItemIdsDefined = product1ItemId !== undefined && product2ItemId !== undefined + + return areItemIdsDefined && product1ItemId === product2ItemId } const isChecksumEquals = (product1: CartItem, product2: CartItem): boolean => diff --git a/core/modules/catalog/components/ProductBundleOption.ts b/core/modules/catalog/components/ProductBundleOption.ts index 9f9aba4c86..8732ffea61 100644 --- a/core/modules/catalog/components/ProductBundleOption.ts +++ b/core/modules/catalog/components/ProductBundleOption.ts @@ -29,10 +29,11 @@ export const ProductBundleOption = { return `bundleOptionQty_${this.option.option_id}` }, value () { - if (Array.isArray(this.option.product_links)) { - return this.option.product_links.find(product => product.id === this.productOptionId) + const { product_links } = this.option + if (Array.isArray(product_links)) { + return product_links.find(product => product.id === this.productOptionId) } - return this.option.product_links + return product_links }, errorMessage () { return this.errorMessages ? this.errorMessages[this.quantityName] : '' @@ -59,14 +60,12 @@ export const ProductBundleOption = { }, methods: { setDefaultValues () { - if (this.option.product_links) { - let defaultOption - if (Array.isArray(this.option.product_links)) { - defaultOption = this.option.product_links.find(pl => { return pl.is_default }) - } else { - defaultOption = this.option.product_links - } - this.productOptionId = defaultOption ? defaultOption.id : this.option.product_links[0].id + const { product_links } = this.option + + if (product_links) { + const defaultOption = Array.isArray(product_links) ? product_links.find(pl => { return pl.is_default }) : product_links + + this.productOptionId = defaultOption ? defaultOption.id : product_links[0].id this.quantity = defaultOption ? defaultOption.qty : 1 } }, From da8616bea8f02d5b897f9abeb15932f8f6e1155e Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 9 Oct 2019 10:29:39 +0200 Subject: [PATCH 26/99] Fixed line length of short if so it is not over 120 chars --- core/modules/catalog/components/ProductBundleOption.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/modules/catalog/components/ProductBundleOption.ts b/core/modules/catalog/components/ProductBundleOption.ts index 8732ffea61..a030effb5f 100644 --- a/core/modules/catalog/components/ProductBundleOption.ts +++ b/core/modules/catalog/components/ProductBundleOption.ts @@ -63,7 +63,9 @@ export const ProductBundleOption = { const { product_links } = this.option if (product_links) { - const defaultOption = Array.isArray(product_links) ? product_links.find(pl => { return pl.is_default }) : product_links + const defaultOption = Array.isArray(product_links) + ? product_links.find(pl => { return pl.is_default }) + : product_links this.productOptionId = defaultOption ? defaultOption.id : product_links[0].id this.quantity = defaultOption ? defaultOption.qty : 1 From 25a13c4beb34bc2e01264763a07302fd467e458b Mon Sep 17 00:00:00 2001 From: tkostuch Date: Wed, 9 Oct 2019 09:49:48 +0200 Subject: [PATCH 27/99] add checkbox custom opton type --- .../components/ProductCustomOptions.ts | 74 ++++++++++++++----- .../components/core/ProductCustomOptions.vue | 4 +- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/core/modules/catalog/components/ProductCustomOptions.ts b/core/modules/catalog/components/ProductCustomOptions.ts index 34f80a5da6..09010443b7 100644 --- a/core/modules/catalog/components/ProductCustomOptions.ts +++ b/core/modules/catalog/components/ProductCustomOptions.ts @@ -6,9 +6,15 @@ import { Logger } from '@vue-storefront/core/lib/logger' function _defaultOptionValue (co) { switch (co.type) { - case 'radio': return co.values && co.values.length ? co.values[0].option_type_id : 0 - case 'checkbox': return false - default: return '' + case 'radio': { + return co.values && co.values.length ? co.values[0].option_type_id : 0 + } + case 'checkbox': { + return [] + } + default: { + return '' + } } } @@ -16,6 +22,29 @@ function _fieldName (co) { return 'customOption_' + co.option_id } +function _getSelectedOptionValue (optionType, optionValues = [], inputValue) { + switch (optionType) { + case 'field': { + return inputValue + } + case 'radio': + case 'select': + case 'drop_down': { + const selectedValue = optionValues.find((value) => value.option_type_id === inputValue) || {} + + return selectedValue.option_type_id || '' + } + case 'checkbox': { + return optionValues.filter((value) => (inputValue || []).includes(value.option_type_id)) + .map((value) => value.option_type_id) + .join(',') + } + default: { + return '' + } + } +} + export const ProductCustomOptions = { name: 'ProductCustomOptions', props: { @@ -26,21 +55,34 @@ export const ProductCustomOptions = { }, data () { return { - inputValues: { - }, - selectedOptions: { - }, + inputValues: {}, validation: { rules: {}, results: {} } } }, + computed: { + selectedOptions () { + const customOptions = this.product.custom_options + if (!customOptions) { + return {} + } + + return customOptions.reduce((selectedOptions, option) => { + const fieldName = _fieldName(option) + selectedOptions[fieldName] = _getSelectedOptionValue(option.type, option.values, this.inputValues[fieldName]) + return selectedOptions + }, {}) + } + }, created () { rootStore.dispatch('product/addCustomOptionValidator', { validationRule: 'required', // You may add your own custom fields validators elsewhere in the theme validatorFunction: (value) => { - return { error: (value === null || value === '') || (value === false) || (value === 0), message: i18n.t('Field is required.') } + const error = Array.isArray(value) ? !value.length : !value + const message = i18n.t('Field is required.') + return { error, message } } }) this.setupInputFields() @@ -50,22 +92,20 @@ export const ProductCustomOptions = { setCustomOptionValue: types.PRODUCT_SET_CUSTOM_OPTION // map `this.add()` to `this.$store.commit('increment')` }), setupInputFields () { - for (let co of this.product.custom_options) { - const fieldName = _fieldName(co) - this['inputValues'][fieldName] = _defaultOptionValue(co) - if (co.is_require) { // validation rules are very basic + for (const customOption of this.product.custom_options) { + const fieldName = _fieldName(customOption) + this['inputValues'][fieldName] = _defaultOptionValue(customOption) + if (customOption.is_require) { // validation rules are very basic this.validation.rules[fieldName] = 'required' // TODO: add custom validators for the custom options } - this.optionChanged(co, co.values && co.values.length > 0 ? co.values[0] : null) + this.optionChanged(customOption) } }, - optionChanged (option, opval = null) { + optionChanged (option) { const fieldName = _fieldName(option) - const value = opval === null ? this.inputValues[fieldName] : opval.option_type_id this.validateField(option) - this.setCustomOptionValue({ optionId: option.option_id, optionValue: value }) + this.setCustomOptionValue({ optionId: option.option_id, optionValue: this.selectedOptions[fieldName] }) this.$store.dispatch('product/setCustomOptions', { product: this.product, customOptions: this.$store.state.product.current_custom_options }) // TODO: move it to "AddToCart" - this.selectedOptions[fieldName] = (opval === null ? value : opval) this.$bus.$emit('product-after-customoptions', { product: this.product, option: option, optionValues: this.selectedOptions }) }, validateField (option) { diff --git a/src/themes/default/components/core/ProductCustomOptions.vue b/src/themes/default/components/core/ProductCustomOptions.vue index 5bf74143f7..7a59caeb31 100644 --- a/src/themes/default/components/core/ProductCustomOptions.vue +++ b/src/themes/default/components/core/ProductCustomOptions.vue @@ -18,7 +18,7 @@ >
Date: Wed, 9 Oct 2019 09:53:21 +0200 Subject: [PATCH 28/99] update changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fdf42c160..c31132bc86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - - Fixed deprecated getter in cmsBlock store - @resubaka (#3683) - - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) +- Fixed deprecated getter in cmsBlock store - @resubaka (#3683) +- Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) +- Fixed handling checkbox custom option (#2781) ## [1.11.0-rc.1] - 2019.10.03 From 95c3bbdc1ce4b4e6bf23ce78a9a6eb4d86bbeb9b Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 9 Oct 2019 11:00:25 +0200 Subject: [PATCH 29/99] Removed un needed brackets from find callback function --- core/modules/catalog/components/ProductBundleOption.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/catalog/components/ProductBundleOption.ts b/core/modules/catalog/components/ProductBundleOption.ts index a030effb5f..d902cbead3 100644 --- a/core/modules/catalog/components/ProductBundleOption.ts +++ b/core/modules/catalog/components/ProductBundleOption.ts @@ -64,7 +64,7 @@ export const ProductBundleOption = { if (product_links) { const defaultOption = Array.isArray(product_links) - ? product_links.find(pl => { return pl.is_default }) + ? product_links.find(pl => pl.is_default) : product_links this.productOptionId = defaultOption ? defaultOption.id : product_links[0].id From 16327c06756cd9384787ba4af20ab60d99d73f68 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 8 Oct 2019 15:02:45 +0200 Subject: [PATCH 30/99] reset nested menu --- .../components/core/blocks/SidebarMenu/SubCategory.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/themes/default/components/core/blocks/SidebarMenu/SubCategory.vue b/src/themes/default/components/core/blocks/SidebarMenu/SubCategory.vue index cddee21c82..9751967265 100644 --- a/src/themes/default/components/core/blocks/SidebarMenu/SubCategory.vue +++ b/src/themes/default/components/core/blocks/SidebarMenu/SubCategory.vue @@ -143,9 +143,10 @@ export default { } }, methods: { - logout () { - this.$store.dispatch('user/logout', {}) + async logout () { + await this.$store.dispatch('user/logout', {}) this.$router.push(this.localizedRoute('/')) + this.$store.commit('ui/setSubmenu', { depth: false }) }, notify (title) { if (title === 'My loyalty card' || title === 'My product reviews') { From 4da78a10f1f466bfdcfc929b9a9209ad9efa05d8 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 8 Oct 2019 15:04:56 +0200 Subject: [PATCH 31/99] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fdf42c160..7142a6c990 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.11.0-rc.2] - unreleased ### Fixed +- Reset nested menu after logout - @gibkigonzo (#3680) - Fixed deprecated getter in cmsBlock store - @resubaka (#3683) - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) From 4176e2499525b9d8bd5d397f8ffeec41b11cd947 Mon Sep 17 00:00:00 2001 From: kskibinski Date: Thu, 10 Oct 2019 15:00:37 +0200 Subject: [PATCH 32/99] Add dependencies to Dockerfile to fix VSF build fails --- CHANGELOG.md | 3 ++- docker/vue-storefront/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7142a6c990..5a6ef5697a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.11.0-rc.2] - unreleased ### Fixed -- Reset nested menu after logout - @gibkigonzo (#3680) + - Fixed VSF build fails for some people due to lack of dependencies in the container - @krskibin (#3699) + - Reset nested menu after logout - @gibkigonzo (#3680) - Fixed deprecated getter in cmsBlock store - @resubaka (#3683) - Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) diff --git a/docker/vue-storefront/Dockerfile b/docker/vue-storefront/Dockerfile index f0aa2896bd..5fb728d9b0 100644 --- a/docker/vue-storefront/Dockerfile +++ b/docker/vue-storefront/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /var/www COPY package.json ./ COPY yarn.lock ./ -RUN apk add --no-cache --virtual .build-deps ca-certificates wget git \ +RUN apk add --no-cache --virtual .build-deps ca-certificates wget git python make g++ \ && yarn install --no-cache \ && apk del .build-deps From 75dc54c2932deb9733bddf31212b18649c659716 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Thu, 10 Oct 2019 17:24:52 +0200 Subject: [PATCH 33/99] add customOption helper --- .../components/ProductCustomOptions.ts | 54 +++---------------- core/modules/catalog/helpers/customOption.ts | 40 ++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 core/modules/catalog/helpers/customOption.ts diff --git a/core/modules/catalog/components/ProductCustomOptions.ts b/core/modules/catalog/components/ProductCustomOptions.ts index 09010443b7..821eecde03 100644 --- a/core/modules/catalog/components/ProductCustomOptions.ts +++ b/core/modules/catalog/components/ProductCustomOptions.ts @@ -1,50 +1,10 @@ +import { customOptionFieldName, selectedCustomOptionValue, defaultCustomOptionValue } from '@vue-storefront/core/modules/catalog/helpers/customOption'; import { mapMutations } from 'vuex' import * as types from '../store/product/mutation-types' import rootStore from '@vue-storefront/core/store' import i18n from '@vue-storefront/i18n' import { Logger } from '@vue-storefront/core/lib/logger' -function _defaultOptionValue (co) { - switch (co.type) { - case 'radio': { - return co.values && co.values.length ? co.values[0].option_type_id : 0 - } - case 'checkbox': { - return [] - } - default: { - return '' - } - } -} - -function _fieldName (co) { - return 'customOption_' + co.option_id -} - -function _getSelectedOptionValue (optionType, optionValues = [], inputValue) { - switch (optionType) { - case 'field': { - return inputValue - } - case 'radio': - case 'select': - case 'drop_down': { - const selectedValue = optionValues.find((value) => value.option_type_id === inputValue) || {} - - return selectedValue.option_type_id || '' - } - case 'checkbox': { - return optionValues.filter((value) => (inputValue || []).includes(value.option_type_id)) - .map((value) => value.option_type_id) - .join(',') - } - default: { - return '' - } - } -} - export const ProductCustomOptions = { name: 'ProductCustomOptions', props: { @@ -70,8 +30,8 @@ export const ProductCustomOptions = { } return customOptions.reduce((selectedOptions, option) => { - const fieldName = _fieldName(option) - selectedOptions[fieldName] = _getSelectedOptionValue(option.type, option.values, this.inputValues[fieldName]) + const fieldName = customOptionFieldName(option) + selectedOptions[fieldName] = selectedCustomOptionValue(option.type, option.values, this.inputValues[fieldName]) return selectedOptions }, {}) } @@ -93,8 +53,8 @@ export const ProductCustomOptions = { }), setupInputFields () { for (const customOption of this.product.custom_options) { - const fieldName = _fieldName(customOption) - this['inputValues'][fieldName] = _defaultOptionValue(customOption) + const fieldName = customOptionFieldName(customOption) + this['inputValues'][fieldName] = defaultCustomOptionValue(customOption) if (customOption.is_require) { // validation rules are very basic this.validation.rules[fieldName] = 'required' // TODO: add custom validators for the custom options } @@ -102,14 +62,14 @@ export const ProductCustomOptions = { } }, optionChanged (option) { - const fieldName = _fieldName(option) + const fieldName = customOptionFieldName(option) this.validateField(option) this.setCustomOptionValue({ optionId: option.option_id, optionValue: this.selectedOptions[fieldName] }) this.$store.dispatch('product/setCustomOptions', { product: this.product, customOptions: this.$store.state.product.current_custom_options }) // TODO: move it to "AddToCart" this.$bus.$emit('product-after-customoptions', { product: this.product, option: option, optionValues: this.selectedOptions }) }, validateField (option) { - const fieldName = _fieldName(option) + const fieldName = customOptionFieldName(option) const validationRule = this.validation.rules[fieldName] this.product.errors.custom_options = null if (validationRule) { diff --git a/core/modules/catalog/helpers/customOption.ts b/core/modules/catalog/helpers/customOption.ts new file mode 100644 index 0000000000..1efa0cba1d --- /dev/null +++ b/core/modules/catalog/helpers/customOption.ts @@ -0,0 +1,40 @@ +export const defaultCustomOptionValue = (co) => { + switch (co.type) { + case 'radio': { + return co.values && co.values.length ? co.values[0].option_type_id : 0 + } + case 'checkbox': { + return [] + } + default: { + return '' + } + } +} + +export const customOptionFieldName = (co) => { + return 'customOption_' + co.option_id +} + +export const selectedCustomOptionValue = (optionType, optionValues = [], inputValue) => { + switch (optionType) { + case 'field': { + return inputValue + } + case 'radio': + case 'select': + case 'drop_down': { + const selectedValue = optionValues.find((value) => value.option_type_id === inputValue) || {} + + return selectedValue.option_type_id || '' + } + case 'checkbox': { + return optionValues.filter((value) => (inputValue || []).includes(value.option_type_id)) + .map((value) => value.option_type_id) + .join(',') + } + default: { + return '' + } + } +} From 510b48283ff70d4932e1d32ee93003047fa799eb Mon Sep 17 00:00:00 2001 From: tkostuch Date: Thu, 10 Oct 2019 18:24:25 +0200 Subject: [PATCH 34/99] add types --- core/modules/catalog/helpers/customOption.ts | 24 ++++++++++++-------- core/modules/catalog/types/CustomOption.ts | 24 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 core/modules/catalog/types/CustomOption.ts diff --git a/core/modules/catalog/helpers/customOption.ts b/core/modules/catalog/helpers/customOption.ts index 1efa0cba1d..dbd31387fc 100644 --- a/core/modules/catalog/helpers/customOption.ts +++ b/core/modules/catalog/helpers/customOption.ts @@ -1,7 +1,9 @@ -export const defaultCustomOptionValue = (co) => { - switch (co.type) { +import { CustomOption, OptionValue, InputValue } from './../types/CustomOption'; + +export const defaultCustomOptionValue = (customOption: CustomOption): InputValue => { + switch (customOption.type) { case 'radio': { - return co.values && co.values.length ? co.values[0].option_type_id : 0 + return customOption.values && customOption.values.length ? customOption.values[0].option_type_id : 0 } case 'checkbox': { return [] @@ -12,24 +14,26 @@ export const defaultCustomOptionValue = (co) => { } } -export const customOptionFieldName = (co) => { - return 'customOption_' + co.option_id +export const customOptionFieldName = (customOption: CustomOption): string => { + return 'customOption_' + customOption.option_id } -export const selectedCustomOptionValue = (optionType, optionValues = [], inputValue) => { +export const selectedCustomOptionValue = (optionType: string, optionValues: OptionValue[] = [], inputValue: InputValue): string => { switch (optionType) { case 'field': { - return inputValue + return inputValue as string } case 'radio': case 'select': case 'drop_down': { - const selectedValue = optionValues.find((value) => value.option_type_id === inputValue) || {} + const selectedValue = optionValues.find((value) => value.option_type_id === inputValue as number) - return selectedValue.option_type_id || '' + return String(selectedValue && selectedValue.option_type_id) || '' } case 'checkbox': { - return optionValues.filter((value) => (inputValue || []).includes(value.option_type_id)) + const checkboxOptionValues = inputValue as number[] || [] + + return optionValues.filter((value) => checkboxOptionValues.includes(value.option_type_id)) .map((value) => value.option_type_id) .join(',') } diff --git a/core/modules/catalog/types/CustomOption.ts b/core/modules/catalog/types/CustomOption.ts new file mode 100644 index 0000000000..d9c6c9a399 --- /dev/null +++ b/core/modules/catalog/types/CustomOption.ts @@ -0,0 +1,24 @@ +export interface CustomOption { + image_size_x: number, + image_size_y: number, + is_require: boolean, + max_characters: number, + option_id: number, + product_sku: string, + sort_order: number, + title: string, + type: string, + price?: number, + price_type?: string, + values?: OptionValue[] +} + +export interface OptionValue { + option_type_id: number, + price: number, + price_type: string, + sort_order: number, + title: string +} + +export type InputValue = string | number | number[] From 177663f91d4952d277b59164ec080af2966ad9a8 Mon Sep 17 00:00:00 2001 From: kskibinski Date: Fri, 11 Oct 2019 11:42:26 +0200 Subject: [PATCH 35/99] Add unit tests for 'core/modules/mailer' --- .eslintrc.js | 1 + CHANGELOG.md | 3 ++ .../mailer/test/unit/sendEmail.spec.ts | 47 +++++++++++++++++++ package.json | 6 ++- test/unit/jest.conf.js | 2 +- test/unit/setupTestEnvironment.js | 1 - test/unit/setupTestEnvironment.ts | 6 +++ yarn.lock | 31 ++++++++++++ 8 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 core/modules/mailer/test/unit/sendEmail.spec.ts delete mode 100644 test/unit/setupTestEnvironment.js create mode 100644 test/unit/setupTestEnvironment.ts diff --git a/.eslintrc.js b/.eslintrc.js index 2d98134c4d..3697d18fb2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,7 @@ module.exports = { root: true, env: { browser: true, jest: true }, + globals: { fetchMock: true }, parser: 'vue-eslint-parser', parserOptions: { parser: '@typescript-eslint/parser', diff --git a/CHANGELOG.md b/CHANGELOG.md index 26c6f2bc5a..a4ead8809b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +### Added + +- Added unit tests for `core/modules/mailer` - @krskibin (#3710) ## [1.11.0-rc.1] - 2019.10.03 diff --git a/core/modules/mailer/test/unit/sendEmail.spec.ts b/core/modules/mailer/test/unit/sendEmail.spec.ts new file mode 100644 index 0000000000..a36001b3e8 --- /dev/null +++ b/core/modules/mailer/test/unit/sendEmail.spec.ts @@ -0,0 +1,47 @@ +import { mailerStore } from '../../store/index' +import config from 'config' + +jest.mock('@vue-storefront/i18n', () => ({ t: jest.fn(str => str) })); +jest.mock('@vue-storefront/core/lib/storage-manager', () => jest.fn()) +jest.mock('@vue-storefront/core/app', () => jest.fn()) +jest.mock('@vue-storefront/core/lib/multistore', () => jest.fn()) +jest.mock('@vue-storefront/core/store', () => ({ Module: jest.fn() })) +jest.mock('@vue-storefront/core/lib/logger', () => ({ + Logger: { + error: jest.fn(() => jest.fn()) + } +})) + +describe('Mailer store module', () => { + const letterMock = {} + const contextMock = {}; + const wrapper = (actions: any) => actions.sendEmail(contextMock, letterMock) + + beforeEach(() => { + jest.clearAllMocks(); + fetchMock.resetMocks() + }) + + it('should send email succesfully', async () => { + fetchMock.mockResponses( + [ JSON.stringify({ code: 200 }), { status: 200 } ], + [ JSON.stringify({ send: true }), { status: 200 } ] + ) + + const res = await wrapper(mailerStore.actions); + const resData = await res.json() + + expect(resData.send).toBe(true) + }) + + it('should thrown error when response code is wrong', async () => { + const wrongResponseCode = 201; + fetchMock.mockResponseOnce(JSON.stringify({ code: wrongResponseCode })) + + try { + const res = await wrapper(mailerStore.actions) + } catch (e) { + expect(e.message).toBe(`Error: ${wrongResponseCode}`) + } + }) +}) diff --git a/package.json b/package.json index 7421865ff4..9987f7098e 100755 --- a/package.json +++ b/package.json @@ -50,7 +50,10 @@ }, "lint-staged": { "*.{js,vue,ts}": "eslint", - "**/i18n/*.csv": ["node ./core/scripts/utils/sort-translations.js", "git add"] + "**/i18n/*.csv": [ + "node ./core/scripts/utils/sort-translations.js", + "git add" + ] }, "husky": { "hooks": { @@ -145,6 +148,7 @@ "inquirer": "^3.3.0", "is-windows": "^1.0.1", "jest": "^24.8.0", + "jest-fetch-mock": "^2.1.2", "jest-serializer-vue": "^2.0.2", "jsonfile": "^4.0.0", "lerna": "^3.14.1", diff --git a/test/unit/jest.conf.js b/test/unit/jest.conf.js index 6a11736922..dadde07caf 100644 --- a/test/unit/jest.conf.js +++ b/test/unit/jest.conf.js @@ -36,6 +36,6 @@ module.exports = { '/node_modules/(?!lodash-es/.*)' ], setupFiles: [ - '/test/unit/setupTestEnvironment.js' + '/test/unit/setupTestEnvironment.ts' ] } diff --git a/test/unit/setupTestEnvironment.js b/test/unit/setupTestEnvironment.js deleted file mode 100644 index 33b7c42cf4..0000000000 --- a/test/unit/setupTestEnvironment.js +++ /dev/null @@ -1 +0,0 @@ -import '@babel/polyfill' diff --git a/test/unit/setupTestEnvironment.ts b/test/unit/setupTestEnvironment.ts new file mode 100644 index 0000000000..a225c14563 --- /dev/null +++ b/test/unit/setupTestEnvironment.ts @@ -0,0 +1,6 @@ +import '@babel/polyfill' +import {GlobalWithFetchMock} from 'jest-fetch-mock'; + +const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock; +customGlobal.fetch = require('jest-fetch-mock'); +customGlobal.fetchMock = customGlobal.fetch; diff --git a/yarn.lock b/yarn.lock index 3de0ff47e4..0bac2b2700 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4943,6 +4943,14 @@ cross-env@^3.1.4: cross-spawn "^5.1.0" is-windows "^1.0.0" +cross-fetch@^2.2.2: + version "2.2.3" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.3.tgz#e8a0b3c54598136e037f8650f8e823ccdfac198e" + integrity sha512-PrWWNH3yL2NYIb/7WF/5vFG3DCQiXDOVf8k3ijatbrtnwNuhMWLC7YF7uqf53tbTFDzHIUD8oITw4Bxt8ST3Nw== + dependencies: + node-fetch "2.1.2" + whatwg-fetch "2.0.4" + cross-spawn@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982" @@ -8128,6 +8136,14 @@ jest-environment-node@^24.8.0: jest-mock "^24.8.0" jest-util "^24.8.0" +jest-fetch-mock@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-2.1.2.tgz#1260b347918e3931c4ec743ceaf60433da661bd0" + integrity sha512-tcSR4Lh2bWLe1+0w/IwvNxeDocMI/6yIA2bijZ0fyWxC4kQ18lckQ1n7Yd40NKuisGmcGBRFPandRXrW/ti/Bw== + dependencies: + cross-fetch "^2.2.2" + promise-polyfill "^7.1.1" + jest-get-type@^24.8.0: version "24.8.0" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-24.8.0.tgz#a7440de30b651f5a70ea3ed7ff073a32dfe646fc" @@ -9815,6 +9831,11 @@ node-fetch-npm@^2.0.2: json-parse-better-errors "^1.0.0" safe-buffer "^5.1.1" +node-fetch@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5" + integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U= + node-fetch@^1.0.1: version "1.7.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" @@ -11201,6 +11222,11 @@ promise-inflight@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" +promise-polyfill@^7.1.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-7.1.2.tgz#ab05301d8c28536301622d69227632269a70ca3b" + integrity sha512-FuEc12/eKqqoRYIGBrUptCBRhobL19PS2U31vMNTfyck1FxPyMfgsXyW4Mav85y/ZN1hop3hOwRlUDok23oYfQ== + promise-retry@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d" @@ -13990,6 +14016,11 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3: dependencies: iconv-lite "0.4.24" +whatwg-fetch@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f" + integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng== + whatwg-fetch@>=0.10.0: version "3.0.0" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb" From 860d7aa5b71e881f8b5598d7a49e8152af1ec388 Mon Sep 17 00:00:00 2001 From: Patryk Andrzejewski Date: Fri, 11 Oct 2019 23:23:43 +0200 Subject: [PATCH 36/99] Update CHANGELOG.md --- CHANGELOG.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 315ddbfb0d..6b12223ad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,20 @@ 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.11.0-rc.1] - UNRELEASED +## [1.11.0-rc.2] - unreleased + +### Fixed +- Fixed deprecated getter in cmsBlock store - @resubaka (#3683) +- Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685) +- Fixed three problems you can run into when you have bundle products - @resubaka (#3692) +- Reset nested menu after logout - @gibkigonzo (#3680) +- Fixed handling checkbox custom option - @gibkigonzo (#2781) +- Get payment methods with billing address data - @rain2o (#2878) + +### Added +- Added support for ES7 - @andrzejewsky (#3690) + +## [1.11.0-rc.1] - 2019.10.03 ### Added @@ -56,7 +69,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Route Manager Queue for adding routes efficiently and with an optional priority - @grimasod (#3540) - Added tests for cart module actions - @andrzejewsky (#3023) - Fixed a problem with type changes in the state when extending a store - @resubaka (#3618) -- Get payment methods with billing address data - @rain2o (#2878) - Fixed problem with bundle product where they have the same hash as other products - @resubaka (#3657) ### Fixed From 71806f6908dd45ac5f49ea37604bd96c3209ea1e Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Fri, 11 Oct 2019 23:39:54 +0200 Subject: [PATCH 37/99] resolve conflicts --- core/i18n/package.json | 2 +- core/package.json | 2 +- docs/package.json | 2 +- package.json | 2 +- packages/cli/boilerplates/module/package.json | 4 ++-- src/themes/default-amp/package.json | 2 +- src/themes/default/package.json | 2 +- test/unit/package.json | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/i18n/package.json b/core/i18n/package.json index 7b3313dc8e..64cba958ec 100644 --- a/core/i18n/package.json +++ b/core/i18n/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/i18n", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Vue Storefront i18n", "license": "MIT", "main": "index.ts", diff --git a/core/package.json b/core/package.json index 53d75e2c2a..dc7cea68f3 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/core", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Vue Storefront Core", "license": "MIT", "main": "app.js", diff --git a/docs/package.json b/docs/package.json index 0612ce0bfb..7046b21434 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,7 +1,7 @@ { "name": "@vue-storefront/docs", "private": true, - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "scripts": { "docs:dev": "vuepress dev", "docs:build": "vuepress build", diff --git a/package.json b/package.json index 9987f7098e..5b3ec19900 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-storefront", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "A Vue.js, PWA eCommerce frontend", "private": true, "engines": { diff --git a/packages/cli/boilerplates/module/package.json b/packages/cli/boilerplates/module/package.json index 77b385d0c2..0506626c4f 100644 --- a/packages/cli/boilerplates/module/package.json +++ b/packages/cli/boilerplates/module/package.json @@ -12,13 +12,13 @@ "license": "MIT", "dependencies": {}, "devDependencies": { - "@vue-storefront/core": "^1.11.0-rc.2", + "@vue-storefront/core": "^1.11.0-rc.1", "ts-loader": "^6.0.4", "typescript": "^3.5.2", "webpack": "^4.35.2", "webpack-cli": "^3.3.5" }, "peerDependencies": { - "@vue-storefront/core": "^1.11.0-rc.2" + "@vue-storefront/core": "^1.11.0-rc.1" } } diff --git a/src/themes/default-amp/package.json b/src/themes/default-amp/package.json index 53248b805c..f96a658fa8 100755 --- a/src/themes/default-amp/package.json +++ b/src/themes/default-amp/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default-amp", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Default AMP theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/src/themes/default/package.json b/src/themes/default/package.json index 73ef55c8ca..612803d26e 100644 --- a/src/themes/default/package.json +++ b/src/themes/default/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-default", - "version": "1.11.0-rc.2", + "version": "1.11.0-rc.1", "description": "Default theme for Vue Storefront", "main": "index.js", "scripts": { diff --git a/test/unit/package.json b/test/unit/package.json index 3df062b2ab..cf5fa8c359 100644 --- a/test/unit/package.json +++ b/test/unit/package.json @@ -1,5 +1,5 @@ { "name": "@vue-storefront/unit-tests", "private": true, - "version": "1.11.0-rc.2" + "version": "1.11.0-rc.1" } From 7843186287e1638bcdf2e726fc26ed23627def5f Mon Sep 17 00:00:00 2001 From: patzick Date: Thu, 3 Oct 2019 11:01:52 +0200 Subject: [PATCH 38/99] update versioning --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15aee575e1..a0eef5d9b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed three problems you can run into when you have bundle products - @resubaka (#3692) - Reset nested menu after logout - @gibkigonzo (#3680) - Fixed handling checkbox custom option - @gibkigonzo (#2781) +- Fixed typos in docs - @afozbek (#3709) ### Added - Added support for ES7 - @andrzejewsky (#3690) From 2fa6728b604d98843f1a2ac0f61fa16434a0d79a Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Sat, 12 Oct 2019 13:57:27 +0200 Subject: [PATCH 39/99] resolve conflicts --- CONTRIBUTING.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48784e9536..00130e0de7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,10 +35,8 @@ Here are some thoughts on how to use TypeScript features in Vue Storefront: [Typ ## Pull Request Checklist -Here's how to submit a pull request. **Pull request that don't meet these requirements will not be merged.** - -**ALWAYS** use the [Pull Request template](https://github.com/DivanteLtd/vue-storefront/blob/master/PULL_REQUEST_TEMPLATE.md) it's automatically added to each PR. -1. Fork the repository and clone it locally fro the 'develop' branch. Make sure it's up to date with current `develop` branch +**ALWAYS** use [Pull Request template](https://github.com/DivanteLtd/vue-storefront/blob/master/PULL_REQUEST_TEMPLATE.md) it's automatically added to each PR. +1. Fork the repository and clone it locally from the 'develop' branch. Make sure it's up to date with current `develop` branch 2. Create a branch for your edits. Use the following branch naming conventions: * bugfix/task-title * feature/task-name @@ -46,7 +44,7 @@ Here's how to submit a pull request. **Pull request that don't meet these requir 4. Reference any relevant issues or supporting documentation in your PR (ex. “Issue: 39. Issue title.”). 5. If you are adding new feature provide documentation along with the PR. Also, add it to [upgrade notes](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/Upgrade%20notes.md) 6. If you are removing/renaming something or changing its behavior also include it in [upgrade notes](https://github.com/DivanteLtd/vue-storefront/blob/master/doc/Upgrade%20notes.md) -7. Test your changes! Run your changes against any existing tests and create new ones when needed. Make sure your changes don’t break the existing project. Make sure that your branch is passing Travis CI build. +7. Test your changes! Run your changes against any existing tests and create new ones when needed. Make sure your changes don’t break the existing project. Make sure that your branch is passing Travis CI build. 8. If you have found a potential security vulnerability, please DO NOT report it on the public issue tracker. Instead, send it to us at contributors@vuestorefront.io. We will work with you to verify and fix it as soon as possible. (https://github.com/DivanteLtd/vue-storefront/blob/master/README.md#documentation--table-of-contents)) @@ -54,5 +52,5 @@ Here's how to submit a pull request. **Pull request that don't meet these requir Your pull request will be merged after meeting following criteria: - Everything from "Pull Request Checklist" -- Pull request is proposed to appropriate branch +- PR is proposed to appropriate branch - There are at least two approvals from core team members From c7cd210f16b54a783c3857ab365ad4954bbb5468 Mon Sep 17 00:00:00 2001 From: cewald Date: Sun, 13 Oct 2019 10:39:21 +0200 Subject: [PATCH 40/99] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba83c88b86..622c9b01a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Route Manager Queue for adding routes efficiently and with an optional priority - @grimasod (#3540) - Added tests for cart module actions - @andrzejewsky (#3023) - Fixed a problem with type changes in the state when extending a store - @resubaka (#3618) +- Added custom page-size parameter for `category-next/loadCategoryProducts` action - @cewald (#3713) ### Fixed From e265bcbae20002e575b7407ff72cdfc1ec18aedb Mon Sep 17 00:00:00 2001 From: cewald Date: Sun, 13 Oct 2019 16:26:06 +0200 Subject: [PATCH 41/99] Add custom system filter fields as config value --- config/default.json | 1 + core/modules/catalog-next/helpers/filterHelpers.ts | 5 +++-- docs/guide/basics/configuration.md | 6 ++++++ docs/guide/cookbook/setup.md | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index d917d5e340..3d17299236 100644 --- a/config/default.json +++ b/config/default.json @@ -311,6 +311,7 @@ "setupVariantByAttributeCode": true, "endpoint": "/api/product", "defaultFilters": ["color", "size", "price", "erin_recommends"], + "systemFilterNames": ["sort", "pagesize"], "maxFiltersQuerySize": 999, "routerFiltersSource": "query", "filterFieldMapping": { diff --git a/core/modules/catalog-next/helpers/filterHelpers.ts b/core/modules/catalog-next/helpers/filterHelpers.ts index cac1d3702a..9981aba2bb 100644 --- a/core/modules/catalog-next/helpers/filterHelpers.ts +++ b/core/modules/catalog-next/helpers/filterHelpers.ts @@ -1,6 +1,7 @@ -import FilterVariant from 'core/modules/catalog-next/types/FilterVariant'; +import config from 'config' +import FilterVariant from 'core/modules/catalog-next/types/FilterVariant' -export const getSystemFilterNames: string[] = ['sort'] +export const getSystemFilterNames: string[] = config.products.systemFilterNames /** * Creates new filtersQuery (based on currentQuery) by modifying specific filter variant. diff --git a/docs/guide/basics/configuration.md b/docs/guide/basics/configuration.md index 21b2c3b32f..02ad8814eb 100644 --- a/docs/guide/basics/configuration.md +++ b/docs/guide/basics/configuration.md @@ -496,6 +496,12 @@ This is the `vue-storefront-api` endpoint for rendering product lists. Here, we have the sort field settings as they're displayed on the Category page. +```json + "systemFilterNames": ["sort", "pagesize"], +``` + +This is array of query-fields which won't be treated as filter fields when in URL. + ```json "gallery": { "mergeConfigurableChildren": true diff --git a/docs/guide/cookbook/setup.md b/docs/guide/cookbook/setup.md index 84075a4e6e..baccae9739 100644 --- a/docs/guide/cookbook/setup.md +++ b/docs/guide/cookbook/setup.md @@ -1131,6 +1131,7 @@ At [`vue-storefront/config/default.json`](https://github.com/DivanteLtd/vue-stor "setupVariantByAttributeCode": true, "endpoint": "http://localhost:8080/api/product", "defaultFilters": ["color", "size", "price", "erin_recommends"], + "systemFilterNames": ["sort", "pagesize"], "filterFieldMapping": { "category.name": "category.name.keyword" }, From c358e7ec6cc948131e0ba2750c902ee6930bf4c7 Mon Sep 17 00:00:00 2001 From: cewald Date: Sun, 13 Oct 2019 16:31:41 +0200 Subject: [PATCH 42/99] Fix typo in docs --- docs/guide/basics/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/basics/configuration.md b/docs/guide/basics/configuration.md index 02ad8814eb..8668fa69d1 100644 --- a/docs/guide/basics/configuration.md +++ b/docs/guide/basics/configuration.md @@ -500,7 +500,7 @@ Here, we have the sort field settings as they're displayed on the Category page. "systemFilterNames": ["sort", "pagesize"], ``` -This is array of query-fields which won't be treated as filter fields when in URL. +This is an array of query-fields which won't be treated as filter fields when in URL. ```json "gallery": { From c0503f72e9477b302182024f2e3ad8e243dae41e Mon Sep 17 00:00:00 2001 From: cewald Date: Sun, 13 Oct 2019 10:36:19 +0200 Subject: [PATCH 43/99] Add custom `pageSize` parameter for `category-next/loadCategoryProducts` --- core/modules/catalog-next/store/category/actions.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index ec53f86148..82703450dc 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -23,7 +23,7 @@ import omit from 'lodash-es/omit' import config from 'config' const actions: ActionTree = { - async loadCategoryProducts ({ commit, getters, dispatch, rootState }, { route, category } = {}) { + async loadCategoryProducts ({ commit, getters, dispatch, rootState }, { route, category, pageSize = 50 } = {}) { const searchCategory = category || getters.getCategoryFrom(route.path) || {} const categoryMappedFilters = getters.getFiltersMap[searchCategory.id] const areFiltersInQuery = !!Object.keys(route[products.routerFiltersSource]).length @@ -36,7 +36,8 @@ const actions: ActionTree = { query: filterQr, sort: searchQuery.sort, includeFields: entities.productList.includeFields, - excludeFields: entities.productList.excludeFields + excludeFields: entities.productList.excludeFields, + size: pageSize }) await dispatch('loadAvailableFiltersFrom', {aggregations, category: searchCategory, filters: searchQuery.filters}) commit(types.CATEGORY_SET_SEARCH_PRODUCTS_STATS, { perPage, start, total }) From 279475b90a9f0b578d411a02eecb2278ded96bad Mon Sep 17 00:00:00 2001 From: cewald Date: Sun, 13 Oct 2019 18:23:19 +0200 Subject: [PATCH 44/99] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 622c9b01a2..c673e48116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added support for ES7 - @andrzejewsky (#3690) +- Added custom page-size parameter for `category-next/loadCategoryProducts` action - @cewald (#3713, #3714) ## [1.11.0-rc.1] - 2019.10.03 @@ -70,7 +71,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Route Manager Queue for adding routes efficiently and with an optional priority - @grimasod (#3540) - Added tests for cart module actions - @andrzejewsky (#3023) - Fixed a problem with type changes in the state when extending a store - @resubaka (#3618) -- Added custom page-size parameter for `category-next/loadCategoryProducts` action - @cewald (#3713) ### Fixed From 4cdfd8cc47dbe9df6f38f6b94f0f7a4dc1e9a4af Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 14 Oct 2019 06:37:17 +0200 Subject: [PATCH 45/99] Remove unneeded "pagesize" config value item --- config/default.json | 2 +- docs/guide/basics/configuration.md | 2 +- docs/guide/cookbook/setup.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/default.json b/config/default.json index 3d17299236..a58bb56d61 100644 --- a/config/default.json +++ b/config/default.json @@ -311,7 +311,7 @@ "setupVariantByAttributeCode": true, "endpoint": "/api/product", "defaultFilters": ["color", "size", "price", "erin_recommends"], - "systemFilterNames": ["sort", "pagesize"], + "systemFilterNames": ["sort"], "maxFiltersQuerySize": 999, "routerFiltersSource": "query", "filterFieldMapping": { diff --git a/docs/guide/basics/configuration.md b/docs/guide/basics/configuration.md index 8668fa69d1..4382698a95 100644 --- a/docs/guide/basics/configuration.md +++ b/docs/guide/basics/configuration.md @@ -497,7 +497,7 @@ This is the `vue-storefront-api` endpoint for rendering product lists. Here, we have the sort field settings as they're displayed on the Category page. ```json - "systemFilterNames": ["sort", "pagesize"], + "systemFilterNames": ["sort"], ``` This is an array of query-fields which won't be treated as filter fields when in URL. diff --git a/docs/guide/cookbook/setup.md b/docs/guide/cookbook/setup.md index baccae9739..ea977f50b7 100644 --- a/docs/guide/cookbook/setup.md +++ b/docs/guide/cookbook/setup.md @@ -1131,7 +1131,7 @@ At [`vue-storefront/config/default.json`](https://github.com/DivanteLtd/vue-stor "setupVariantByAttributeCode": true, "endpoint": "http://localhost:8080/api/product", "defaultFilters": ["color", "size", "price", "erin_recommends"], - "systemFilterNames": ["sort", "pagesize"], + "systemFilterNames": ["sort"], "filterFieldMapping": { "category.name": "category.name.keyword" }, From b39ee28c60542cdce16a330de38fddc2935f1cb0 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 15 Oct 2019 15:21:24 +0200 Subject: [PATCH 46/99] Fixed error around sort option in graphql --- core/lib/search/adapter/graphql/gqlQuery.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/search/adapter/graphql/gqlQuery.js b/core/lib/search/adapter/graphql/gqlQuery.js index 0bb90a660e..c065a36689 100644 --- a/core/lib/search/adapter/graphql/gqlQuery.js +++ b/core/lib/search/adapter/graphql/gqlQuery.js @@ -45,7 +45,11 @@ export function prepareQueryVars (Request) { if (Request.sort !== '') { const sortParse = Request.sort.split(':') - queryVariables.sort[sortParse[0]] = sortParse[1].toUpperCase() + if (sortParse[1] !== undefined) { + queryVariables.sort[sortParse[0]] = sortParse[1].toUpperCase() + } else { + queryVariables.sort[sortParse[0]] = 'ASC' + } } queryVariables.pageSize = Request.size From 28d1fed57091683e1d7ca9500d098d1a239b5c25 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 15 Oct 2019 15:22:01 +0200 Subject: [PATCH 47/99] Added in to cmsBlock items response in graphql --- core/lib/search/adapter/graphql/queries/cmsBlock.gql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/search/adapter/graphql/queries/cmsBlock.gql b/core/lib/search/adapter/graphql/queries/cmsBlock.gql index 74f5b6531a..e9cdb49214 100644 --- a/core/lib/search/adapter/graphql/queries/cmsBlock.gql +++ b/core/lib/search/adapter/graphql/queries/cmsBlock.gql @@ -5,9 +5,10 @@ query cmsBlocks ($filter: CmsInput) { { items { title + id identifier content creation_time } } -} \ No newline at end of file +} From 0627ab29210940e5eb9721f0e94ab00608ee7138 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 15 Oct 2019 15:24:34 +0200 Subject: [PATCH 48/99] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98435d2516..bb42fb2920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed handling checkbox custom option - @gibkigonzo (#2781) - Fixed typos in docs - @afozbek (#3709) - Fixed VSF build fails for some people due to lack of dependencies in the container - @krskibin (#3699) +- Fixed two graphql problems, one with cms_blocks and the other with default sort order - @resubaka (#3718) ### Added - Added support for ES7 - @andrzejewsky (#3690) From a084ebc663b4859f976c18d74d6db388b53a0a59 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 16 Oct 2019 06:35:05 +0200 Subject: [PATCH 49/99] Small fix to default sort order of _score As _score needs to be default DESC and not ASC we need to check if the sort key is _score or not. --- core/lib/search/adapter/graphql/gqlQuery.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/search/adapter/graphql/gqlQuery.js b/core/lib/search/adapter/graphql/gqlQuery.js index c065a36689..80595a9f7d 100644 --- a/core/lib/search/adapter/graphql/gqlQuery.js +++ b/core/lib/search/adapter/graphql/gqlQuery.js @@ -48,7 +48,11 @@ export function prepareQueryVars (Request) { if (sortParse[1] !== undefined) { queryVariables.sort[sortParse[0]] = sortParse[1].toUpperCase() } else { - queryVariables.sort[sortParse[0]] = 'ASC' + if (sortParse[0] === '_score') { + queryVariables.sort[sortParse[0]] = 'DESC' + } else { + queryVariables.sort[sortParse[0]] = 'ASC' + } } } From dd77bbac9ed5dc0c916814fb4a71936a6e892b40 Mon Sep 17 00:00:00 2001 From: cewald Date: Wed, 16 Oct 2019 07:57:02 +0200 Subject: [PATCH 50/99] Add config value to getter --- core/modules/catalog-next/store/category/getters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/catalog-next/store/category/getters.ts b/core/modules/catalog-next/store/category/getters.ts index dd54b83f2b..9cff3f2ca5 100644 --- a/core/modules/catalog-next/store/category/getters.ts +++ b/core/modules/catalog-next/store/category/getters.ts @@ -107,7 +107,7 @@ const getters: GetterTree = { getCurrentSearchQuery: (state, getters, rootState) => getters.getCurrentFiltersFrom(rootState.route[products.routerFiltersSource]), getCurrentFilters: (state, getters) => getters.getCurrentSearchQuery.filters, hasActiveFilters: (state, getters) => !!Object.keys(getters.getCurrentFilters).length, - getSystemFilterNames: () => ['sort'], + getSystemFilterNames: () => products.systemFilterNames, getBreadcrumbs: (state, getters) => getters.getBreadcrumbsFor(getters.getCurrentCategory), getBreadcrumbsFor: (state, getters) => category => { if (!category) return [] From e09b890188490b2078f5defc5d53a2d06fc8faa0 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 15 Oct 2019 16:44:31 +0200 Subject: [PATCH 51/99] add product-quantity component --- .../components/core/ProductQuantity.vue | 102 ++++++++++++++++++ src/themes/default/pages/Product.vue | 69 ++++-------- 2 files changed, 120 insertions(+), 51 deletions(-) create mode 100644 src/themes/default/components/core/ProductQuantity.vue diff --git a/src/themes/default/components/core/ProductQuantity.vue b/src/themes/default/components/core/ProductQuantity.vue new file mode 100644 index 0000000000..baa3b33d3e --- /dev/null +++ b/src/themes/default/components/core/ProductQuantity.vue @@ -0,0 +1,102 @@ + + + + diff --git a/src/themes/default/pages/Product.vue b/src/themes/default/pages/Product.vue index 36b7aeb0ad..4e7fefb849 100644 --- a/src/themes/default/pages/Product.vue +++ b/src/themes/default/pages/Product.vue @@ -128,31 +128,16 @@ v-else-if="getCurrentProduct.custom_options && getCurrentProduct.custom_options.length > 0" :product="getCurrentProduct" /> -
- - -
+ v-model="getCurrentProduct.qty" + :max-quantity="maxQuantity" + :loading="isStockInfoLoading" + :is-simple-or-configurable="isSimpleOrConfigurable" + show-quantity + @error="getQuantityError" + />
Date: Tue, 15 Oct 2019 17:27:01 +0200 Subject: [PATCH 52/99] add quantity check in microcart --- .../core/blocks/Microcart/EditMode.vue | 16 +++- .../core/blocks/Microcart/Product.vue | 95 ++++++++++++++++--- src/themes/default/pages/Product.vue | 1 - 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/themes/default/components/core/blocks/Microcart/EditMode.vue b/src/themes/default/components/core/blocks/Microcart/EditMode.vue index 70da1ab9c9..a4dc770ec7 100644 --- a/src/themes/default/components/core/blocks/Microcart/EditMode.vue +++ b/src/themes/default/components/core/blocks/Microcart/EditMode.vue @@ -1,10 +1,13 @@