【问题标题】:Stop Magento sending auto invoice after completed payment完成付款后停止 Magento 发送自动发票
【发布时间】:2013-01-09 21:56:00
【问题描述】:

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

感谢您的帮助!

【问题讨论】:

    标签: magento paypal payment invoice


    【解决方案1】:

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

    欢呼 西蒙

    【讨论】:

    • 抱歉不是这样。它只是不再发送电子邮件,但仍会创建它们并将状态设置为“已完成”,这是错误的。
    • 好的,但那是你的问题 :) 问一个新的,然后
    【解决方案2】:

    我不认为接受的答案是解决问题的最佳方法。如果您从后端完全禁用自动交易电子邮件,您也无法手动触发它们或在您的自定义模块中使用它们。这意味着,如果您需要在另一个时间点将其作为 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>
    

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

    【讨论】:

    • ...但是您意识到这个问题是针对 Magento 1 提出的,对吧? ;) 您的解决方案很好,但仅适用于 Magento 2。
    • 此解决方案还可以阻止订单电子邮件
    • @DushyantJoshi 由于仅更改了发票模型,因此所有其他交易邮件都应该可以正常工作。您是否仔细检查了配置?
    • @Tobi 通过评论$this-&gt;notifierInterface-&gt;notify($order, $invoice, $comment); 它甚至还发送发票电子邮件。
    猜你喜欢
    • 2015-10-09
    • 2016-04-04
    • 2016-06-26
    • 1970-01-01
    • 2012-04-22
    • 2016-03-17
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多