0.0.22 • Published 17 days ago
@waakif/waakif-cart v0.0.22
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)
0.0.22
17 days ago
0.0.20
19 days ago
0.0.21
19 days ago
0.0.19
2 months ago
0.0.16
3 months ago
0.0.17
3 months ago
0.0.18
3 months ago
0.0.12
3 months ago
0.0.13
3 months ago
0.0.14
3 months ago
0.0.15
3 months ago
0.0.10
3 months ago
0.0.11
3 months ago
0.0.9
3 months ago
0.0.8
3 months ago
0.0.7
3 months ago
0.0.6
3 months ago
0.0.5
3 months ago
0.0.4
3 months ago
0.0.3
3 months ago
0.0.2
3 months ago
0.0.1
3 months ago