@waakif/waakif-cart v0.0.55
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)
Test Package In Local
First do below steps in cart package file
yarn build
npm link
Then go to your frontend repo and remove waakif-cart package if installed and run
npm link @waakif/waakif-cart --legacy-peer-deps
After all the testing unlink package from repo and publish the package
npm unlink @waakif/waakif-cart
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
7 months ago
7 months ago
8 months ago
9 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago