0

I have the following in my di.xml

<type name="Magento\Sales\Model\Order">
    <plugin name="Module_OrderAfterSave" type="Vendor\Module\Plugin\OrderAfterSave" sortOrder="10" disabled="false" />
</type>

If I pay via credit card or by check/money order then my plugin works and my function gets call.

However if I pay via Paypal my afterSave function never gets called. Anyone know why?

The orders for paypal are going through fine its just not running my plugin :-(

1 Answer 1

0

I'd argue against using the save method for any instance (for plugins, preferences/overrides, anything) that inherits from AbstractModel as it is deprecated because entities must not be responsible for their own persistence.

That aside, these options should work for any payment method:

Option 1

You could create a plugin for the place() method in Magento\Sales\Model\Order instead:

Place Method

Option 2

Alternatively, you could use the "after" observer: sales_order_place_after


I will say, I'm a bit at a loss as to how you were even able to get your plugin to run seeing as Magento's core functionality (I'm looking int 2.2.1) doesn't use (or at least I can't find where it uses) save() to save the order (see Magento\Quote\Model\QuoteManagement for more details: https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Quote/Model/QuoteManagement.php#L513)

But I digress...

Definitely try one of the two options (I prefer plugins over observers)

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.