Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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 the cartId (from for the updated item) and the quantity 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 in AddOnsItemsContainer (./src/pages/cart/addons-item-container/addons-item-container.tsx). We can use the cartEntries 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 this useEffect

    • We can pass the cartEntries on these methods (we’ll need this on the further logics)

    • Pass the removeAllFromCart and updateQuantity as config items on the useAddOnsItemContainer 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

...