Skip to main content

useCartProduct

This hook is used to get the cart product data.

propsTypeDescriptionExample
openProductFunctionOpens the product page<button onClick={openProduct}>Open Product</button>
titleStringProduct title'T shirt Yasi'
isFreeGiftBooleanIs the product a free giftfalse
imageUriStringProduct image url'https://cdn.shopify.com/image.jpg'
variationTextStringProduct variation text'XL / blue'
salePriceStringProduct sale price'Rs. 60'
regularPriceStringProduct regular price'Rs. 35'
unitRegularPriceStringProduct unit regular price'Rs. 35'
unitSalePriceStringProduct unit sale price'Rs. 30'
onRemoveItemFunctionRemoves the product from the cart<button onClick={onRemoveItem}>Remove Item</button>
removeLoadingBooleanloading state of the remove itemfalse
onSaleBooleanIs the product on saletrue
quantityNumberProduct quantity1
__appmakerCustomStylesObjectCustom styles{button: { backgroundColor: '#ee3d63', }}
onQuantityChangeFunctionUpdates the product quantity<button onClick={onQuantityChange}>Update Quantity</button>
quantityLoadingBooleanloading state of the quantity changefalse
itemSavingsAmountStringProduct savings amount'40'
itemSavingsWithCurrencyStringProduct savings with currency'Rs. 40'
regularPriceWithCurrencyStringProduct regular price with currency'Rs. 35'
variantLineItemRegularPriceWithCurrencyStringProduct variant line item regular price with currency'Rs. 70'
variantLineItemSalePriceWithCurrencyStringProduct variant line item sale price with currency'Rs. 60'
discountTitleStringProduct discount title'Discount'
currencyHelperFunctionCurrency helper functioncurrencyHelper(200 , 'INR' ) // Rs. 200
variantTitleStringProduct variant title'XL / blue'
lineItemTotalPriceStringProduct line item total price'30'
variantObjectShopify Product variant
increaseQuantityFunctionIncreases the product quantity<button onClick={increaseQuantity}>Increase Quantity</button>
decreaseQuantityFunctionDecreases the product quantity
canRemoveItemBooleanCan the product be removedtrue
canUpdateQuantityBooleanCan the product quantity be updatedtrue
lineItemRegularPricestringProduct line item regular price'70'
lineItemRegularPriceWithCurrencyStringProduct line item regular price with currency'Rs. 70'
lineItemSubTotalPriceWithCurrencyStringProduct line item sub total price with currency'Rs. 30'
hasDiscountBooleanDoes the product have a discounttrue
hasSavingsBooleanDoes the product have savingsfalse
lineItemDiscountCodesArrayProduct line item discount codes[ 'APP' ]
isLineItemFreeBooleanIs the product line item freefalse
skuStringProduct sku'sku-123'
customAttributesArrayProduct custom attributes[{ key: '_appmaker', value: 'true' }]

Usage:

import { useCartProduct } from '@appmaker-xyz/shopify';

const CartCard = (props) => {
const {
title,
imageUri,
regularPrice,
isFreeGift,
onSale,
quantity,
onRemoveItem,
removeLoading,
decreaseQuantity,
openProduct,
currencyHelper,
} = useCartProduct(props);
return (
<div>
<h1>{title}</h1>
<img src={imageUri} />
<text>{currencyHelper(regularPrice,'INR')}</text> // Rs. 200
<button onClick={openProduct}>Open Product</button>
</div>
);
};

cart