How to organize and apply delivery fee in an e-commerce
I'm trying to do an e-commerce with *DotNet * and RazorPages.
I have the following contexts in my app: Cart, Ordering, Fullfillment, Invoicing. I have decided that I want to apply a delivery fee to a new order , before the order is "Placed" (i.e., paid for). The idea goes like this:
When a customer goes from shopping cart to checkout, a new order is created and a timer starts, e.g., 15 mins. During this time, the order lines and delivery fee cannot be altered. While timer >0, the order can be placed. If the timer goes to 0, the checkout "session" times out and the order is deleted. The customer is returned to their cart and must go to checkout again, in which case a new order will be created with the current delivery fee.
In my code, DeliveryFee is defined inside a GlobalVariables.cs. I figured it had to be stored in my database, so I've added a DbSet<GlobalVariables> to my ApplicationDbContext. If any of the global variables are updated, create a new record in the db. To get the current values, get the latest record (max id).
Does this way of going about it make sense? I'm sure there are better ways 🙂
0 Replies