useProductDetail
This hook is used to get the product detail data.
props | Type | Description | Example |
---|---|---|---|
shareProduct | Function | Share product | shareProduct() |
onSale | Boolean | Whether product is on sale or not | true |
buyNowLoading | Boolean | State for buy now loading | false |
addtoCartLoading | Boolean | State for add to cart loading | false |
addToCart | Function | addToCart({buynow,appmakerAction}), by default both params are false | addToCart() |
updateCart | Function | updateCart({ quantity = 1, appmakerAction = false }), by default quantity is 1 and appmakerAction is false | updateCart() |
count | Number | Count of product | 0 |
adding | Boolean | state for cart update | false |
setAdding | Function | It's a state setter for cart update | setAdding(true) |
setCount | Function | State setter for quantity | setCount(1) |
buyNow | Function | Buy now function, buyNow() | buyNow() |
title | String | Title of product | T shirt Yasi |
tax_included_text | String | Tax included text | |
product_subtitle | String | Product subtitle | |
average_rating | String | Average rating | 3.43 |
reviews_count | String | Reviews count | 14 |
product | Object | Product | |
salePrice | String | Sale price | Rs. 30 |
regularPrice | String | Regular price | Rs. 35 |
currentVariantInStock | Boolean | Is current variant in stock | true |
regularPriceValue | Number | Regular price value | 35 |
tags | String | Tags | |
salePriceValue | Number | Sale price value | 30 |
productVariant | Object | Product variant | |
variantId | String | Variant id | 40018184732834 |
salePercentage | String | Sale percentage | 14 % |
descriptionHtml | String | HTML description of the product | <p>Product description</p> |
description | String | Plain text description of the product | "Product description" |
savedAmount | Number | Amount saved on sale | 5 |
displayWishlist | Boolean | Whether to display wishlist option | true |
displayShareButton | Boolean | Whether to display share button | true |
preOrderEnabled | Boolean | Whether pre-order is enabled for the product | false |
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',
}
});