Skip to content

Commit dad6546

Browse files
authored
@W-19263207 [V4 Migration] Support standard product (#3007)
* feat: support standard product v4 * fix: fix skipped unit test * fix: remove unnecessary test id * add change log * no change log needed when merging into feature branch * fix equalalpha order of product & variant * remove unnecessary product and support empty variant
1 parent 3f7281a commit dad6546

File tree

7 files changed

+817
-238
lines changed

7 files changed

+817
-238
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
export const mockStandardProductOrderable = {
9+
currency: 'GBP',
10+
id: 'a-standard-dress',
11+
imageGroups: [
12+
{
13+
images: [
14+
{
15+
alt: 'White and Black Tone, , large',
16+
disBaseLink:
17+
'https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dw9178fd89/images/large/PG.W20766.IVORYXX.PZ.jpg',
18+
link: 'https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dw9178fd89/images/large/PG.W20766.IVORYXX.PZ.jpg',
19+
title: 'White and Black Tone, '
20+
}
21+
],
22+
viewType: 'large'
23+
},
24+
{
25+
images: [
26+
{
27+
alt: 'White and Black Tone, , medium',
28+
disBaseLink:
29+
'https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dw9af8c50e/images/medium/PG.W20766.IVORYXX.PZ.jpg',
30+
link: 'https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dw9af8c50e/images/medium/PG.W20766.IVORYXX.PZ.jpg',
31+
title: 'White and Black Tone, '
32+
}
33+
],
34+
viewType: 'medium'
35+
},
36+
{
37+
images: [
38+
{
39+
alt: 'White and Black Tone, , small',
40+
disBaseLink:
41+
'https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dw58be3274/images/small/PG.W20766.IVORYXX.PZ.jpg',
42+
link: 'https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dw58be3274/images/small/PG.W20766.IVORYXX.PZ.jpg',
43+
title: 'White and Black Tone, '
44+
}
45+
],
46+
viewType: 'small'
47+
}
48+
],
49+
inventory: {
50+
ats: 999999,
51+
backorderable: false,
52+
id: 'inventory_m',
53+
orderable: true,
54+
preorderable: false,
55+
stockLevel: 999999
56+
},
57+
longDescription: 'A Standard Dress',
58+
minOrderQuantity: 1,
59+
name: 'White and Black Tone',
60+
pageMetaTags: [
61+
{
62+
id: 'description',
63+
value: 'Buy White and Black Tone at RefArchGlobal.'
64+
},
65+
{
66+
id: 'robots',
67+
value: 'index, follow'
68+
},
69+
{
70+
id: 'og:url',
71+
value: 'https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.store/s/RefArchGlobal/dw/shop/v99_9/products/a-standard-dress?currency=GBP&locale=en-GB&expand=availability,promotions,options,images,prices,variations,set_products,bundled_products,page_meta_tags&all_images=true'
72+
},
73+
{
74+
id: 'title',
75+
value: 'Buy White and Black Tone for GBP 4.00 | RefArchGlobal'
76+
}
77+
],
78+
price: 4,
79+
pricePerUnit: 4,
80+
primaryCategoryId: 'womens-outfits',
81+
shortDescription: 'A Standard Dress',
82+
slugUrl:
83+
'https://zzrf-001.dx.commercecloud.salesforce.com/s/RefArchGlobal/en_GB/product/a-standard-dress/a-standard-dress.html',
84+
stepQuantity: 1,
85+
type: {
86+
item: true
87+
},
88+
tieredPrices: [
89+
{
90+
price: 70,
91+
pricebook: 'gbp-m-list-prices',
92+
quantity: 1
93+
},
94+
{
95+
price: 4,
96+
pricebook: 'gbp-m-sale-prices',
97+
quantity: 1
98+
}
99+
]
100+
}
101+
102+
export const mockStandardProductNotOrderable = {
103+
...mockStandardProductOrderable,
104+
id: 'a-standard-dress-not-orderable',
105+
inventory: {
106+
ats: 0,
107+
backorderable: false,
108+
id: 'inventory_m',
109+
orderable: false,
110+
preorderable: false,
111+
stockLevel: 0
112+
}
113+
}

packages/template-chakra-storefront/src/components/product-view/index.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,21 @@ const ProductView = forwardRef(
162162
setChildProductOrderability,
163163
isBasketLoading = false,
164164
onVariantSelected = () => {},
165-
validateOrderability = (variant, quantity, stockLevel) =>
166-
!isProductLoading && variant?.orderable && quantity > 0 && quantity <= stockLevel,
165+
validateOrderability = (product, variant, quantity, stockLevel) => {
166+
if (isProductLoading) return false
167+
168+
// If product has variations, a variant must be selected
169+
if (product?.variationAttributes?.length > 0 && !variant) {
170+
return false
171+
}
172+
173+
// Check if product (either variant or standard) is orderable and if quantity is valid
174+
return (
175+
(variant?.orderable || product?.inventory?.orderable) &&
176+
quantity > 0 &&
177+
quantity <= stockLevel
178+
)
179+
},
167180
showImageGallery = true,
168181
setSelectedBundleQuantity = () => {},
169182
selectedBundleParentQuantity = 1
@@ -199,8 +212,8 @@ const ProductView = forwardRef(
199212
return getPriceData(product, {quantity})
200213
}, [product, quantity])
201214
const canAddToWishlist = !isProductLoading
202-
const isProductASet = product?.type.set
203-
const isProductABundle = product?.type.bundle
215+
const isProductASet = product?.type?.set
216+
const isProductABundle = product?.type?.bundle
204217
const errorContainerRef = useRef(null)
205218

206219
const {disableButton, customInventoryMessage} = useMemo(() => {
@@ -240,7 +253,7 @@ const ProductView = forwardRef(
240253
const validateAndShowError = (opts = {}) => {
241254
const {scrollErrorIntoView = true} = opts
242255
// Validate that all attributes are selected before proceeding.
243-
const hasValidSelection = validateOrderability(variant, quantity, stockLevel)
256+
const hasValidSelection = validateOrderability(product, variant, quantity, stockLevel)
244257
const hasError = !isProductASet && !isProductABundle && !hasValidSelection
245258
const scrollToError = hasError && scrollErrorIntoView
246259

@@ -379,7 +392,7 @@ const ProductView = forwardRef(
379392
if (
380393
!isProductASet &&
381394
!isProductABundle &&
382-
validateOrderability(variant, quantity, stockLevel)
395+
validateOrderability(product, variant, quantity, stockLevel)
383396
) {
384397
toggleShowOptionsMessage(false)
385398
}

0 commit comments

Comments
 (0)