完成付款后停止Magento发送自动发票

时间:2013-01-25 20:55:15

标签: magento paypal payment invoice

问题是,我想通过API手动发送它们,因为在我的国家/地区,发票是一个法律约束的订单。 有没有办法做到这一点?

感谢您的帮助!

2 个答案:

答案 0 :(得分:5)

转到系统 - >配置 - >销售电子邮件并停用“发票”。

Cheerz 西蒙

答案 1 :(得分:1)

我认为公认的答案不是解决问题的最佳方法。如果您完全从后端禁用自动交易电子邮件,则也无法手动触发它们或在自定义模块中使用它们。这意味着,如果您需要从头开始禁用的每封交易电子邮件,都必须以magento标准的方式发送给其他人,这在事后需要付出大量的维护工作。

我想出的解决方案是在发票创建时以编程方式禁用发送电子邮件,并在自定义观察者事件中利用默认发件人类别。在我们的情况下,我们希望在创建货件后发送发票电子邮件。

您可以通过重写\ Magento \ Sales \ Model \ InvoiceOrder来做到这一点。找到行

$this->notifierInterface->notify($order, $invoice, $comment);

然后将其删除。 如果要触发电子邮件,仍然可以使用InvoiceSender中的标准“发送”功能从任何位置进行。在我们的例子中,我们触发了来自观察者的电子邮件,如下所示:

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;

class SendInvoiceWithShipment implements ObserverInterface
{
    protected $_invoiceSender;

    public function __construct(
        InvoiceSender $invoiceSender
    ) {
        $this->_invoiceSender = $invoiceSender;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getShipment()->getOrder();
        $invoices = $order->getInvoiceCollection();
        foreach ($invoices as $invoice) {
             // this is where the magic happens
             $this->_invoiceSender->send($invoice);
        }               


    }
}

观察员由事件sales_order_shipment_save_after触发

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name='sales_order_shipment_save_after'>
        <observer name='SendInvoiceWithShipment' instance='Vendor\Module\Observer\SendInvoiceWithShipment'
        />
    </event>
</config>

您可以为每个交易电子邮件执行此操作。

相关问题