@@ -46,7 +46,11 @@ export const GroupedProduct: FunctionComponent<GroupedProductProps> = ({ group }
46
46
async ( { items } ) => {
47
47
if ( ! cartId || addingSimpleProductsToCart . loading ) return
48
48
49
- await addSimpleProductToCart ( items . filter ( ( item : any ) => item . data . quantity > 0 ) )
49
+ const values = items . filter ( ( item : any ) => item . data . quantity > 0 )
50
+
51
+ if ( values . length === 0 ) return
52
+
53
+ await addSimpleProductToCart ( values )
50
54
51
55
await history . push ( '/cart' )
52
56
@@ -57,34 +61,38 @@ export const GroupedProduct: FunctionComponent<GroupedProductProps> = ({ group }
57
61
58
62
return (
59
63
< Root as = { Form } onSubmit = { handleAddToCart } >
60
- { items ?. map ( ( { sku, name, price, stock, quantity } , key ) => (
61
- < Item key = { key } >
62
- < Title > { name } </ Title >
63
-
64
- < Input type = "hidden" name = { `items[${ key } ].data.sku` } value = { sku } rules = { { required : true } } />
65
-
66
- < PriceContainer >
67
- < Price
68
- label = { price . maximum . regular . value > price . minimum . regular . value ? 'Starting at' : undefined }
69
- regular = { price . minimum . regular . value }
70
- special = { price . minimum . discount . amountOff && price . minimum . final . value - price . minimum . discount . amountOff }
71
- currency = { price . minimum . regular . currency }
72
- />
73
-
74
- < Quantity
75
- name = { `items[${ key } ].data.quantity` }
76
- defaultValue = { stock === 'IN_STOCK' ? quantity : 0 }
77
- disabled = { stock === 'IN_STOCK' }
78
- addLabel = "Add"
79
- removeLabel = "Remove"
80
- minValue = { 0 }
81
- min = { 0 }
82
- rules = { { required : true } }
83
- hideError
84
- />
85
- </ PriceContainer >
86
- </ Item >
87
- ) ) }
64
+ { items ?. map ( ( { sku, name, price, stock, quantity } , key ) => {
65
+ const inStock = stock === 'IN_STOCK'
66
+
67
+ return (
68
+ < Item key = { key } >
69
+ < Title > { name } </ Title >
70
+
71
+ < Input type = "hidden" name = { `items[${ key } ].data.sku` } value = { sku } rules = { { required : true } } />
72
+
73
+ < PriceContainer >
74
+ < Price
75
+ label = { price . maximum . regular . value > price . minimum . regular . value ? 'Starting at' : undefined }
76
+ regular = { price . minimum . regular . value }
77
+ special = { price . minimum . discount . amountOff && price . minimum . final . value - price . minimum . discount . amountOff }
78
+ currency = { price . minimum . regular . currency }
79
+ />
80
+
81
+ < Quantity
82
+ name = { `items[${ key } ].data.quantity` }
83
+ defaultValue = { inStock ? quantity : 0 }
84
+ disabled = { ! inStock }
85
+ addLabel = "Add"
86
+ removeLabel = "Remove"
87
+ minValue = { 0 }
88
+ min = { 0 }
89
+ rules = { { required : true } }
90
+ hideError
91
+ />
92
+ </ PriceContainer >
93
+ </ Item >
94
+ )
95
+ } ) }
88
96
< Button type = "submit" as = "button" text = "Add to Cart" loading = { addingSimpleProductsToCart . loading } />
89
97
</ Root >
90
98
)
0 commit comments