Question

I recently made a module that calculates the real gross margin for every order and order_item based on shipping cost data I import. I did this by adding 2 columns to the sales_flat_order table and the sales_flat_order_item table. This seemed to work great, until I realized that when I saved the imported data, it also updated the updated_at value. Since this was the first import of all orders, they all now report having been updated today. This is throwing off reports and other shipping software that syncs with it.

This brings me to 2 questions:

  1. Is adding a column to an existing table (in this case, the sales tables) a major NO-NO?
  2. If not, is there a way to set the data that doesn't increase the updated_at value?

If it helps, the code that actually writes the data is inside my IndexController.php file. It loops through the collection of orders and the items within those orders and sets the necessary values using something like $order->setGrossMargin($orderGM)->save();. I imagine it is the call to save() that is doing it, but I'm not sure the right way around this problem.

In the mean time, I'm working on a solution in which I import the data to custom tables and only read from the sales tables when necessary. Either way, it's a good exercise :)

Brian

Was it helpful?

Solution

Instead of calling save(), did you try:

$order->getResource()->saveAttribute('gross_margin')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top