From 581181ca1cb35f37d1b7c2502ba262921cd00800 Mon Sep 17 00:00:00 2001 From: Marcin Kwiatkowski Date: Wed, 29 Jun 2022 08:11:54 +0200 Subject: [PATCH 1/2] fix: m2-860. fixed wrong values of selected configurable product variants --- .../product-types/configurable/ConfigurableProduct.vue | 2 +- .../checkout/composables/useCart/commands/addItemCommand.ts | 4 ++-- packages/theme/modules/checkout/composables/useCart/index.ts | 5 ++++- .../theme/modules/checkout/composables/useCart/useCart.ts | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/theme/modules/catalog/product/components/product-types/configurable/ConfigurableProduct.vue b/packages/theme/modules/catalog/product/components/product-types/configurable/ConfigurableProduct.vue index 1117710ea..b57b7b285 100644 --- a/packages/theme/modules/catalog/product/components/product-types/configurable/ConfigurableProduct.vue +++ b/packages/theme/modules/catalog/product/components/product-types/configurable/ConfigurableProduct.vue @@ -131,7 +131,7 @@ v-e2e="'product_add-to-cart'" :disabled="isCartLoading || !canAddToCart(product, qty) || isFetching" class="product__add-to-cart" - @click="addItem({ product, quantity: parseInt(qty) })" + @click="addItem({ product, quantity: parseInt(qty), productConfiguration })" /> { @@ -61,8 +62,7 @@ export const addItemCommand = { .addProductsToCart .cart as unknown as Cart; case 'ConfigurableProduct': - const selectedOptions = product.configurable_product_options_selection.options_available_for_selection - .flatMap((attr) => attr.option_value_uids); + const selectedOptions = Object.values(productConfiguration as Object); const configurableCartInput: AddProductsToCartInput = { cartId, diff --git a/packages/theme/modules/checkout/composables/useCart/index.ts b/packages/theme/modules/checkout/composables/useCart/index.ts index 80c4da71e..c573572ec 100644 --- a/packages/theme/modules/checkout/composables/useCart/index.ts +++ b/packages/theme/modules/checkout/composables/useCart/index.ts @@ -122,7 +122,9 @@ PRODUCT } }; - const addItem = async ({ product, quantity, customQuery }): Promise => { + const addItem = async ({ + product, quantity, productConfiguration, customQuery, + }): Promise => { Logger.debug('useCart.addItem', { product, quantity }); try { @@ -136,6 +138,7 @@ PRODUCT currentCart: cart.value, product, quantity, + productConfiguration, customQuery, }); diff --git a/packages/theme/modules/checkout/composables/useCart/useCart.ts b/packages/theme/modules/checkout/composables/useCart/useCart.ts index 96073ff91..8cd34e645 100644 --- a/packages/theme/modules/checkout/composables/useCart/useCart.ts +++ b/packages/theme/modules/checkout/composables/useCart/useCart.ts @@ -8,6 +8,7 @@ import { Product } from '~/modules/catalog/product/types'; export type UseCartAddItemParams = ComposableFunctionArgs<{ product: PRODUCT; quantity: number; + productConfiguration?: { [key: string]: string }; }>; /** From 112bd08f0b88a2118bad0ff21688833b0305f3a5 Mon Sep 17 00:00:00 2001 From: Marcin Kwiatkowski Date: Wed, 29 Jun 2022 09:15:11 +0200 Subject: [PATCH 2/2] Update packages/theme/modules/checkout/composables/useCart/commands/addItemCommand.ts Co-authored-by: Artur Tagisow <5359825+sethidden@users.noreply.github.com> --- .../checkout/composables/useCart/commands/addItemCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/modules/checkout/composables/useCart/commands/addItemCommand.ts b/packages/theme/modules/checkout/composables/useCart/commands/addItemCommand.ts index d3f90dfc0..92e0c1d41 100644 --- a/packages/theme/modules/checkout/composables/useCart/commands/addItemCommand.ts +++ b/packages/theme/modules/checkout/composables/useCart/commands/addItemCommand.ts @@ -62,7 +62,7 @@ export const addItemCommand = { .addProductsToCart .cart as unknown as Cart; case 'ConfigurableProduct': - const selectedOptions = Object.values(productConfiguration as Object); + const selectedOptions = Object.values(productConfiguration as object); const configurableCartInput: AddProductsToCartInput = { cartId,