Table of Contents
...
For context and details:
Discovery:Promo code at checkout page X config offer type (WIP)
Tech refinement for the mentioned discovery: Tech refinement - Add offer Combo/Picker to the cart
...
Business problem to be solved
Enable the ability to edit an offer Combo/Picker after adding the item to the cart (for more details about adding a Combo/Picker offer item see the documents above)
...
Show the edit item button for Combo/Picker offer items added through promo code field
Cart preview item
...
Show the edit item button for Combo/Picker offer items added through the promo code field
All items and information need to be correct if the user decides to go back to the home page or menu page
Cart item update flow
When editing the item and go back to the menu page the total value, items and sub-items need to be correct
After updating the item and going back to the checkout page the whole item needs to be correct (sub-items, total price, etc)
Cart preview item
...
Show the edit item button for Combo/Picker offer items added through the promo code field
All items and information need to be correct if the user decides to go back to the home page or menu page
Tasks breakdown
Task 1 - Adjust the condition to show the edit button for Combo/Picker offer item at checkout/cart preview
...
Before inserting the item for the first time we need to change the url property value to the following combination:
menu/type-id
(example:menu/combo-dc95c3c7-5b84-4e36-aee0-a0acee02ccda
)We need to use the picker/combo id and type from Sanity incentive item or the query. We can’t use the
mainEntry
fromtransformMenuObjectToCartItem
because for Picker the id will be changed and this will cause a bug
Solution proposal
PS: This was not developed/tested during the PoC as we think that we don’t have anything impossible to solve here. Besides that, we are suggesting a path to this
All the logic below needs to be inside our hook:
src/state/loyalty/hooks/use-redeem-promo-code-checkout.ts
Create a new isolated method that will be responsible to only mount the desired URL
This method needs to be used on:
Before the
upsertCart
call, changing the url property on the passed objectAfter we update the Combo/Picker item on the menu and go back to the checkout page
Option 1:
Get the
cartEntries
fromuseOrderContext
and iterate and compare with the offers available at theappliedOffers
from Redux state (useAppSelector(selectors.loyalty.selectAppliedOffers
)) if we have an offer there. If yes, update the cart entry (updateCartEntry
fromuseOrderContext
) with the correct URL
Option 2:
Analyze where the URL is created on the code and adjust the code from there (hypothesis)
Important tip: our
useEffect
(atsrc/state/loyalty/hooks/use-redeem-promo-code-checkout.ts
) is running almost "all the time". During the PoC we detected that after update the item and going back to the checkout page the item appears with the correct price and then was removed and quickly added again with a wrong price. This can be related to thisuseEffect
that needs to be refactored.
DOD
Update tests