Search code examples
shopware6

Possibly wrong transaction status in Shopware 6 mails?


All e-mail templates in Shopware 6 reference the transactions payment name and current state by using the first collection entry order.transactions.first.paymentMethod.translated.name and order.transactions.first.stateMachineState.translated.name.

Is the transaction sorting for e-mails different that the default sorting by createdAt? Because according to all code examples I have found so far (e.g. AccountOrderPageLoader) the transactions are normally sorted by createdAt.

Based on the sortings I would expect e-mails to show a wrong payment method if the customer switches the payment method after ordering.

So my question is: Shouldn't all e-mail templates reference the last entry of the transactions collection to really show the latest state? Or is the sorting for e-mails changed somewhere else?

Thanks for clarification.


Solution

  • I think this is a valid concern but given the standard procedures shouldn't become an issue. This is because when using the StateMachineRegistry to transition from one state to another, the existing state entity is being updated instead of a new one being inserted. So if the transition model is being used as it is intended, there should only be one state per combination of order and payment/delivery method that gets updated, with the former states being persisted as state_machine_history entities to retrace state changes.

    Technically however, given that the associations are instances of OneToManyAssociationField, it is obviously possible to persist multiple entities of order_transaction or order_delivery per order when using the corresponding repositories. I think the reason for this relation model being used was to, in the future, potentially allow multiple delivery/payment methods when placing a single order. However this currently isn't implemented which is why it is important to use the proper services to transition between states as explained.