Magento 如何仅在管理部分检测更改的字段?

Magento how to detect changed fields only in admin section?

我需要根据更改的自定义字段的值向自定义数据库 table 插入一些值,如果特定的自定义字段值(在自定义运输方式中)有 changed.I 需要检查在我的 Observer.php 事件中,我触发的是 admin_system_config_changed_section_carriers 用于从字段中获取值并将值插入 table

有没有办法做到这一点?

编辑:

这是我的观察者函数

public function handle_adminSystemConfigChangedSection($observer){

        $post = Mage::app()->getRequest()->getPost();
        $firstBarcodeFlatrate = $post['groups']['flatrate']['fields']['barcode_start']['value'];
        $lastBarcodeFlatrate = $post['groups']['flatrate']['fields']['barcode_end']['value'];

        $flatrateRange = range($firstBarcodeFlatrate,$lastBarcodeFlatrate);
        $shippingMethod = 'flatrate';

        foreach($flatrateRange as $barcodes){
            $insertData = array(
                'barcode' => $barcodes,'shipping_method' => $shippingMethod,'status' => 1,
            );
            $model = Mage::getModel('customshippingmethods/customshippingmethods')->setData($insertData);
            try {
                $model->save();
            } catch (Exception $e){
                echo $e->getMessage();
            }
        }

如上所示,每次我保存配置时数据库查询都会更新,但我只需要 运行 查询 iff $firstBarcodeFlatrate 值已更改

我可能会选择两个选项: 1.缓存$firstBarcodeFlatrate的最后一个值 $cacheId = 'first_barcode_flatrate_last_value'; $cache = Mage::app()->getCache(); $lastValue = $cache->load($cacheId); if (!$lastValue) { //We don't have cached last value, we need to run the query and cache it: //Cache the value: $cache->save($firstBarcodeFlatrate, $cacheId, array('first_barcode_flatrate_last_value'), null); //Run the query here } else { //We have last value, we need to check if it has been changed: if($lastValue != $firstBarcodeFlatrate) { //Update the cached value: $cache->save($firstBarcodeFlatrate, $cacheId, array('first_barcode_flatrate_last_value'), null); //Run the query here. } } 选项 2 是创建另一个具有单行和两个字段的 table 或添加另一个系统配置字段来存储上次使用的值。然后在 运行 查询之前,您将检查此值,如果它与 $firstBarcodeFlatrate 不同,您将 运行 查询,否则您不会,尽管我认为缓存会为您完成这项工作.