Adyen / adyen-shopware5

MIT License
11 stars 12 forks source link

OrderId always null #110

Closed Gugiman closed 3 years ago

Gugiman commented 3 years ago

Hi,

please see this line for reference:

https://github.com/Adyen/adyen-shopware5/blob/7848a158771b244b8dd7b9c80e8bbfecad6101c4/Subscriber/OrderEmailSubscriber.php#L50

When looking into the Shopware 5 code where this event is thrown i don't think there is an orderId accessible:

https://github.com/shopware/shopware/blob/b206fe23b16f8a4eaa91bf825a1f61bba1c3a469/engine/Shopware/Core/sOrder.php#L976

Therefore the orderId is always null, mailtemplate vars are always empty and no mail is sended anyway.

And just a few lines further:

https://github.com/Adyen/adyen-shopware5/blob/develop/Subscriber/OrderEmailSubscriber.php#L59

I saw (via xDebug) that at this specific moment the orderId in s_plugin_adyen_order_payment_info is -1 That means that when we could get the right orderId, we wouldn't find anything.

Gugiman commented 3 years ago

To be a bit more precise.

The screenshot shows a xdebug session where I stopped right after creating an order. The Shopware_Modules_Order_SendMail_Send event just dispatched.

1) The way adyen searches for the orderId results in null (1.1) 2) I wrote a method searching for the orderId by using the ordernumber. Which works (2.1) 3) But although i have an orderId now, it would never find something in s_plugin_adyen_order_payment_info because the order is saved with id -1 in that specific moment.

So the mail variables are not stored and therefore no mail is send later when the notification comes in.

adyen

acampos1916 commented 3 years ago

Hello @Gugiman, thanks for opening this issue.

Could you verify if https://github.com/Adyen/adyen-shopware5/pull/125 solves the problem? We found out that the OrderId is not present at that moment of the order flow as you suggested, so a fallback to the ordernumber was added.

Cheers, Ángel

Gugiman commented 3 years ago

Hi Column "ordermail_variables" gets correctly filled now. But who is responsible for calling /process/return Action for actually sending the mail?

acampos1916 commented 3 years ago

Hello @Gugiman,

Payments will finish in /process/return and the email will be sent based on resultCode (e.g. redirect methods https://github.com/adyen/adyen-shopware5/blob/master/Controllers/Frontend/Transparent.php#L34). For payments that can't confirm the order being fully paid then the trigger will be a notification.

acampos1916 commented 3 years ago

Thanks for checking this. So if understand correctly the email does get sent when the notification is received but the ordermail_variables column is not cleared?

Gugiman commented 3 years ago

Last thing was an error on my own. On *PostDispatch_Frontend_Checkout we alter the sOrderNumber variable. Therefore you can't find the right paymentInfo for sending.

But we fix this on our site. Thank you!

acampos1916 commented 3 years ago

Thanks for checking @Gugiman.

I also believe that I made a mistake, as the notifications are not supposed to trigger the confirmation email after all https://github.com/Adyen/adyen-shopware5/pull/46 it is only based on the payments resultCode.