How to correctly handle an Order

Hi all,

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:

  1. A user experience issue where the basket clears if they refresh or move off the page
  2. 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?

Thanks in advance.

Dan

Hi Dan,

I am corrently working on a similar case with a shopping Cart, I found this article helpfull

Hope it helps

Hi Folks @dantidmas88 @clement.trubert!

I can think of a few ways that would still be messy in the dB at the end of the day. Perhaps the use of a plugin might help though. This one is a great option by @gaurav (scroll down to repeating groups number 16 and expand “see it in action” Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.

Hope this helps! :+1:

I ended up handling it like this:

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.

If anyone needs help in the future hit me up.

@dantidmas88

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.

Glad to hear things worked out :slight_smile:

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 :smiley:

1 Like

“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.”

Do you mean the BDK plugin for RG? I am also creating a cart and faced similar question.

Yes I meant that plugin

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.