以编程方式创建发票时给客户发送电子邮件


14

以编程方式创建发票时,如何使系统通过电子邮件将发票发送给客户?

$order=Mage::getModel('sales/order')->load($orderid); 
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
    Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
                   ->addObject($invoice)
                   ->addObject($invoice->getOrder());
$transactionSave->save();

Answers:


12

之后$transactionSave->save();

$invoice->getOrder()->setIsInProcess(true);
$history = $invoice->getOrder()->addStatusHistoryComment(
    'Programmatically created invoice', true
);
$invoice->sendEmail(true, '');
$order->save();

这将指示Magento通过电子邮件将发票发送给客户。


发送电子邮件是否需要设置状态?
Qaisar Satti 2015年

是的,这是Magento规范。如果未包括在内,则该订单将不会设置为正在处理(应立即开具发票)。
Moose
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.