I've hit an issue trying to add a new action to an existing route in Magento 2.
I've created a new module, registered it and created a new action extending the existing add to cart functionality. I had this working on an existing project, but had to port it over to a new installation. Now when I attempt to POST to the path: <magentourl>/checkout/cart/addbulk, it throws a 404. A GET request will hit the execute method and creates the log entry.
The following are the components of the module.
app/code/Test/Checkout/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="Test_Checkout" schema_version="2.0.0" setup_version="2.0.3">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
app/code/Test/Checkout/etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="checkout" frontName="checkout">
<module name="Test_Checkout" />
</route>
</router>
</config>
app/code/Test/Checkout/Controller/Cart/Addbulk.php
<?php
namespace Test\Checkout\Controller\Cart;
class Addbulk extends \Magento\Checkout\Controller\Cart\Add
{
public function execute()
{
$items = $this->getRequest()->getParam('item', []);
$this->_objectManager->get('Psr\Log\LoggerInterface')>addDebug('Posting data to addBulk');
...
return $this->_goBack();
}
}
I've enabled the module, run bin/magento setup:upgrade, cleared cache and then attempted to post.
When I do a POST, it returns a 404 error, on a GET it creates the log entry as expected.
Does anyone have any idea why this module would not have migrated correctly, or anything else I would need to add to get this working?
Turns out the environment itself was broken. I installed my module on a fresh install of magento 2 successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With