Skip to content

Commit

Permalink
Merge pull request #2159 from graphcommerce-org/fix/product-aggregations
Browse files Browse the repository at this point in the history
fix: prevent agragations from being excluded during defaultConfigurableOptionsSelection
  • Loading branch information
paales authored Jan 4, 2024
2 parents 8421496 + 17a5304 commit 4cc7abf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-pens-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-product-configurable": patch
---

Spread product back into products instead of only adding items
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function defaultConfigurableOptionsSelection<Q extends BaseQuery = BaseQu
): Q & Pick<AddProductsToCartFormProps, 'defaultValues'> {
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)
Expand All @@ -44,7 +44,8 @@ export function defaultConfigurableOptionsSelection<Q extends BaseQuery = BaseQu
?.attributes

const selectedOptions = (attributes ?? []).filter(nonNullable).map((a) => 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
Expand Down

1 comment on commit 4cc7abf

@vercel
Copy link

@vercel vercel bot commented on 4cc7abf Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

graphcommerce-hygraph-dynamic-rows-ui – ./packages/hygraph-dynamic-rows-ui

graphcommerce-hygraph-dynamic-rows-ui.vercel.app
graphcommerce-hygraph-dynamic-rows-ui-graphcommerce.vercel.app
graphcommerce-hygraph-dynamic-rows-ui-git-canary-graphcommerce.vercel.app

Please sign in to comment.