Hi Magento Community,
I am trying to create a plugin after the function that gets called when a user goes to reorder a product from their account. However, I have been unable to do so.
The following code is in my di.xml file:
<type name="Magento\Sales\Controller\Order\Reorder">
<plugin name="on_reorder_correct_products" type="Vendor\Module\Plugin\AfterReorder" sortOrder="100"/>
</type>
In the AfterReorder.php file is this function:
public function afterExecute(
$subject, $result
) {
return $result;
}
This never gets called. I checked the namespace and it's correct. There are other plugins that DO get called, which are aroundExecute plugins that are part of magento's company and negotiable quote modules. However, this afterExecute function never gets called. I tried another aroundExecute function instead, but that also doesn't get called.
UPDATE: I found the reason for this was that there is an aroundExecute plugin in the NegotiableQuote module that navigates to the cart page after it is complete, effectively making it impossible for further plugins to execute. Is there a way to call a plugin before this plugin gets executed? None of the Magento plugins that call around the reorder "execute" function have any sortOrder set.
Hello @garney_stimpson
Please create a custom extension and write the below code in etc/di.xml.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Sales\Controller\Order\Reorder"> <plugin name="replaceQuoteItems" type="Magento\NegotiableQuote\Plugin\Sales\Controller\Order\ReorderPlugin" disabled="true" /> <plugin name="replaceOrderItem" type="VendorName\ModuleName\Plugin\Sales\Controller\Order\ReorderPlugin" /> </type> </config>
it will help you!
Thank you
Hello garney_stimpson,
Reorders in Magento 2 help customers to reorder after they complete their purchase. This feature simplifies the process when customers no longer have to fill in all the information if every detail stays the same.
It is a default Magento feature that allows customers to repeat their orders by pressing only one button.
You can follow the below ways to fix the reorder plugin issue,
However, the Reorder button does not appear in the customer account nor on the order view page, but then also Allow Reorder option is enabled.
To Enable reorder in Magento 2:
You can also create a custom extension and write the below code in etc/di.xml,
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Sales\Controller\Order\Reorder"> <plugin name="replaceQuoteItems" type="Magento\NegotiableQuote\Plugin\Sales\Controller\Order\ReorderPlugin" disabled="true" /> <plugin name="replaceOrderItem" type="VendorName\ModuleName\Plugin\Sales\Controller\Order\ReorderPlugin" /> </type> </config>
Now, run the DI compile process: php bin/magento setup:di:compile
Thus, customers can reorder from their account or order view page when the Magento reorders feature is enabled.
------------------------
Regards,
Rex M