2

I am trying to override the "customer-edit-post" controller but am getting 500 Internal server error with following script.

di.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
 <preference for="Magento\Customer\Controller\Account\EditPost" type="VestricsM2\Connector\Controller\Index\Post" />
</config>   

Contoller: PackageName\ModuleName\Contoller\Index\Post.php

<?php

  namespace VestricsM2\Connector\Controller\Index;

  class Post extends \Magento\Customer\Controller\Account\EditPost{

     protected $logger;

     protected $resourceConfig;

     public function __construct(
                    \Magento\Framework\App\Action\Context $context
                   ) {

       parent::__construct($context);
     }

    public function execute(){
       echo "Testtttt"; exit;
     }
   }
2
  • And now I'm trying to think what our best practice is for overriding a controller action. You have three options.
    – benmarks
    Apr 22 '17 at 14:25
  • Can you please follow @Kishan Patadia post exatly
    – Ramesh
    Apr 23 '17 at 13:12
2

Update your di.xml as follows.

<?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\Customer\Controller\Account\EditPost" type="VestricsM2\Connector\Controller\Index\Post" />
</config> 

Also remove constructor from controller class.

2
  • not showing any error but it's not going to my custom controller. the customer details updating
    – Ramesh
    Apr 11 '17 at 13:28
  • @Ramesh Have you solved this problem, same issue is with me if you can help Jan 31 '18 at 13:28
2

Your constructor needs to match the original constructor so in your case you can simply remove your __construct method here as it's useless.

1
  • not showing any error but it's not going to my custom controller. the customer details updating
    – Ramesh
    Apr 11 '17 at 13:24
0

This below script is working at di.xml

<?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\Customer\Controller\Account\EditPost" type="\VestricsM2\Connector\Controller\Index\Post" />
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.