PLU x Item unavailable (analysis)

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 (perhaps, where we configure the POS data for restaurants)


Technical 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 the unavailableCartEntries and the cart will know when to show the modal

      • useUnavailableCartEntries: This hook is used inside the usePriceOrder, returning the unavailableCartEntries

        • useGetUnavailableItemsFromMenu: This hook will filter/return the unavailable items (with data = null)

          • useCartEntriesMenuObjects: This hook will use the asyncGetMenuObject from useMenuContext to get the menu object items

            • The returned data from this context will be filtered using the applyFiltersForAvailability method

            • This method will check if the item is available using the itemIsAvailable (for type “Item”) that uses the vendorConfigIsAvailable method

            • Finally, the vendorConfigIsAvailable will use the pluIsAvailable 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 UNAVAILABLE

            • OBS: The applyFiltersForAvailability will receive the prices object from useStoreUtils that will use the usePosDataQuery: