获取产品变更 [英] Get product changes

查看:59
本文介绍了获取产品变更的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是:

在向系统管理员日志和他莫名其妙改变产品.

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

推荐答案

您可以通过对象的 方法.获取对象的好时机是通过它的save_before事件,因此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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆