Non-technically explanation
The PLU item needs to exist in the restaurant PLU data (PLU with price)
If the item doesn't exist in the selected store data (when using the Whitelabel app) the app will alert the user that the item is unavailable (when the item is added in the cart preview or added inside the checkout, for example)
The restaurant data is not available to be configured inside Sanity. This needs to be done somewhere else.
Analysis
For each restaurant, we'll have the restaurantPosData
returned from the usePosDataQuery
. This will be where we get the prices object for all PLUs available for the user selected store.
At some point in the application, we'll check if an item (in the menu or the item added to the cart) is an available item checking his PLU against the PLU prices object. If this PLU is not found the application will show a modal alerting the user that the item is not available for the selected store (image above).
Some components and hooks will work together in this workflow:
Cart Page → The page is responsible for showing the
OrderUnavailableModal
Path:
src/pages/cart/index.tsx
usePriceOrder
: This hook will pass theunavailableCartEntries
and the cart will know when to show the modaluseUnavailableCartEntries:
This hook is used inside theusePriceOrder
, returning theunavailableCartEntries
useGetUnavailableItemsFromMenu
: This hook will filter/return the unavailable items (with data = null)useCartEntriesMenuObjects
: This hook will use theasyncGetMenuObject
fromuseMenuContext
to get the menu object itemsThe returned data from this context will be filtered using the
applyFiltersForAvailability
methodThis method will check if the item is available using the
itemIsAvailable
(for type “Item”) that uses thevendorConfigIsAvailable
methodFinally, the
vendorConfigIsAvailable
will use thepluIsAvailable
to look inside the restaurant prices PLU data looking for the PLU for the desired item. If the PLU is not found there, the item is considered UNAVAILABLEOBS: The
applyFiltersForAvailability
will receive the prices object fromuseStoreUtils
that will use theusePosDataQuery
:
Add Comment