|
| 1 | +--- |
| 2 | +"@bigcommerce/catalyst-core": minor |
| 3 | +--- |
| 4 | + |
| 5 | +Add out-of-stock / backorder message to product cards on PLPs based on store settings: |
| 6 | +- Add out of stock message if the product is out of stock and stock is set to display it. |
| 7 | +- Add the backorder message if the product has no on-hand stock and is available for backorder and the store/product is set to display the backorder message |
| 8 | + |
| 9 | +## Migration |
| 10 | + |
| 11 | +### Option 1: Automatic Migration (Recommended) |
| 12 | +For existing Catalyst stores, the simplest way to get the newly added feature is to rebase the existing code with the new release code. The files that will be updated are listed below. |
| 13 | + |
| 14 | +### Option 2: Manual Migration |
| 15 | +If you prefer not to rebase or have made customizations that prevent rebasing, follow these manual steps: |
| 16 | + |
| 17 | +#### Step 1: Update GraphQL Fragment |
| 18 | +Add the inventory fields to your product card fragment in `core/components/product-card/fragment.ts` under `Product`: |
| 19 | +```graphql |
| 20 | +inventory { |
| 21 | + hasVariantInventory |
| 22 | + isInStock |
| 23 | + aggregated { |
| 24 | + availableForBackorder |
| 25 | + unlimitedBackorder |
| 26 | + availableOnHand |
| 27 | + } |
| 28 | +} |
| 29 | +variants(first: 1) { |
| 30 | + edges { |
| 31 | + node { |
| 32 | + entityId |
| 33 | + sku |
| 34 | + inventory { |
| 35 | + byLocation { |
| 36 | + edges { |
| 37 | + node { |
| 38 | + locationEntityId |
| 39 | + backorderMessage |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +#### Step 2: Update Product interface in Product Card component |
| 50 | +Update the `Product` interface in `core/vibes/soul/primitives/product-card/index.tsx` adding the following field to it: |
| 51 | + |
| 52 | +`inventoryMessage?: string;` |
| 53 | + |
| 54 | +#### Step 3: Update Data Transformer |
| 55 | +Modify `core/data-transformers/product-card-transformer.ts` to include inventory message in the transformed data. You can simply copy the whole file from this release as it does not have UI breaking changes. |
| 56 | + |
| 57 | +#### Step 4: Update Product Card Layout |
| 58 | +Update `core/vibes/soul/primitives/product-card/index.tsx` layout to display the new `inventoryMessage` product field. |
| 59 | + |
| 60 | +#### Step 5: Update Page Data GraphQL queries |
| 61 | +Add inventory settings queries to the pages data. Add the following query to the main GQL query under `site.settings`: |
| 62 | +``` |
| 63 | +inventory { |
| 64 | + defaultOutOfStockMessage |
| 65 | + showOutOfStockMessage |
| 66 | + showBackorderMessage |
| 67 | +} |
| 68 | +``` |
| 69 | +to the following page data files: |
| 70 | +- `core/app/[locale]/(default)/(faceted)/brand/[slug]/page-data.ts` |
| 71 | +- `core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts` |
| 72 | +- `core/app/[locale]/(default)/(faceted)/search/page-data.ts` |
| 73 | +- `core/app/[locale]/(default)/page-data.ts` |
| 74 | + |
| 75 | +#### Step 6: Update Page Components |
| 76 | +Update the corresponding page components to use the `productCardTransformer` method (if not already using it) to get the product card, and pass inventory data to those product cards based on the store inventory settings. Use the following code while retrieving the product lists: |
| 77 | +``` |
| 78 | + const { defaultOutOfStockMessage, showOutOfStockMessage, showBackorderMessage } = |
| 79 | + data.site.settings?.inventory ?? {}; |
| 80 | +
|
| 81 | + return productCardTransformer( |
| 82 | + featuredProducts, |
| 83 | + format, |
| 84 | + showOutOfStockMessage ? defaultOutOfStockMessage : undefined, |
| 85 | + showBackorderMessage, |
| 86 | + ); |
| 87 | +``` |
| 88 | +in the following files: |
| 89 | +- `core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx` |
| 90 | +- `core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx` |
| 91 | +- `core/app/[locale]/(default)/(faceted)/search/page.tsx` |
| 92 | +- `core/app/[locale]/(default)/page.tsx` |
| 93 | + |
| 94 | +### Files Modified in This Change |
| 95 | +- `core/app/[locale]/(default)/(faceted)/brand/[slug]/page-data.ts` |
| 96 | +- `core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx` |
| 97 | +- `core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts` |
| 98 | +- `core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx` |
| 99 | +- `core/app/[locale]/(default)/(faceted)/search/page-data.ts` |
| 100 | +- `core/app/[locale]/(default)/(faceted)/search/page.tsx` |
| 101 | +- `core/app/[locale]/(default)/page-data.ts` |
| 102 | +- `core/app/[locale]/(default)/page.tsx` |
| 103 | +- `core/components/product-card/fragment.ts` |
| 104 | +- `core/data-transformers/product-card-transformer.ts` |
| 105 | +- `core/vibes/soul/primitives/product-card/index.tsx` |
0 commit comments