How to extend magento part 1

Every framework based on which you build you project, needs to be extended. In this case we are going to see how to extend the functionality on magento using plugin feature.

I will start by showing what not to do in order to extend the functionality of magento. Lets say that you have to add some feature on the following controller of magento \Magento\Checkout\Controller\Cart\Add. Controller has a function execute and your wish to is add some validations before this piece of code could be execute. One of the thing which jumps in the mind of programmers is that I could extend this class and ask magento to load my class whenever the controller is called. What you could try to do is listed below

Note: never ever like this

class MyAdd extends \Magento\Checkout\Controller\Cart\Add
{
    public function execute()
    {
        // do my checks here if everything is ok i will call parent execute
        parent::execute();
    }
}

Part 2

what clients say about us

Client testimonials

Our sites look great and run smoothly. Thanks for all your hard work and patience in getting us to where we are today.

contact us

Contact Us

If you have questions or want us to send you a quote for project please email us.

latest news

Articles

PHPUnit mock magic functions
Learn more about PHPUnit Partial Mock.