shopware - 重新发送特定订单状态电子邮件,例如订单交付在 Shopware 6 中发货

标签 shopware shopware6

我想知道发送特定订单状态电子邮件是否有更简单的解决方案。

目前我使用以下代码发送例如再次收到“订单已发货”电子邮件。

$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('orderNumber', $orderNumber));
$criteria->addAssociation('orderCustomer.salutation');
$criteria->addAssociation('orderCustomer.customer');
$criteria->addAssociation('stateMachineState');
$criteria->addAssociation('deliveries.shippingMethod');
$criteria->addAssociation('deliveries.shippingOrderAddress.country');
$criteria->addAssociation('deliveries.shippingOrderAddress.countryState');
$criteria->addAssociation('salesChannel');
$criteria->addAssociation('language.locale');
$criteria->addAssociation('transactions.paymentMethod');
$criteria->addAssociation('lineItems');
$criteria->addAssociation('currency');
$criteria->addAssociation('addresses.country');
$criteria->addAssociation('addresses.countryState');

/** @var OrderEntity|null $order */
$order = $this->orderRepository->search($criteria, $context)->first();

$context = new Context(new SystemSource());
$salesChannelContext = $this->orderConverter->assembleSalesChannelContext($order, $context)->getContext();
$salesChannelContext->addExtension(
    MailSendSubscriber::MAIL_CONFIG_EXTENSION,
    new MailSendSubscriberConfig(false)
);
$event = new OrderStateMachineStateChangeEvent(
    'state_enter.order_delivery.state.shipped',
    $order,
    $salesChannelContext
);
$flowEvent = new FlowEvent('action.mail.send', new FlowState($event), [
    'recipient' => [
'data' => [],
'type' => 'default',
    ],
    'mailTemplateId' => $mailTemplateId,
]);

$this->sendMailAction->handle($flowEvent);

最佳答案

鉴于您实际上不想更改状态,这看起来是一个很好的解决方案。

如果您确实需要以编程方式更改状态,您可以使用 StateMachineRegistry 服务。

$transition = new Transition(OrderDeliveryDefinition::ENTITY_NAME, $orderDeliveryId, StateMachineTransitionActions::ACTION_SHIP, 'stateId');
$this->stateMachineRegistry->transition($transition, Context::createDefaultContext());

但是,如果当前状态等于您想要转换到的状态,则预计会抛出 UnnecessaryTransitionException。在执行此操作之前,您必须将状态更改回之前的状态,如果您只想重复发送该邮件,那么您的代码可能不会那么麻烦。

关于shopware - 重新发送特定订单状态电子邮件,例如订单交付在 Shopware 6 中发货,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73193065/

相关文章:

PHP 7 simpleXML fatal error

Shopware6 应用程序使 services.cart 在 Custom Hook 中可用

shopware - 使用 CLI 添加额外的店面 URL

Shopware 6 插件标准所有国家/地区

shopware - 当供应商太大时如何向商店添加插件?

stripe-payments - 如何在shopware 6中使用store-api设置付款详细信息

shopware - 覆盖订单状态输入流程操作的邮件收件人并添加数据

shopware - 在 Shopware 6 中通过 php 创建媒体

Shopware:有条件地取消将产品添加到购物车

php - 如何扩展 Shopware 6 Controller 操作