Hi, I think you should store price of single product in OrderItem entity, because when the price of the product changes, the order will show the wrong price ;)
Hello @pelkas. The price is always calculated at runtime by the getTotal() method in the OrderItem entity. The price is therefore up to date. An OrderItem contains a product and a quantity. The item price depends on the quantity of products that the user has chosen.
The price of the product may change between placing an order and payment. If we do not save the price of the order when placing the order, we will calculate it again from the changed price of the product when paying. Additionally, if we display orders in some administration panel, their price will change if we recalculate them each time using the getTotal() method.
The price should always be recalculated until checkout. This tutorial is about the shopping cart and should be kept simple for learning to code with Symfony. As I wrote in the introduction, the checkout and order process are not supported.
Hi, I think you should store price of single product in OrderItem entity, because when the price of the product changes, the order will show the wrong price ;)
Hello @pelkas. The price is always calculated at runtime by the
getTotal()
method in theOrderItem
entity. The price is therefore up to date. AnOrderItem
contains a product and a quantity. The item price depends on the quantity of products that the user has chosen.The price of the product may change between placing an order and payment. If we do not save the price of the order when placing the order, we will calculate it again from the changed price of the product when paying. Additionally, if we display orders in some administration panel, their price will change if we recalculate them each time using the getTotal() method.
The price should always be recalculated until checkout. This tutorial is about the shopping cart and should be kept simple for learning to code with Symfony. As I wrote in the introduction, the checkout and order process are not supported.
Oh, sure. My brain seeing the Order and OrderItem entities automatically found that this is the place to hold the order price. Sorry to bother you.
Cheers :)