【问题标题】:create invoice and email in Magento在 Magento 中创建发票和电子邮件
【发布时间】:2012-10-23 07:52:42
【问题描述】:

我想在 Magento 中自动创建发票和电子邮件。发票创建似乎可行,但我正在让电子邮件部分正常工作......

 Mage::app();       
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderid);

    try 
    {
        if(!$order->canInvoice())           {   
            Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
        }

        $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();
    }       
    catch (Mage_Core_Exception $e) {

    }
}

【问题讨论】:

标签: email magento invoice


【解决方案1】:

我知道我的反应有点晚,但对于找到此页面的其他人来说:

您需要添加发送电子邮件的代码。 在注册行之后执行此操作:


$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(true);
$invoice->sendEmail();

setCustomerNoteNotify 用于表示客户是否必须收到电子邮件。

setIsInProcess 会将订单状态更改为处理中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    相关资源
    最近更新 更多