Stefan Brendle
Stefan Brendle

Reputation: 1564

Magento: How to check if a value has changed in an order

I'm working on an order import connector to magento. To improve performance I only want to load orders, which were not loaded before. This would be no problem, just save the order id and that's it. But if there are changes, for example the billing address was changed in the magento backend or the order status was set to another, it will not be recognised.

My idea was to look for a "updated_at" column and I expected, that Magento updates this value every time if there was any change according to the order - no mather, if it's the order status or the billing/shipping address.

Fortnunately there is an updated_at column, but if I change the billing address for example, the new date was not set to the updated_at column. My new billing_name is foundable via "phpMyAdmin" in the tables "sales_flat_order_grid" and "sales_flat_order_address". In the first one there's also a updated_at column (which contains also the old value, not the real "updated time"), in the second there isn't a updated_at column.

Is there a "updated-at"-column for the whole order? I know, I can do similiar things with magento-events, mysql triggers or overwrite the responsible magento class, but I would prefer to do it with a standard Magento installation.

Thank you! :)

Upvotes: 2

Views: 1945

Answers (2)

Jianwu Chen
Jianwu Chen

Reputation: 6023

I checked the source code of Varient_Object, seems it won't automatically be set when you set some attributes. Instead you have to explicitly call: flagDirty($field, $flag=true).

Edited: Unfortunately, even flagDirty() method doesn't work. The _dirty field is never initialized. Seems it's a bug.

However, you can use hasDataChanges(), instead.

Upvotes: 0

Michael Leiss
Michael Leiss

Reputation: 5670

I would check the model via isDirty(). Since this method is in Varien_Object you should be good to go...

Good luck!

Upvotes: 1

Related Questions