As of Commerce 2.11, orders get automatically placed, as soon as they are paid in full: #2934647: The order can stay unplaced after an offsite payment
After updating to 2.11, we had the same problems with all PayPal orders (express checkout):
- The "place" event gets fired twice
- The "total_paid" value of the order is empty
This clearly looked as a typical double-save problem. And so it is: The onReturn() callback sets data on the order and saves the order afterwards. This save call causes the problems.
I've had a closer look and saw that saving isn't necessary at all. Setting the data on the order is enough, it will be saved by Commerce anyway. I'll add a patch here and also talk with @bojanz to clarify the interface api comment more if necessary
Comments
Comment #2
agoradesign commentedComment #3
agoradesign commentedComment #4
agoradesign commentedadded #3011667: Saving the order before its payment in PaymentGateway::onReturn() can cause data loss as related issue
Comment #5
bojanz commentedIt's odd that the paid event gets fired twice, we have protection against that (in OrderStorage), how is it bypassed?
Comment #6
TheWinkingSkeever commentedTHANK YOU!!
I was getting duplicate receipt emailed out whenever using the express checkout. Commenting out that
//$order->save();solved my issue. Everything else appears to be working fine as well.Comment #8
bojanz commentedCommitted the #2 patch with a comment tweak. Even with the Commerce bug fixed, we shouldn't be saving the order here.