-
Notifications
You must be signed in to change notification settings - Fork 355
feat: Add out-of-stock/backorder message to product lists #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| --- | ||
| "@bigcommerce/catalyst-core": minor | ||
| --- | ||
|
|
||
| Add out-of-stock / backorder message to product cards on PLPs based on store settings: | ||
| - Add out of stock message if the product is out of stock and stock is set to display it. | ||
| - 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 | ||
|
|
||
| ## Migration | ||
|
|
||
| ### Option 1: Automatic Migration (Recommended) | ||
| 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. | ||
|
|
||
| ### Option 2: Manual Migration | ||
| If you prefer not to rebase or have made customizations that prevent rebasing, follow these manual steps: | ||
|
|
||
| #### Step 1: Update GraphQL Fragment | ||
| Add the inventory fields to your product card fragment in `core/components/product-card/fragment.ts` under `Product`: | ||
| ```graphql | ||
| inventory { | ||
| hasVariantInventory | ||
| isInStock | ||
| aggregated { | ||
| availableForBackorder | ||
| unlimitedBackorder | ||
| availableOnHand | ||
| } | ||
| } | ||
| variants(first: 1) { | ||
| edges { | ||
| node { | ||
| entityId | ||
| sku | ||
| inventory { | ||
| byLocation { | ||
| edges { | ||
| node { | ||
| locationEntityId | ||
| backorderMessage | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Step 2: Update Product interface in Product Card component | ||
| Update the `Product` interface in `core/vibes/soul/primitives/product-card/index.tsx` adding the following field to it: | ||
|
|
||
| `inventoryMessage?: string;` | ||
|
|
||
| #### Step 3: Update Data Transformer | ||
| 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. | ||
|
|
||
| #### Step 4: Update Product Card Layout | ||
| Update `core/vibes/soul/primitives/product-card/index.tsx` layout to display the new `inventoryMessage` product field. | ||
|
|
||
| #### Step 5: Update Page Data GraphQL queries | ||
| Add inventory settings queries to the pages data. Add the following query to the main GQL query under `site.settings`: | ||
| ``` | ||
| inventory { | ||
| defaultOutOfStockMessage | ||
| showOutOfStockMessage | ||
| showBackorderMessage | ||
| } | ||
| ``` | ||
| to the following page data files: | ||
| - `core/app/[locale]/(default)/(faceted)/brand/[slug]/page-data.ts` | ||
| - `core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts` | ||
| - `core/app/[locale]/(default)/(faceted)/search/page-data.ts` | ||
| - `core/app/[locale]/(default)/page-data.ts` | ||
|
|
||
| #### Step 6: Update Page Components | ||
| 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: | ||
| ``` | ||
| const { defaultOutOfStockMessage, showOutOfStockMessage, showBackorderMessage } = | ||
| data.site.settings?.inventory ?? {}; | ||
|
|
||
| return productCardTransformer( | ||
| featuredProducts, | ||
| format, | ||
| showOutOfStockMessage ? defaultOutOfStockMessage : undefined, | ||
| showBackorderMessage, | ||
| ); | ||
| ``` | ||
| in the following files: | ||
| - `core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx` | ||
| - `core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx` | ||
| - `core/app/[locale]/(default)/(faceted)/search/page.tsx` | ||
| - `core/app/[locale]/(default)/page.tsx` | ||
|
|
||
| ### Files Modified in This Change | ||
| - `core/app/[locale]/(default)/(faceted)/brand/[slug]/page-data.ts` | ||
| - `core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx` | ||
| - `core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts` | ||
| - `core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx` | ||
| - `core/app/[locale]/(default)/(faceted)/search/page-data.ts` | ||
| - `core/app/[locale]/(default)/(faceted)/search/page.tsx` | ||
| - `core/app/[locale]/(default)/page-data.ts` | ||
| - `core/app/[locale]/(default)/page.tsx` | ||
| - `core/components/product-card/fragment.ts` | ||
| - `core/data-transformers/product-card-transformer.ts` | ||
| - `core/vibes/soul/primitives/product-card/index.tsx` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.