How to update product price without changing a order total. HELP
Application Type
Traditional Web

Hello, I need help with my project. I am trying to update the product price without changing/updating the order total. I need to change the price of a product and the total of the orders that were made before doesn't change. 

Is it possible to do? Thank you.

mvp_badge
MVP
Solution

Hello Tatiana.
Without seeing your code, I can only guess. You have a Product table with the price and a OrderItem connecting products with Orders? Something like this?

When you update product price, the price will change.

What you need is to save the price with the orderitem.
I would also advice you to save the prices in a different table so you can see the history.

It can get a lot more complex, but this will solve your issue.


Extra note: for invoice you must save everything. Not only the price at the moment, but even customer information. That also changes more often than we imagine.

mvp_badge
MVP

In addition to that, if you create history entities for all of these entities, you can refer from the order to specific history records instead of the current records, since history records do not change.

Thank you for your reply. I will try it. 

Hi, I've tried your method but now getting 0 for price when trying to save it. It saved one time so I tried to create an order and then change the price of the product and the order total changed again. 

Now it's saving but I am getting the same effect. Product price updating with the order total. 

I understand why is happening but am not sure how to fix it.  To calculate the order total I am multiplying Product price by quantity. SO when I am updating the Product price, the order total will also change but how to avoid this. 

mvp_badge
MVP

Hi Tatiana,

As Nuno already wrote before, when storing an order, save the price at that moment and the total price (amount * price) in the order line. You should never recalculate amounts when retrieving an order. That's basically rule #1. All information on an order should be stored with the order. Not only to prevent problems like you are having, but also when calculating and displaying discounts.

mvp_badge
MVP

Can you share the OML?

Hello, thank you for your replies and help. I did fix this issue. Now I just need to enter the order total manually but it's ok. Thank you again!
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.