Disclaimer: I never wrote a database model regarding a “shopping cart” or “orders”
I think that the price at the time of purchase should be encoded in the purchase data: just like a paper receipt from the store. Let me call it total_price , which represents each detail line on the receipt and should not be confused with total_purchase_price .
That is a fixed amount. It does not matter if the price of the product changes later, and the price changes will not reflect how much was [paid].
Thus, I would have the following fields: product , unit_price , quantity , total_price . A calculated column, such as base_total_price ( unit_price * quantity ), can be easily added if required.
Now, total_price can be a calculated value based on the word base_total_price * precent_discount : but, no matter how it ends, I believe that total_price should exist and should be fixed at the time of purchase. (This means that if it is a calculated column, all inputs are also committed at the time of purchase.)
Addendum: As indicated above, I have never developed such a model before, but one thing that I observed in stores is discounts, which are used as a negative element with cost details. That is, items are bought "at full price", and then the registry adds an entry to offset the costs of each commercial. I do not know the merits / arguments of this approach.
user166390
source share