php - Magento how to detect changed fields only in admin section? -
i need insert values custom database table based on values of changed custom field, if specific custom field value (in custom shipping method) had changed.i need check in observer.php event i'm firing admin_system_config_changed_section_carriers
getting values field , insert values table
is there possible way ?
edit:
here observer function
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 $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(); } }
as can see above database query update each time save configuration need run query iff $firstbarcodeflatrate
value had changed
i go 2 options: 1. cache last value of $firstbarcodeflatrate $cacheid = 'first_barcode_flatrate_last_value'; $cache = mage::app()->getcache(); $lastvalue = $cache->load($cacheid); if (!$lastvalue) { //we don't have cached last value, need run query , cache it: //cache value: $cache->save($firstbarcodeflatrate, $cacheid, array('first_barcode_flatrate_last_value'), null); //run query here } else { //we have last value, need check if has been changed: if($lastvalue != $firstbarcodeflatrate) { //update cached value: $cache->save($firstbarcodeflatrate, $cacheid, array('first_barcode_flatrate_last_value'), null); //run query here. } }
option 2 create table single row , 2 fields or add system config field store last used value. before running query, check value if it's different $firstbarcodeflatrate run query, otherwise won't, though think caching job you.
Comments
Post a Comment