How To

How to Override Custom Module’s Controller file in Magento 2

Understanding that each business has its own story, to give a personalized touch to store always ends up with customization & development. Over the time Magento has topped Ecommerce CMS list with its functionality, features and power of extending the native functionalities. Compared to Magento 1, In Magento 2 overriding and manipulating with classes is becoming easier a developer to play quickly. At MageComp, we have never recommended modifying default core functionalities, but we can extend core functionalities using concepts of overriding which is a safe and easy way to achieve customization or development.

The extension plays an important role to achieve customization in Magento 2 but when there are tons of extensions installed within a store environment it creates conflicts with other extensions. At that time to quickly get rid of the problem, the easiest solution comes to mind is to override custom extension controller file. By default, there are three different ways to override core functionalities. Today we will use preference method to override any custom module controller into your extension.

Firstly, we need to notify Magento for overriding functionality by creating ‘di.xml’ at below path.
app\code\Vendor\Extension\etc\di.xml



   

Now, you need to create your extension controller file at the following path by adding your own logic to below code.
app\code\Vendor\Extension\Controller\Adminhtml\Customcontroller\Customaction.php


If you face any issue while implementing this code comment down below. We will help you to fixed it asap.
Happy Coding!
Click to rate this post!
[Total: 12 Average: 3.7]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

3 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

5 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

5 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

6 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

7 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago