@waakif/waakif-cart
v0.0.36
Published
This is an app for waakif to maintain cart and handle all the computation and mathematics
Downloads
29
Readme
Waakif Cart
A custom cart functionality with Add / Update Items and Add Offers.
How to Install
yarn add @waakif/waakif-cart or npm i @waakif/waakif-cart
Peer Dependency
yarn add sonner
Initialization
After installing package you have to initialze
this package and feed some data to create / update
cart.
import {useCart} from 'waakif-cart'
const {updateCart, cartData, upsertOffer, removeOffer} = useCart({
products: [],
offers: [],
org: {_id: '123', name: 'Dummy Org'}
})
Data Return
cartData: Retruns from useCart
with following object
{
"items": [
{
"appliedDiscountAmount": 10,
"discountApplied": false,
"eachPrice": 99,
"product": "123",
"quantity": 1,
"totalAmount": 99,
"notes": "Freebie / Bogo",
"totalAmountWithoutDiscount": 99,
"name": "Pizza",
"productId": "Product Object"
},
],
"gstAmount": 18,
"gstPercentage": 18,
"totalAmount": 300,
"totalAmountWithGst": 354,
"discount": 0,
"appliedOfferId": "Offer Object",
"loyaltyPointsUsed": 0,
"gstDetails": {
"CGSTAmount": 9,
"SGSTAmount": 9
}
}
Supported Methods / Hooks
|Method|Parameter|Return|
|-|-|-|
|useCart|{products: List of Products, offers: List of Offers, org: Org Details}
|This hook will return 3 things: 1.updateCart 2.cartData 3.upsertOffer
|updateCart|{product: id of product, quantity: 3}
|This will do all the calculation of product and make new cart data
|upsertOffer|offerId|This function will check offer requirements and if all things passes for offer then it will applied to cart.
|removeOffer|null|This will remove the applicable offer from the cartData
Collaboration
Steps for build and publish package
1. yarn build or npm run build
2. npm publish (before publishing must have to login with `npm` credential)