@graphcommerce/magento-product 9.1.0-canary.23 → 9.1.0-canary.26
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,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 9.1.0-canary.26
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#2522](https://github.com/graphcommerce-org/graphcommerce/pull/2522) [`43641a4`](https://github.com/graphcommerce-org/graphcommerce/commit/43641a48e0f3828d99b686b2f7cbca915f426d64) - Solve issue where grouped products could only be added to the cart correctly once. ([@paales](https://github.com/paales))
|
8
|
+
|
9
|
+
## 9.1.0-canary.25
|
10
|
+
|
11
|
+
## 9.1.0-canary.24
|
12
|
+
|
3
13
|
## 9.1.0-canary.23
|
4
14
|
|
5
15
|
### Patch Changes
|
@@ -60,24 +60,31 @@ export function AddProductsToCartForm(props: AddProductsToCartFormProps) {
|
|
60
60
|
cartId,
|
61
61
|
cartItems: cartItems
|
62
62
|
.filter((cartItem) => cartItem.sku && cartItem.quantity !== 0)
|
63
|
-
.map(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
...
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
63
|
+
.map(
|
64
|
+
({
|
65
|
+
selected_options_record = {},
|
66
|
+
entered_options_record = {},
|
67
|
+
keep_sku,
|
68
|
+
...cartItem
|
69
|
+
}) => ({
|
70
|
+
...cartItem,
|
71
|
+
quantity: cartItem.quantity || 1,
|
72
|
+
selected_options: [
|
73
|
+
...(cartItem.selected_options ?? []).filter(nonNullable),
|
74
|
+
...Object.values(selected_options_record).flat(1).filter(nonNullable),
|
75
|
+
],
|
76
|
+
entered_options: [
|
77
|
+
...(cartItem.entered_options ?? []).filter(nonNullable),
|
78
|
+
...Object.entries(entered_options_record).map(([uid, value]) => {
|
79
|
+
if (value instanceof Date) {
|
80
|
+
const dateValue = value.toISOString().replace(/.000Z/, '').replace('T', ' ')
|
81
|
+
return { uid, value: dateValue }
|
82
|
+
}
|
83
|
+
return { uid, value: value.toString() }
|
84
|
+
}),
|
85
|
+
],
|
86
|
+
}),
|
87
|
+
),
|
81
88
|
}
|
82
89
|
|
83
90
|
const sku = requestData.cartItems[requestData.cartItems.length - 1]?.sku
|
@@ -95,9 +102,11 @@ export function AddProductsToCartForm(props: AddProductsToCartFormProps) {
|
|
95
102
|
onComplete: async (result, variables) => {
|
96
103
|
await onComplete?.(result, variables)
|
97
104
|
|
98
|
-
// After the form has been submitted, we're resetting the submitted SKU's
|
105
|
+
// After the form has been submitted, we're resetting the submitted SKU's to disable them all.
|
106
|
+
// We use the presence of the SKU to determine if the line is 'enabled'.
|
107
|
+
// After submitting we reset (when using multiple buttons in a single form)
|
99
108
|
form.getValues('cartItems').forEach((item, index) => {
|
100
|
-
if (item.sku) form.setValue(`cartItems.${index}.sku`, '')
|
109
|
+
if (item.sku && !item.keep_sku) form.setValue(`cartItems.${index}.sku`, '')
|
101
110
|
})
|
102
111
|
|
103
112
|
if (toUserErrors(result.data).length || result.errors?.length || !redirect) return
|
@@ -30,7 +30,9 @@ export function useAddProductsToCartAction(
|
|
30
30
|
const formState = useFormState({ control })
|
31
31
|
const { sku = props.product?.sku, product, index = 0, onClick: onClickIncoming, disabled } = props
|
32
32
|
|
33
|
-
const loading =
|
33
|
+
const loading =
|
34
|
+
formState.isSubmitting &&
|
35
|
+
(product?.__typename === 'GroupedProduct' || getValues(`cartItems.${index}.sku`) === sku)
|
34
36
|
|
35
37
|
const [showSuccess, setShowSuccess] = useState<boolean>(false)
|
36
38
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { UseFormGqlMutationReturn } from '@graphcommerce/ecommerce-ui'
|
2
|
-
import type {
|
2
|
+
import type { CartItemInput } from '@graphcommerce/graphql-mesh'
|
3
3
|
import { createContext, useContext } from 'react'
|
4
4
|
import type { LiteralUnion, Simplify } from 'type-fest'
|
5
5
|
import type {
|
@@ -9,25 +9,35 @@ import type {
|
|
9
9
|
|
10
10
|
export type RedirectType = LiteralUnion<'added' | undefined | false, `/${string}`>
|
11
11
|
|
12
|
-
type Item =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
type Item = CartItemInput & {
|
13
|
+
/**
|
14
|
+
* The value of the selected_options_record values will be added to the selected_options array.
|
15
|
+
*
|
16
|
+
* This format exists to prevent name collisions and without having to select by index in the
|
17
|
+
* selected_options array.
|
18
|
+
*/
|
19
|
+
selected_options_record?: Record<string, string | string[]>
|
20
|
+
/**
|
21
|
+
* The value of the entered_options_record entries will be coverted to entries for the
|
22
|
+
* entered_options array.
|
23
|
+
*
|
24
|
+
* This format exists to prevent name collisions and without having to select by index in the
|
25
|
+
* entered_options array.
|
26
|
+
*/
|
27
|
+
entered_options_record?: Record<string, string | number | Date>
|
28
|
+
|
29
|
+
/**
|
30
|
+
* If the sku is present in a cartItem we consider the cartItem to be included in the submission.
|
31
|
+
*
|
32
|
+
* In `useAddProductsToCartAction` the sku of the product is set. This allows to determine which
|
33
|
+
* product to add to the cart depending on which button is pressed. This usecase is relevant when
|
34
|
+
* adding products from a list that are wrapped in a single form.
|
35
|
+
*
|
36
|
+
* In the usecase where the product is always known (like on the product page), we don't want to
|
37
|
+
* reset the sku. For example for grouped products we always want to add variants of the product.
|
38
|
+
*/
|
39
|
+
keep_sku?: boolean
|
40
|
+
}
|
31
41
|
|
32
42
|
export type AddProductsToCartFields = Omit<AddProductsToCartMutationVariables, 'cartItems'> & {
|
33
43
|
cartItems: Item[]
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@graphcommerce/magento-product",
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
5
|
-
"version": "9.1.0-canary.
|
5
|
+
"version": "9.1.0-canary.26",
|
6
6
|
"sideEffects": false,
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
8
8
|
"eslintConfig": {
|
@@ -18,18 +18,18 @@
|
|
18
18
|
"typescript": "5.7.2"
|
19
19
|
},
|
20
20
|
"peerDependencies": {
|
21
|
-
"@graphcommerce/ecommerce-ui": "^9.1.0-canary.
|
22
|
-
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.
|
23
|
-
"@graphcommerce/framer-next-pages": "^9.1.0-canary.
|
24
|
-
"@graphcommerce/framer-scroller": "^9.1.0-canary.
|
25
|
-
"@graphcommerce/graphql": "^9.1.0-canary.
|
26
|
-
"@graphcommerce/graphql-mesh": "^9.1.0-canary.
|
27
|
-
"@graphcommerce/image": "^9.1.0-canary.
|
28
|
-
"@graphcommerce/magento-cart": "^9.1.0-canary.
|
29
|
-
"@graphcommerce/magento-store": "^9.1.0-canary.
|
30
|
-
"@graphcommerce/next-ui": "^9.1.0-canary.
|
31
|
-
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.
|
32
|
-
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.
|
21
|
+
"@graphcommerce/ecommerce-ui": "^9.1.0-canary.26",
|
22
|
+
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.26",
|
23
|
+
"@graphcommerce/framer-next-pages": "^9.1.0-canary.26",
|
24
|
+
"@graphcommerce/framer-scroller": "^9.1.0-canary.26",
|
25
|
+
"@graphcommerce/graphql": "^9.1.0-canary.26",
|
26
|
+
"@graphcommerce/graphql-mesh": "^9.1.0-canary.26",
|
27
|
+
"@graphcommerce/image": "^9.1.0-canary.26",
|
28
|
+
"@graphcommerce/magento-cart": "^9.1.0-canary.26",
|
29
|
+
"@graphcommerce/magento-store": "^9.1.0-canary.26",
|
30
|
+
"@graphcommerce/next-ui": "^9.1.0-canary.26",
|
31
|
+
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.26",
|
32
|
+
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.26",
|
33
33
|
"@lingui/core": "^4.2.1",
|
34
34
|
"@lingui/macro": "^4.2.1",
|
35
35
|
"@lingui/react": "^4.2.1",
|