...
First of all, we’ll need to look at what’s configured on Sanity (the free quantity field)
Use the following methods from
useOrderContext
(./src/state/order/index.js
) hook:removeAllFromCart
: here we’ll pass the array with cart id’s that we want to remove (paid items)updateQuantity
: here we’ll pass thecartId
(from for the updated item) and thequantity
of free items after removing the paid item(s) or to remove free extras items (when changing the main item(s))
Create a new
useEffect
inAddOnsItemsContainer
(./src/pages/cart/addons-item-container/addons-item-container.tsx
). We can use thecartEntries
on the dependencies array.Create a new method (or methods, feel free on that) in
useAddOnsItemContainer
(/src/pages/cart/addons-item-container/hook/use-addons-item-container.ts
) that we’ll be used inside thisuseEffect
We can pass the
cartEntries
on these methods (we’ll need this on the further logics)Pass the
removeAllFromCart
andupdateQuantity
as config items on theuseAddOnsItemContainer
and use these methods in the new logic
Following the rules and business requirements we’ll need to make the logic
Always remember that we can have one or more sections and one or more free items. The solution needs to be dynamic
...