Create module.xml file at app/code/Magemonkeys/RewriteProduct/etc and add the following code inside this file:
1 2 3 4 5 |
<?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="Magemonkeys_RewriteProduct" setup_version="1.0.1"> </module> </config> |
Create registration.php file at app/code/Magemonkeys/RewriteProduct and add the following code inside this file:
1 2 3 4 5 6 7 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkeys_RewriteProduct', __DIR__ ); |
Create di.xml file at app/code/Magemonkeys/RewriteProduct/etc in order to specify which model to override by using <preference for=””> and <preference type=””>.
Add the following code inside dl.xml file: The purpose of creating this file is to override di.xml file
1 2 3 4 |
<?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="Magemonkeys\RewriteProduct\Model\Catalog\Product" /> </config> |
Now, create Product.php file at app/code/Magemonkeys/RewriteProduct/Model/Catalog and add the following code in this file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php namespace Magemonkeys\RewriteProduct\Model\Catalog; class Product extends \Magento\Catalog\Model\Product { public function getName() { return $this->_getData(self::NAME) . ' + Override Model - Name'; } public function getSku() { return "123-Override Model - Sku"; } } |
Run the following commands in the Magento 2 root directory:
1 2 3 4 5 |
php bin/magento module:enable Magemonkeys_RewriteProduct php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento cache:clean php bin/magento cache:flush |
Now, it’s time to check the result!
Go to the product page and you should see as below:
[crayon-63e09fa5d2663403663000/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.