如何从订单增量ID获取发票ID

时间:2014-07-30 08:41:55

标签: magento

我有100000096的订单增量ID,我想得到它的发票ID,请帮我在magento中实现这个,我试过了

                 $incrementId = '100000096';
               $order = Mage::getModel('sales/order')->load($incrementId);
                   $invIncrementIDs = array();
                     foreach ($order->getInvoiceCollection() as $inv) {
                         $invIncrementIDs[] = $inv->getIncrementId();
              }

但它返回一个空数组。

3 个答案:

答案 0 :(得分:5)

您在load()函数中使用了订单增量ID,您必须使用loadByIncrementId()

尝试使用它 -

$orderid = '100000096'; // order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
if ($order->hasInvoices()) {
    $invIncrementIDs = array();
    foreach ($order->getInvoiceCollection() as $inv) {
        $invIncrementIDs[] = $inv->getIncrementId();
    }
}

echo "<pre>";
print_r($invIncrementIDs);
echo "</pre>";

答案 1 :(得分:1)

试试这个:

$orderIncrementId = '100000004'; // your order increment id

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

if ($order->hasInvoices()) {
    $invIncrementId = array();
    foreach ($order->getInvoiceCollection() as $invoice) {
        $invoiceIncId[] = $invoice->getIncrementId();
    }
}


echo "<pre>";print_r($invoiceIncId);echo '<br>';

Invoice id

获取Invoice incrementId
$incrementId = $invoiceIncId[0];
$invoive = Mage::getModel('sales/order_invoice')->loadByIncrementId($incrementId);
$invoiceId = $invoice->getId();

echo "<pre>";print_r($invoiceId);exit;

答案 2 :(得分:0)

试试这个你不会后悔

$order_id = "type_here_your_orderid";
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
                ->setOrderFilter($order_id)
                ->load();
$invoice_id = $invoices->getData()[0]["increment_id"];
echo $invoice_id;

这就是全部。