Skip to main content

useProductDetail

This hook is used to get the product detail data.

propsTypeDescriptionExample
shareProductFunctionShare productshareProduct()
onSaleBooleanWhether product is on sale or nottrue
buyNowLoadingBooleanState for buy now loadingfalse
addtoCartLoadingBooleanState for add to cart loadingfalse
addToCartFunctionaddToCart({buynow,appmakerAction}), by default both params are falseaddToCart()
updateCartFunctionupdateCart({ quantity = 1, appmakerAction = false }), by default quantity is 1 and appmakerAction is falseupdateCart()
countNumberCount of product0
addingBooleanstate for cart updatefalse
setAddingFunctionIt's a state setter for cart updatesetAdding(true)
setCountFunctionState setter for quantitysetCount(1)
buyNowFunctionBuy now function, buyNow()buyNow()
titleStringTitle of productT shirt Yasi
tax_included_textStringTax included text
product_subtitleStringProduct subtitle
average_ratingStringAverage rating3.43
reviews_countStringReviews count14
productObjectProduct
salePriceStringSale priceRs. 30
regularPriceStringRegular priceRs. 35
currentVariantInStockBooleanIs current variant in stocktrue
regularPriceValueNumberRegular price value35
tagsStringTags
salePriceValueNumberSale price value30
productVariantObjectProduct variant
variantIdStringVariant id40018184732834
salePercentageStringSale percentage14 %
descriptionHtmlStringHTML description of the product<p>Product description</p>
descriptionStringPlain text description of the product"Product description"
savedAmountNumberAmount saved on sale5
displayWishlistBooleanWhether to display wishlist optiontrue
displayShareButtonBooleanWhether to display share buttontrue
preOrderEnabledBooleanWhether pre-order is enabled for the productfalse

Usage:

import { useProductDetail } from '@appmaker-xyz/shopify';
const { product, variantId, salePercentage ,addToCart } = useProductDetail(); // You can get the above props from this hook
const cartResp = await addToCart({
buynow: true,
appmakerAction: {
action: 'OPEN_INAPP_PAGE', // you can set a custom action here
pageId: 'cartPageCheckout',
}
});

const updateCartResp = await updateCart({
quantity: 2,
appmakerAction: {
action: 'OPEN_INAPP_PAGE', // you can set a custom action here
pageId: 'cartPageCheckout',
}
});