Configuration of Module:

Create module.xml in
app/code/Techievolve/Product/etc and add the following code to it:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Techievolve_Product" setup_version="1.0.1">
    </module>
</config>

Module Registration:

Create registration.php in
app/code/Techievolve/Product and add the following code to it:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Techievolve_Product',
__DIR__
);
&#91;/code&#93;

<strong>Override di.xml</strong>

Create di.xml  in app/code/Techievolve/Product/etc in order to specify which model to override by using   and .

Add the following code to the di.xml file:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Model\Product" type="Techievolve\Product\Model\Catalog\Product" />
</config>

Override Product.php

<?php

namespace Techievolve\Product\Model\Catalog;

class Product extends \Magento\Catalog\Model\Product {

    public function getName() {
       return $this->_getData(self::NAME) . ' + Test Text';
    }

    public function getSku() {
    
        return "Test-Demo";
    }
}

Run the following commands using ssh or terminal:

php bin/magento module:enable Techievolve_Product
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Categories: Magento2

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *