useProductDetailV2
This hook provides product detail page (PDP) functionality including add-to-cart, buy now, pricing, variant selection state, and selling plan support.
Import
import { useProductDetailV2 } from '@appmaker-xyz/shopify';
Basic Usage
const {
product,
title,
addToCart,
buyNow,
addtoCartLoading,
buyNowLoading,
salePrice,
regularPrice,
onSale,
salePercentage,
currentVariantInStock,
selectedVariant,
count,
setCount,
updateCart,
} = useProductDetailV2({ blockData, onAction });
Parameters
| Parameter | Type | Description |
|---|---|---|
blockData | Object | Block data containing the product node. |
onAction | Function | Action handler for cart operations and messages. |
showAddedToCartMessage | boolean | Whether to show a toast after adding to cart. Default: true. |
Return Value
| Property | Type | Description |
|---|---|---|
product | Object | The full product object. |
tags | string[] | Product tags. |
hasTag | Function | Check if product has a specific tag. Signature: hasTag(tag). |
vendorName | string | Product vendor name. |
addToCart | Function | Adds product to cart. Accepts { buynow, variant, sellingPlanId }. |
updateCart | Function | Updates cart line item quantity. Accepts { quantity }. |
addtoCartLoading | boolean | Whether the add-to-cart action is in progress. |
buyNow | Function | Triggers buy now flow. Accepts optional { walletPreference }. |
buyNowLoading | boolean | Whether the buy now action is in progress. |
count | number | Current quantity count. |
setCount | Function | Sets the quantity count. |
salePrice | number | Current sale price amount. |
regularPrice | number | Compare-at (regular) price amount. |
onSale | boolean | Whether the product is on sale. |
salePercentage | string \| null | Discount percentage (e.g., "20 %"), or null if not on sale. |
currentVariantInStock | boolean | Whether the selected variant is available for sale. |
selectedVariant | Object | The currently selected variant from page state. |
regularPriceWithCurrency | string | Formatted regular price with currency. Empty if same as sale price. |
salePriceWithCurrency | string | Formatted sale price with currency. |
preOrderEnabled | boolean | Whether pre-order is enabled for out-of-stock products. |
isBuyNowOnly | boolean | Whether the product is tagged as buy-now-only. |
isDisablePurchase | boolean | Whether purchasing is disabled for this product. |
checkStockAvailability | Function | Checks if requested quantity is available. Returns { success, availableQuantity }. |
selectedVariantStores | Array | Store availability data for the selected variant. |
variantSellingPlans | Array | Selling plan allocations for the selected variant. |
purchaseRequiresSellingPlan | boolean | Whether a selling plan is required to purchase. |
setSelectedSellingPlanId | Function | Sets the selected selling plan ID. |
selectedSellingPlanId | string | Currently selected selling plan ID. |
addToCartText | string | Label for add-to-cart button. |
addToCartButtonColor | string | Color for add-to-cart button. |
addCartFontColor | string | Font color for add-to-cart button. |
buyNowText | string | Label for buy-now button. |
buyNowButtonColor | string | Color for buy-now button. |
buyNowFontColor | string | Font color for buy-now button. |
outOfStockText | string | Label for out-of-stock state. |
outOfStockButtonColor | string | Color for out-of-stock button. |
outOfStockFontColor | string | Font color for out-of-stock button. |