Magento :Difference between Override and Rewrite

As Magento says don’t change the core files, so there are two ways you can change core files and for Block/Helper/Model classes.

Definations:-

  • Override :

When we use design fallback mechanism then we are doing override

  • Rewrite :

When we rewrite magento Core classes in our class then we are doing rewrite.

Example of Override :

If i need to override app/code/core/Mage/Catalog/Block/Product/List.php file then I copy in my local module with same path shown below app/code/local/Mage/Catalog/Block/Product/List.php

Note :- This is not Suggested By magento But you can do that way.

Example Of Rewrite :

If I want to rewrite this block class Mage_Adminhtml_Block_Sales_Order_Create then I code in my module config.xml Like Below.

   <global>
        <blocks>
            <adminhtml>
                <rewrite>
                   <sales_order_create>Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create</sales_order_create>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>

And In my class Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create

I code Like Below

class Trimantra_Smallchanges_Block_Adminhtml_Sales_Order_Create extends Mage_Adminhtml_Block_Sales_Order_Create {
           //My Function Or funcions That I want to Rewrite..
}

These are two ways we can customize core classes without changing core files

Overwrite module phtml file and re-write in own theme Magento 2

Some day ago I am facing one issue in magento 2  with overwrite module’s PHTML file in my custom theme,

So  here is the solution ,

Steps,

  1. Copy the Phtml file from module (For module location On template path hint)
  2. go to MAGENTO_ROOT/app/design/frontend/VENDOR/YOUR_THEME/MODULE_NAME/templates/filename.phtml

Here MODULE_NAME is your module name from you copy the phtml file In my case its Magento_Search.

 

 

Error after Magento 2 upgrade command

After firing this command from your terminal  “php bin/magento setup:upgrade" If you get blank screen or your website crash and you get error in your log file, then just follow below steps to solve the issue.

Here the simple steps are

  1. Delete the “di” folder located in var directory via cpanel or FTP
  2. Log into your terminal via ssh access and go to your magento root directory
  3. Run this command to change directory command: “cd bin”
  4. Then run this command “sudo ./magento setup:di:compile”
  5. Go back to your magento root directory
  6. Finally give file/directory permissions through command.
  7. Clear the cache and check your website is working now.