diff --git a/.changeset/rotten-vans-train.md b/.changeset/rotten-vans-train.md new file mode 100644 index 000000000..d112379b3 --- /dev/null +++ b/.changeset/rotten-vans-train.md @@ -0,0 +1,10 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Show backorder details for digital items on cart page + +## Migration +For existing Catalyst stores, to this fix, simply rebase the existing code with the new release code. The files to be rebased for this change to be applied are: +- core/app/[locale]/(default)/cart/page-data.ts +- core/app/[locale]/(default)/cart/page.tsx diff --git a/core/app/[locale]/(default)/cart/page-data.ts b/core/app/[locale]/(default)/cart/page-data.ts index c6e47636d..9c00df8d7 100644 --- a/core/app/[locale]/(default)/cart/page-data.ts +++ b/core/app/[locale]/(default)/cart/page-data.ts @@ -115,6 +115,12 @@ export const DigitalItemFragment = graphql(` } } url + stockPosition { + backorderMessage + quantityOnHand + quantityBackordered + quantityOutOfStock + } } `); diff --git a/core/app/[locale]/(default)/cart/page.tsx b/core/app/[locale]/(default)/cart/page.tsx index bc07f3d47..fd4111dea 100644 --- a/core/app/[locale]/(default)/cart/page.tsx +++ b/core/app/[locale]/(default)/cart/page.tsx @@ -127,43 +127,40 @@ export default async function Cart({ params }: Props) { let inventoryMessages; - if (item.__typename === 'CartPhysicalItem') { - if (item.stockPosition?.quantityOutOfStock === item.quantity) { - inventoryMessages = { - outOfStockMessage: data.site.settings?.inventory?.showOutOfStockMessage - ? data.site.settings.inventory.defaultOutOfStockMessage + if (item.stockPosition?.quantityOutOfStock === item.quantity) { + inventoryMessages = { + outOfStockMessage: data.site.settings?.inventory?.showOutOfStockMessage + ? data.site.settings.inventory.defaultOutOfStockMessage + : undefined, + }; + } else { + inventoryMessages = { + quantityReadyToShipMessage: + data.site.settings?.inventory?.showQuantityOnHand && !!item.stockPosition?.quantityOnHand + ? t('quantityReadyToShip', { + quantity: Number(item.stockPosition.quantityOnHand), + }) : undefined, - }; - } else { - inventoryMessages = { - quantityReadyToShipMessage: - data.site.settings?.inventory?.showQuantityOnHand && - !!item.stockPosition?.quantityOnHand - ? t('quantityReadyToShip', { - quantity: Number(item.stockPosition.quantityOnHand), - }) - : undefined, - quantityBackorderedMessage: - data.site.settings?.inventory?.showQuantityOnBackorder && - !!item.stockPosition?.quantityBackordered - ? t('quantityOnBackorder', { - quantity: Number(item.stockPosition.quantityBackordered), - }) - : undefined, - quantityOutOfStockMessage: - data.site.settings?.inventory?.showOutOfStockMessage && - !!item.stockPosition?.quantityOutOfStock - ? t('partiallyAvailable', { - quantity: item.quantity - Number(item.stockPosition.quantityOutOfStock), - }) - : undefined, - backorderMessage: - data.site.settings?.inventory?.showBackorderMessage && - !!item.stockPosition?.quantityBackordered - ? (item.stockPosition.backorderMessage ?? undefined) - : undefined, - }; - } + quantityBackorderedMessage: + data.site.settings?.inventory?.showQuantityOnBackorder && + !!item.stockPosition?.quantityBackordered + ? t('quantityOnBackorder', { + quantity: Number(item.stockPosition.quantityBackordered), + }) + : undefined, + quantityOutOfStockMessage: + data.site.settings?.inventory?.showOutOfStockMessage && + !!item.stockPosition?.quantityOutOfStock + ? t('partiallyAvailable', { + quantity: item.quantity - Number(item.stockPosition.quantityOutOfStock), + }) + : undefined, + backorderMessage: + data.site.settings?.inventory?.showBackorderMessage && + !!item.stockPosition?.quantityBackordered + ? (item.stockPosition.backorderMessage ?? undefined) + : undefined, + }; } return {