Magento 2 - Customer click stock alert on product page after logged in it shows 404 page
-
26-02-2021 - |
Frage
When customer click subscribe to price or stock notification (on product page) then after login, gets redirected to the 404 page.
Any help, experience and knowledge sharing would be appreciated.
Keine korrekte Lösung
Andere Tipps
I also encountered this issue on 'stock alert' on Magento 2.3.1 CE.
The problem is that upon successful login, Magento tries to get the url (productalert/add/stock/* or productalert/add/price/* respectively).
Since Magento\ProductAlert\Controller\Add\Stock implements HttpPostActionInterface, it returns a 404 (no route found), as HttpPostActionInterface does not allow get requests. This also applies for Magento\ProductAlert\Controller\Add\Price.
You will have to override this controller and remove the implementation of HttpPostActionInterface.
Create controller action by copying the price or stock actions and remove implements. I will be using stock as the example below:
Before:
namespace Magento\ProductAlert\Controller\Add;
...
/**
* Controller for notifying about stock.
*/
class Stock extends AddController implements HttpPostActionInterface
After:
namespace Vendor\Module\Controller\Add;
...
/**
* Controller for notifying about stock.
*/
class Stock extends AddController
In your di.xml:
<preference for="Magento\ProductAlert\Controller\Add\Stock" type="Vendor\Module\Controller\Add\Stock" />
Run cache:flush and setup:di:compile once changes are in place.
Good luck!