0

How can i write below script in magento 2

class NameSpace_Notification_Model_App extends Mage_Core_Model_Config_Data
 {

   public function save(){ } 

 }
  • Do you want to override that class Mage_Core_Model_Config_Data and save method? – Miroslav Petroff Nov 15 '16 at 7:56
1

in magento 2 you can write code

 <?php
    namespace NameSpace_Notification_Model;

    class App extends \Magento\Config\Model\Config
    {


    public function save(){ } 

    }

Note::your __construct must be same with \Magento\Config\Model\Config __construct

0

You have to write like this,

namespace {NameSpace}\{Module}\Model;

class App extends \Magento\Config\Model\Config
{
   public function __construct(
            \Magento\Framework\App\Config\ReinitableConfigInterface $config,
            \Magento\Framework\Event\ManagerInterface $eventManager,
            \Magento\Config\Model\Config\Structure $configStructure,
            \Magento\Framework\DB\TransactionFactory $transactionFactory,
            \Magento\Config\Model\Config\Loader $configLoader,
            \Magento\Framework\App\Config\ValueFactory $configValueFactory,
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            array $data = array()
    ) {
        parent::__construct($config, $eventManager, $configStructure, $transactionFactory, $configLoader, $configValueFactory, $storeManager, $data);
    }

    public function save(){ } 
...
}

and in your etc/di.xml file you have to override

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <preference for="Magento\Config\Model\Config" type="{NameSpace}\{ModuleName}\Model\{Your_Model_File}" />
</config>

You can also refer this url.

After that you have to recompile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.