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:
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-628467cd30796752650690/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...