DEV Community

Discussion on: Creating Cart Entities | Building a Shopping Cart with Symfony

Collapse
 
pelkas profile image
Łukasz Kuliński

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 ;)

Collapse
 
qferrer profile image
Quentin Ferrer

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.

Collapse
 
pelkas profile image
Łukasz Kuliński

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.

Thread Thread
 
qferrer profile image
Quentin Ferrer

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.

Thread Thread
 
pelkas profile image
Łukasz Kuliński

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