0

I seem to be missing something when it comes to overriding controllers. This is a somewhat recurring question in here, but nothing I've found in other questions worked for me, so either they might be a bit outdated or I am missing something obvious. I am on Magento 2.3.4, trying to override Magento's module-contact functionality.

Here's what I've done:

Created a new module in /app/code/vendor/module. Checked that the module shows up in module manager / php magento module:status. Created etc/di.xml with the following code

<?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\Contact\Controller\Index\Post" type="Vendor\Module\Controller\Index\ExtendIndex" />
</config>

Created etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Module" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Contact"/>
        </sequence>
    </module>
</config>

Created /Controller/Index/ExtendIndex.php with minor functionality for testing

namespace Vendor\Module\Controller\Index;
class ExtendIndex extends \Magento\Contact\Controller\Index\Post
{
    public function execute($coreRoute = null)
    {

    echo "1";
        $this->messageManager->addSuccess('Message from new controller.');
        return parent::execute($coreRoute);
    }
}

Then flushed Magento Cache

Despite all that, which seems to be every step needed for this to work, it hasn't, and I've tried all minor variations in terms of code I could think, as it could simply be a "" somewhere that shouldn't be be or similar.

What am I missing here?

1 Answer 1

0

Firstly I see some concern/ The name of the modules folders must be capitalized as follows:

 /app/code/Vendor/Module

The name of the module in the module.xml file be as follows

<module name="Vendor_Module" setup_version="1.0.0">
2
  • Thanks for your reply. But everything on the code is correct, name wise (as in, capitalizations and such). I see some is indeed wrong in the text here but is just because I typed vendor/module when writing the question instead of copy pasting the names. Anyways I double checked that after your reply and still no dice Nov 12, 2021 at 20:32
  • Very important you have Vendor_Module dans module.xml, can you edit the question with the correct code or with the same code you have Nov 13, 2021 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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