@graphcommerce/magento-product-grouped 9.1.0-canary.44 → 9.1.0-canary.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.1.0-canary.46
4
+
5
+ ## 9.1.0-canary.45
6
+
7
+ ### Patch Changes
8
+
9
+ - [`f915f65`](https://github.com/graphcommerce-org/graphcommerce/commit/f915f655f5965bab1d50eca9b275199c02e7b7d1) - Make sure the default quantity is selected on the product page for grouped products. Products are sorted correctly and create a separate GroupedProductItem fragment for easier etensibility. ([@paales](https://github.com/paales))
10
+
3
11
  ## 9.1.0-canary.44
4
12
 
5
13
  ## 9.1.0-canary.43
@@ -113,7 +121,6 @@
113
121
  ### Patch Changes
114
122
 
115
123
  - [#1752](https://github.com/graphcommerce-org/graphcommerce/pull/1752) [`2a6a4d9ec`](https://github.com/graphcommerce-org/graphcommerce/commit/2a6a4d9ecfa1b58a66ba9b9d00016d6feda9aa95) - Updated dependencies to latest versions, except for nextjs; Solve tons of peer dependency issues.
116
-
117
124
  - Updated the @mui/material package
118
125
  - Removed dependencies on react-hook-form-mui and @playwright/test
119
126
  - Upgraded dependencies including type-fest and graphql-mesh
@@ -2,21 +2,18 @@ import { Image } from '@graphcommerce/image'
2
2
  import type { AddToCartItemSelector } from '@graphcommerce/magento-product'
3
3
  import {
4
4
  AddProductsToCartQuantity,
5
- ProductListPrice,
5
+ ProductPagePrice,
6
6
  useFormAddProductsToCart,
7
7
  } from '@graphcommerce/magento-product'
8
8
  import type { ActionCardProps } from '@graphcommerce/next-ui'
9
- import { ActionCard, actionCardImageSizes, responsiveVal } from '@graphcommerce/next-ui'
9
+ import { ActionCard, actionCardImageSizes } from '@graphcommerce/next-ui'
10
10
  import { Link } from '@mui/material'
11
- import type { GroupedProductFragment } from '../GroupedProduct.gql'
11
+ import type { GroupedProductItemFragment } from '../graphql/fragments/GroupedProductItem.gql'
12
12
 
13
- type GroupedProductItem = NonNullable<
14
- NonNullable<GroupedProductFragment['items']>[number]
15
- >['product']
16
-
17
- export type GroupedProductActionCardProps = GroupedProductItem &
18
- Omit<ActionCardProps, 'value' | 'image' | 'price' | 'title' | 'action'> &
19
- AddToCartItemSelector
13
+ export type GroupedProductActionCardProps = {
14
+ item: GroupedProductItemFragment
15
+ } & AddToCartItemSelector &
16
+ Omit<ActionCardProps, 'value' | 'image' | 'price' | 'title' | 'action'>
20
17
 
21
18
  const typographySizes = {
22
19
  small: 'body2',
@@ -25,23 +22,16 @@ const typographySizes = {
25
22
  }
26
23
 
27
24
  export function GroupedProductActionCard(props: GroupedProductActionCardProps) {
28
- const {
29
- uid,
30
- name,
31
- small_image,
32
- price_range,
33
- url_key,
34
- sx = [],
35
- size = 'large',
36
- index = 0,
37
- sku,
38
- url_rewrites,
39
- ...rest
40
- } = props
41
-
25
+ const { item, sx = [], size = 'large', index = 0, ...rest } = props
26
+ const { product } = item
42
27
  const { control, register } = useFormAddProductsToCart()
43
- if (!sku) return null
28
+
29
+ if (!product?.sku) return null
30
+
31
+ const { uid, name, small_image, url_key, sku, url_rewrites } = product
44
32
  const hasUrl = (url_rewrites ?? []).length > 0
33
+ const qty = item.qty ?? 0
34
+
45
35
  return (
46
36
  <>
47
37
  <input type='hidden' {...register(`cartItems.${index}.sku`)} value={sku} />
@@ -126,12 +116,20 @@ export function GroupedProductActionCard(props: GroupedProductActionCardProps) {
126
116
  secondaryAction={
127
117
  <AddProductsToCartQuantity
128
118
  size='small'
129
- defaultValue={1}
130
119
  index={index}
120
+ defaultValue={qty}
131
121
  onMouseDown={(e) => e.stopPropagation()}
122
+ inputProps={{ min: 0 }}
123
+ />
124
+ }
125
+ price={
126
+ <ProductPagePrice
127
+ index={index}
128
+ product={product}
129
+ defaultValue={qty ?? 0}
130
+ variant='total'
132
131
  />
133
132
  }
134
- price={<ProductListPrice {...price_range.minimum_price} />}
135
133
  {...rest}
136
134
  />
137
135
  </>
@@ -1,6 +1,6 @@
1
- import { ActionCardLayout, filterNonNullableKeys } from '@graphcommerce/next-ui'
1
+ import { ActionCardLayout, filterNonNullableKeys, nonNullable } from '@graphcommerce/next-ui'
2
2
  import { useMemo } from 'react'
3
- import type { GroupedProductFragment } from '../GroupedProduct.gql'
3
+ import type { GroupedProductFragment } from '../graphql/fragments/GroupedProduct.gql'
4
4
  import { GroupedProductActionCard } from './GroupedProductActionCard'
5
5
 
6
6
  export type GroupedProductsProps = {
@@ -9,21 +9,15 @@ export type GroupedProductsProps = {
9
9
 
10
10
  export function GroupedProducts(props: GroupedProductsProps) {
11
11
  const { product } = props
12
- const productItems = useMemo(() => {
13
- if (product?.__typename !== 'GroupedProduct') return null
14
- const { items } = product
15
- return filterNonNullableKeys(items, ['product']).map((item, i) => ({
16
- ...item.product,
17
- value: item.product.sku ?? '',
18
- index: i,
19
- }))
20
- }, [product])
21
- if (!productItems) return null
12
+
13
+ const items = filterNonNullableKeys(product.items, ['position', 'product']).sort(
14
+ (a, b) => a.position - b.position,
15
+ )
22
16
 
23
17
  return (
24
18
  <ActionCardLayout>
25
- {productItems.map((item) => (
26
- <GroupedProductActionCard {...item} key={item.value ?? ''} size='medium' />
19
+ {items.map((item, index) => (
20
+ <GroupedProductActionCard index={index} item={item} key={item.position} size='medium' />
27
21
  ))}
28
22
  </ActionCardLayout>
29
23
  )
@@ -0,0 +1,6 @@
1
+ fragment GroupedProduct on GroupedProduct {
2
+ __typename
3
+ items {
4
+ ...GroupedProductItem
5
+ }
6
+ }
@@ -0,0 +1,11 @@
1
+ fragment GroupedProductItem on GroupedProductItem {
2
+ position
3
+ qty
4
+ product {
5
+ url_key
6
+ url_rewrites {
7
+ url
8
+ }
9
+ ...ProductListItem
10
+ }
11
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product-grouped",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.1.0-canary.44",
5
+ "version": "9.1.0-canary.46",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,18 +12,18 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/ecommerce-ui": "^9.1.0-canary.44",
16
- "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.44",
17
- "@graphcommerce/graphql": "^9.1.0-canary.44",
18
- "@graphcommerce/image": "^9.1.0-canary.44",
19
- "@graphcommerce/magento-cart": "^9.1.0-canary.44",
20
- "@graphcommerce/magento-product": "^9.1.0-canary.44",
21
- "@graphcommerce/magento-product-simple": "^9.1.0-canary.44",
22
- "@graphcommerce/magento-product-virtual": "^9.1.0-canary.44",
23
- "@graphcommerce/magento-store": "^9.1.0-canary.44",
24
- "@graphcommerce/next-ui": "^9.1.0-canary.44",
25
- "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.44",
26
- "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.44",
15
+ "@graphcommerce/ecommerce-ui": "^9.1.0-canary.46",
16
+ "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.46",
17
+ "@graphcommerce/graphql": "^9.1.0-canary.46",
18
+ "@graphcommerce/image": "^9.1.0-canary.46",
19
+ "@graphcommerce/magento-cart": "^9.1.0-canary.46",
20
+ "@graphcommerce/magento-product": "^9.1.0-canary.46",
21
+ "@graphcommerce/magento-product-simple": "^9.1.0-canary.46",
22
+ "@graphcommerce/magento-product-virtual": "^9.1.0-canary.46",
23
+ "@graphcommerce/magento-store": "^9.1.0-canary.46",
24
+ "@graphcommerce/next-ui": "^9.1.0-canary.46",
25
+ "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.46",
26
+ "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.46",
27
27
  "@lingui/core": "^4.2.1",
28
28
  "@lingui/macro": "^4.2.1",
29
29
  "@lingui/react": "^4.2.1",
@@ -1,15 +0,0 @@
1
- fragment GroupedProduct on GroupedProduct {
2
- __typename
3
- items {
4
- position
5
- qty
6
- product {
7
- uid
8
- __typename
9
- url_rewrites {
10
- url
11
- }
12
- ...ProductListItem
13
- }
14
- }
15
- }