Skip to main content

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

ParameterTypeDescription
blockDataObjectBlock data containing the product node.
onActionFunctionAction handler for cart operations and messages.
showAddedToCartMessagebooleanWhether to show a toast after adding to cart. Default: true.

Return Value

PropertyTypeDescription
productObjectThe full product object.
tagsstring[]Product tags.
hasTagFunctionCheck if product has a specific tag. Signature: hasTag(tag).
vendorNamestringProduct vendor name.
addToCartFunctionAdds product to cart. Accepts { buynow, variant, sellingPlanId }.
updateCartFunctionUpdates cart line item quantity. Accepts { quantity }.
addtoCartLoadingbooleanWhether the add-to-cart action is in progress.
buyNowFunctionTriggers buy now flow. Accepts optional { walletPreference }.
buyNowLoadingbooleanWhether the buy now action is in progress.
countnumberCurrent quantity count.
setCountFunctionSets the quantity count.
salePricenumberCurrent sale price amount.
regularPricenumberCompare-at (regular) price amount.
onSalebooleanWhether the product is on sale.
salePercentagestring \| nullDiscount percentage (e.g., "20 %"), or null if not on sale.
currentVariantInStockbooleanWhether the selected variant is available for sale.
selectedVariantObjectThe currently selected variant from page state.
regularPriceWithCurrencystringFormatted regular price with currency. Empty if same as sale price.
salePriceWithCurrencystringFormatted sale price with currency.
preOrderEnabledbooleanWhether pre-order is enabled for out-of-stock products.
isBuyNowOnlybooleanWhether the product is tagged as buy-now-only.
isDisablePurchasebooleanWhether purchasing is disabled for this product.
checkStockAvailabilityFunctionChecks if requested quantity is available. Returns { success, availableQuantity }.
selectedVariantStoresArrayStore availability data for the selected variant.
variantSellingPlansArraySelling plan allocations for the selected variant.
purchaseRequiresSellingPlanbooleanWhether a selling plan is required to purchase.
setSelectedSellingPlanIdFunctionSets the selected selling plan ID.
selectedSellingPlanIdstringCurrently selected selling plan ID.
addToCartTextstringLabel for add-to-cart button.
addToCartButtonColorstringColor for add-to-cart button.
addCartFontColorstringFont color for add-to-cart button.
buyNowTextstringLabel for buy-now button.
buyNowButtonColorstringColor for buy-now button.
buyNowFontColorstringFont color for buy-now button.
outOfStockTextstringLabel for out-of-stock state.
outOfStockButtonColorstringColor for out-of-stock button.
outOfStockFontColorstringFont color for out-of-stock button.