magento以编程方式创建未付款发票 [英] magento create unpaid invoice programmatically

查看:111
本文介绍了magento以编程方式创建未付款发票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在由自己的观察者以编程方式为sales_order_save_after事件创建发票.

I'm creating invoices programmatically by an own observer for the sales_order_save_after event.

不幸的是,发票被立即标记为已付款.

Unfortunately, the invoice is immediately marked as paid.

如何获得新发票仍处于打开状态并且管理员必须将其设置为已付款状态?

How can I achieve that the new invoice is still open and a admin has to set it to paid state?

到目前为止,我的代码:

My code so far:

$invoiceId = Mage::getModel('sales/order_invoice_api')
                    ->create($order->getIncrementId(), array());
$invoice = Mage::getModel('sales/order_invoice')
                    ->loadByIncrementId($invoiceId);
$invoice->capture()->save();

为了使我对urfusion答案的评论易于理解,请参见以下代码段:

To make my comment to urfusion's answer understandable, here the code snippet:

  public function order_placed($observer) {
    $event = $observer->getEvent();

    // ....

    $emailInvoice = false;
    $captureInvoice = false;

    $order = Mage::getModel("sales/order")->load($data['entity_id']);
    if($order->canInvoice() and $order->getIncrementId())
    {
        $invoiceApi = Mage::getModel('sales/order_invoice_api');
        $invoiceId = $invoiceApi->create(
                                $order->getIncrementId(),
                                array(),
                                Mage::Helper('sales')->__('Pending Invoice created!'),
                                $emailInvoice,
                                false);

        if($captureInvoice)  {
            $invoiceApi->capture($invoiceId);
        }
    }
  }

推荐答案

主要取决于将发票设置为paidpending的付款方式设置.

mainly it depend on the payment method settings that your invoice will be set as paid or pending.

如果指定了付款方式:

检查以下代码以将发票设置为待处理.

check the below code for setting invoice as pending.

protected $_canCapture                  = true;
protected $_canCapturePartial           = true;

$emailInvoice = true;
$captureInvoice = false;

$invoiceApi = Mage::getModel('sales/order_invoice_api');
$invoiceId = $invoiceApi->create(
    $order->getIncrementId(),
    array(),
    Mage::helper('sales')->__('Pending Invoice created!'),
    $emailInvoice,
    false
);

if ($captureInvoice) {
    $invoiceApi->capture($invoiceId);
}

这篇关于magento以编程方式创建未付款发票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆