Web Analytics

Fill the form & Get Installation Support





    How to Override Model in Magento 2

    Configuration of Module

    Create module.xml file at app/code/Magemonkeys/RewriteProduct/etc and add the following code inside this file:

     

    Registration of Module

    Create registration.php file at app/code/Magemonkeys/RewriteProduct and add the following code inside this file:

     

    Override di.xml

    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

    Override Product.php

    Now, create Product.php file at app/code/Magemonkeys/RewriteProduct/Model/Catalog and add the following code in this file.

    Launch SSH and Run Commands

    Run the following commands in the Magento 2 root directory:

    Now, it’s time to check the result!

    Go to the product page and you should see as below:

    Are you having any query with your Magento store?
    Fill the form below to hire Magento expert(s).
    Fill the below form if you have any Magento programming need.





      Recent Articles

      Author Info

      Author Image

      Magento Certified Developer

      Hire J. Lakum

      Get a Free Quote





        Connect With Us