Skip to content

Commit 874e332

Browse files
authored
fix(product): BACK-400 Fix BO data on PDP for complex products (#3031)
1 parent 15e365a commit 874e332

3 files changed

Lines changed: 29 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: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
6868

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

@@ -91,17 +102,6 @@ export default async function Product({ params, searchParams }: Props) {
91102
}
92103

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

127129
const product = await getStreamableProductInventory(variables, customerAccessToken);
@@ -155,17 +157,6 @@ export default async function Product({ params, searchParams }: Props) {
155157
});
156158

157159
const streamableProductPricingAndRelatedProducts = Streamable.from(async () => {
158-
const options = await searchParams;
159-
160-
const optionValueIds = Object.keys(options)
161-
.map((option) => ({
162-
optionEntityId: Number(option),
163-
valueEntityId: Number(options[option]),
164-
}))
165-
.filter(
166-
(option) => !Number.isNaN(option.optionEntityId) && !Number.isNaN(option.valueEntityId),
167-
);
168-
169160
const currencyCode = await getPreferredCurrencyCode();
170161

171162
const variables = {

0 commit comments

Comments
 (0)