开发者

Magento Order Table: custom column

开发者 https://www.devze.com 2023-04-03 17:19 出处:网络
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

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


Instead of calling save(), did you try:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消