I’m creating an app that allows Instagram home chefs to sell food online. Workflow wise it’s a little simpler than UberEats and Deliveroo, it simply allows the customer to add items/qty to their basket and select a day for delivery or collection (I’ve handled all that stuff using Air Date/Time Plugin, which is a godsend btw!).
I’ve been watching a few tutorials around handling the basket/checkout workflow and they all seem to create an Order in the database when the Menu page loads. This seems ok, but if the user refreshes the page it creates a new Order, rather than persisting the current Order for a session. Whilst this works, it presents two issues:
A user experience issue where the basket clears if they refresh or move off the page
Mess in the db. A lot of orders that are never processed.
Can anyone think of a better way to handle Order logic? Worth pointing out that the user could be either logged in or not logged in at the stage where they are creating their Order.
Would I be better off using a state to hold all the menu selections and only creating an Order when they actually proceed to checkout? Is there a way to do this where the state is not cleared if they refresh the page, or move to another page and come back?
Data objects
Outlet
Menu
Products
Basket
Line Items
Order
When the user clicks to Add a product, I create or check if a user already has a basket. If they do, I create a line item, which contains the Product, Qty, and Subtotal field.
Multiple line items can be added to a basket.
When the user checks out I’ll create an order and either attach the basket or copy the line items out of it.
I could have gone down the local storage or Env variable routes, but it’s likely overkill for my product right now.
I created an online store and approached it in a somewhat similar fashion. Essentially, creating line items based on a selected product and an indicated quantity. Bubble displays the line items based on the user that created it. Dollar subtotal/totals get added/subtracted to the user record in number fields. The order gets created, with its line items, upon the user choosing to pay, at which time they can only do so if logged in.
It seemed you wanted things to happen on the page, so I suggested the plugin in case you wanted to avoid elaborate logic to make things sing.
Yes thanks @cmarchan after deliberating I found that it wasn’t a big issue to create a basket object, as long as my orders table stays clean it should be fine.
Thank you for your help and push in the right direction