0

I am trying to validate my configuration before save but it does not work on website scope.

It works if i choose default config scope.

Here is my code.

 <?xml version="1.0"?>
<config>
<sections>
 <payment>
 <groups>
 <banktransfer>
 <fields>
 <showinfrontend translate="label">
 <label>Enabled On Front-End</label>
 <frontend_type>select</frontend_type>
 <source_model>adminhtml/system_config_source_yesno</source_model>
 <sort_order>1</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </showinfrontend>
 <partpayment translate="label">
 <label>Partpayment Method</label>
 <frontend_type>select</frontend_type>
 <source_model>bankpayment/partpayment</source_model>
 <backend_model>bankpayment/system_config_backend_validatepayment</backend_model>
 <sort_order>1</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </partpayment>
 </fields>
 </banktransfer>
 </groups>
 </payment>
 </sections>
</config>

Model file is as below.

 <?php
class Kgn_Bankpayment_Model_System_Config_Backend_Validatepayment extends Mage_Core_Model_Config_Data
{
 protected function _beforeSave()
 {
 echo "<pre/>";print_r(Mage::app()->getRequest()->getPost());exit;
 $value = $this->getValue();
 $totalpartCollection = Mage::getModel('pdftemplate/totalpart')->getCollection()
 ->addFieldToFilter('payment_id','banktransfer');
 $resource = Mage::getSingleton('core/resource');
 $writeConnection = $resource->getConnection('core_write');
 $table = $resource->getTableName('pdftemplate/totalpart');
 foreach($totalpartCollection as $totalpart){
 $id = $totalpart->getId();
 if($value == $id){
 $query = "UPDATE {$table} SET status = 1,is_default=1 WHERE totalpartrule_id = "
 . (int)$id;
 $writeConnection->query($query);
 }else{
 $query = "UPDATE {$table} SET status = 2,is_default=0 WHERE totalpartrule_id = ". (int)$id;
 $writeConnection->query($query);
 }
 }
 }
}
asked Jul 20, 2017 at 7:45

1 Answer 1

1

Got the answer.

But it is strange when i choose website or store view scope and only one of checkbox checked near form field then it is not working if i uncheck all the checkbox and save then it is working. If anyone know how this is actually working please write note here for understand.

Here Is Screenshot

answered Jul 20, 2017 at 8:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.