Resend order mails
it would be nice to have the possibility to resend the order mail to customer. A customer deleted his mail and asks me to resend.
As far as I can see is this not easy to integrate at the moment.
The process looks as follows:
During the order the FinishEvent is dispatched:
https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Classes/Controller/Cart/OrderController.php#L234
This triggers the EventListener Order/Finish/Email.php:
https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Classes/EventListener/Order/Finish/Email.php#L23-L27
... which executes sendBuyerMail():
https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Classes/EventListener/Order/Finish/Email.php#L49-L56
... which is using the MailHandler's method sendBuyerMail():
https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Classes/Service/MailHandler.php#L292-L310
As the referenced lines show needs the MailHandler the cart object. But this does no longer exist because it does not get stored. I cannot see how this could be solved.
The scope to refactor this seems quite big and no other seemed to miss the feature. I would propose to close this issue. @extcode do you agree?
But a question I got: Why is the cart not stored?
Why we should store the cart (session) to the database? Perhaps one can do this with an own Event. There is an model for storing the cart to database, but this is intended to store the cart while the customer was redirected a payment provider. In error case the cart can be restored from there.
I it should be possible to add a button (to the backend) which directly instantiate the MailHandler or trigger an event. I think the MailHandler can be used for that process, because $this->cart isn't a hard requirement. It is not an constructor argument, but will be set by $mailHandler->setCart($cart). It's then only assigned to the view (FluidEmail). So if the email template do not use/require any information from the cart session, you will be save.
You may also want to have a separate template for the resend that contains different wording and makes it clear that it is a resend of the email and not a new order. This could probably also be solved.
I just realized that there are two Cart:
- https://github.com/extcode/cart/blob/main/Classes/Domain/Model/Cart.php
- https://github.com/extcode/cart/blob/main/Classes/Domain/Model/Cart/Cart.php
The first is the one which could be stored by a payment provider. But the second is needed. And it is really needed because it stores the currency (cart.currency) and the summary data (cart.net, cart.gross, ...) of the order. This is heavily used in the email template, e.g. here:
https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Resources/Private/Partials/Mail/CartSummary.html#L17
Follow-up: It is possible to solve this. Maybe the email-templates should even be cleaned up (not sure). Because: All those information are stored in the table tx_cart_domain_model_order_item.
These information are persisted, this is used in the backend: https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Resources/Private/Partials/Backend/Order/Show/CartTable/Footer.html#L10
... and imo should anyway also be used in the emails!?
Yes. I think we can try to get rid of properties of the cart object in email templates. Most should be easily replaceable.