From 4b4a40b14f8ede77a030d199d452a6b1b33460d8 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Tue, 8 Oct 2019 14:34:08 +0200 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 95c3bbdc1ce4b4e6bf23ce78a9a6eb4d86bbeb9b Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Wed, 9 Oct 2019 11:00:25 +0200 Subject: [PATCH 7/7] 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