Skip to content

Commit 7be5192

Browse files
committed
fix(product): BACK-400 Fix BO data on PDP for complex products
1 parent 4e44415 commit 7be5192

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Display backorder information for variants on PDP.

core/app/[locale]/(default)/product/[slug]/page-data.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,17 @@ export const getStreamableProduct = cache(
337337

338338
const StreamableProductInventoryQuery = graphql(
339339
`
340-
query StreamableProductInventoryQuery($entityId: Int!) {
340+
query StreamableProductInventoryQuery(
341+
$entityId: Int!
342+
$optionValueIds: [OptionValueId!]
343+
$useDefaultOptionSelections: Boolean
344+
) {
341345
site {
342-
product(entityId: $entityId) {
346+
product(
347+
entityId: $entityId
348+
optionValueIds: $optionValueIds
349+
useDefaultOptionSelections: $useDefaultOptionSelections
350+
) {
343351
sku
344352
inventory {
345353
hasVariantInventory
@@ -363,7 +371,7 @@ const StreamableProductInventoryQuery = graphql(
363371
[ProductVariantsInventoryFragment],
364372
);
365373

366-
type ProductInventoryVariables = VariablesOf<typeof StreamableProductQuery>;
374+
type ProductInventoryVariables = VariablesOf<typeof StreamableProductInventoryQuery>;
367375

368376
export const getStreamableProductInventory = cache(
369377
async (variables: ProductInventoryVariables, customerAccessToken?: string) => {

core/app/[locale]/(default)/product/[slug]/page.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
6767

6868
export default async function Product({ params, searchParams }: Props) {
6969
const { locale, slug } = await params;
70+
const options = await searchParams;
71+
72+
const optionValueIds = Object.keys(options)
73+
.map((option) => ({
74+
optionEntityId: Number(option),
75+
valueEntityId: Number(options[option]),
76+
}))
77+
.filter(
78+
(option) => !Number.isNaN(option.optionEntityId) && !Number.isNaN(option.valueEntityId),
79+
);
80+
7081
const customerAccessToken = await getSessionCustomerAccessToken();
7182
const detachedWishlistFormId = 'product-add-to-wishlist-form';
7283

@@ -90,17 +101,6 @@ export default async function Product({ params, searchParams }: Props) {
90101
}
91102

92103
const streamableProduct = Streamable.from(async () => {
93-
const options = await searchParams;
94-
95-
const optionValueIds = Object.keys(options)
96-
.map((option) => ({
97-
optionEntityId: Number(option),
98-
valueEntityId: Number(options[option]),
99-
}))
100-
.filter(
101-
(option) => !Number.isNaN(option.optionEntityId) && !Number.isNaN(option.valueEntityId),
102-
);
103-
104104
const variables = {
105105
entityId: Number(productId),
106106
optionValueIds,
@@ -121,6 +121,8 @@ export default async function Product({ params, searchParams }: Props) {
121121
const streamableProductInventory = Streamable.from(async () => {
122122
const variables = {
123123
entityId: Number(productId),
124+
optionValueIds,
125+
useDefaultOptionSelections: true,
124126
};
125127

126128
const product = await getStreamableProductInventory(variables, customerAccessToken);
@@ -153,17 +155,7 @@ export default async function Product({ params, searchParams }: Props) {
153155
return removeEdgesAndNodes(variants).find((v) => v.sku === product.sku);
154156
});
155157

156-
const streamableProductPricingAndRelatedProducts = Streamable.from(async () => {
157-
const options = await searchParams;
158-
159-
const optionValueIds = Object.keys(options)
160-
.map((option) => ({
161-
optionEntityId: Number(option),
162-
valueEntityId: Number(options[option]),
163-
}))
164-
.filter(
165-
(option) => !Number.isNaN(option.optionEntityId) && !Number.isNaN(option.valueEntityId),
166-
);
158+
const streamableProductPricingAndRelatedProducts = Streamable.from(async () => {;
167159

168160
const currencyCode = await getPreferredCurrencyCode();
169161

0 commit comments

Comments
 (0)