From 17a5304cbe297d29ddddce0d88f2c1bff220b59d Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Thu, 4 Jan 2024 13:44:13 +0100 Subject: [PATCH] fix: prevent agragations from being excluded during defaultConfigurableOptionsSelection --- .changeset/spotty-pens-explain.md | 5 +++++ .../utils/defaultConfigurableOptionsSelection.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/spotty-pens-explain.md diff --git a/.changeset/spotty-pens-explain.md b/.changeset/spotty-pens-explain.md new file mode 100644 index 0000000000..0958f82299 --- /dev/null +++ b/.changeset/spotty-pens-explain.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-product-configurable": patch +--- + +Spread product back into products instead of only adding items diff --git a/packages/magento-product-configurable/utils/defaultConfigurableOptionsSelection.ts b/packages/magento-product-configurable/utils/defaultConfigurableOptionsSelection.ts index 10dd41eeb1..31e538af29 100644 --- a/packages/magento-product-configurable/utils/defaultConfigurableOptionsSelection.ts +++ b/packages/magento-product-configurable/utils/defaultConfigurableOptionsSelection.ts @@ -29,7 +29,7 @@ export function defaultConfigurableOptionsSelection { if (!import.meta.graphCommerce.configurableVariantForSimple) { const product = query?.products?.items?.find((p) => p?.url_key === urlKey) - return { ...query, products: { items: [product] }, defaultValues: {} } + return { ...query, products: { ...query?.products, items: [product] }, defaultValues: {} } } const simple = query?.products?.items?.find((p) => p?.url_key === urlKey) @@ -44,7 +44,8 @@ export function defaultConfigurableOptionsSelection a.uid) - if (!selectedOptions.length) return { ...query, products: { items: [simple] }, defaultValues: {} } + if (!selectedOptions.length) + return { ...query, products: { ...query?.products, items: [simple] }, defaultValues: {} } /** * We're using writeQuery to the Apollo Client cache, to to avoid a second request to the GraphQL