获取产品变更 [英] Get product changes
问题描述
情况是:
在向系统管理员日志和他莫名其妙改变产品.
Admin logs in to system and he changes product somehow.
例如:
将数量设置为10 添加2张图片 变更说明
Sets qty to 10 Adds 2 images Changes description
有什么方法可以追踪这些变化?嗯,我的意思是准确追踪什么,以及如何管理改变?
Is there any way to track these changes? Well I mean exactly track WHAT and HOW admin changed?
我使用Magento CE 1.6
I use Magento CE 1.6
推荐答案
您可以通过对象的 catalog_product_save_before
事件创建观察者.观察者可能包含以下内容:
You can find the unaltered data through an object's getOrigData()
method. A good time to get the object is through it's save_before event, so create an observer for the catalog_product_save_before
event. The observer might contain the following:
public function onCatalogProductSaveBefore($observer)
{
$product = $observer->getProduct();
if ($product->hasDataChanges()) {
$newValues = array_diff_assoc($product->getData(), $product->getOrigData());
$oldValues = array_diff_assoc($product->getOrigData(), $product->getData());
$added = array_diff_key($product->getData(), $product->getOrigData());
$unset = array_diff_key($product->getOrigData(), $product->getData());
}
}
请注意,$newValues
将包括所有$added
和已更改其值的现有属性.同上,用于
Note that $newValues
will include all of $added
and existing attributes that have had their value changed. Ditto for $oldValues
and $unset
.
这篇关于获取产品变更的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!