Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resend order mails #315

Open
slowhand11 opened this issue Nov 26, 2020 · 6 comments
Open

Resend order mails #315

slowhand11 opened this issue Nov 26, 2020 · 6 comments
Labels
enhancement needs feedback The author of the issue needs to add more information

Comments

@slowhand11
Copy link

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.

@rintisch
Copy link
Collaborator

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:

$finishEvent = new FinishEvent($this->cart, $orderItem, $this->configurations);

This triggers the EventListener Order/Finish/Email.php:

public function __invoke(FinishEvent $event): void
{
$this->cart = $event->getCart();
$orderItem = $event->getOrderItem();
$settings = $event->getSettings();

... which executes sendBuyerMail():

protected function sendBuyerMail(Item $orderItem): void
{
$mailHandler = GeneralUtility::makeInstance(
MailHandler::class
);
$mailHandler->setCart($this->cart);
$mailHandler->sendBuyerMail($orderItem);
}

... which is using the MailHandler's method sendBuyerMail():

public function sendBuyerMail(Item $orderItem): void
{
if (empty($this->getBuyerEmailFrom()) || empty($orderItem->getBillingAddress()->getEmail())) {
return;
}
$status = $orderItem->getPayment()->getStatus();
$fromAddress = new Address($this->getBuyerEmailFrom(), $this->getBuyerEmailName());
$email = new FluidEmail();
$email
->to($orderItem->getBillingAddress()->getEmail())
->from($fromAddress)
->setTemplate('Mail/' . ucfirst($status) . '/Buyer')
->format(FluidEmail::FORMAT_HTML)
->assign('settings', $this->pluginSettings['settings'])
->assign('cart', $this->cart)
->assign('orderItem', $orderItem);

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?

@rintisch rintisch added the needs feedback The author of the issue needs to add more information label Oct 17, 2024
@rintisch
Copy link
Collaborator

But a question I got: Why is the cart not stored?

@extcode
Copy link
Owner

extcode commented Oct 17, 2024

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.

@rintisch
Copy link
Collaborator

rintisch commented Oct 17, 2024

I just realized that there are two Cart:

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:

<cart:format.currency currencySign="{cart.currencySign}">{cart.net}</cart:format.currency>

@rintisch
Copy link
Collaborator

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:

<cart:format.currency currencySign="{orderItem.currency}">{orderItem.net}</cart:format.currency>

... and imo should anyway also be used in the emails!?

@extcode
Copy link
Owner

extcode commented Oct 17, 2024

Yes. I think we can try to get rid of properties of the cart object in email templates. Most should be easily replaceable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs feedback The author of the issue needs to add more information
Projects
None yet
Development

No branches or pull requests

3 participants