使用API​​更新产品数量的Magento销售订单发票无法正常工作 [英] Magento Sales Order Invoice with product quantity updation using API not working properly

查看:92
本文介绍了使用API​​更新产品数量的Magento销售订单发票无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Magento应用程序,并且打算使用Magento API创建销售订单发票.

I'm creating a Magento application and I'm planing to create sales order invoice by using Magento API.

这是我用于发票创建的伪代码.问题在于它创建了一张发票,但是该发票始终为空白(不显示产品和数量)

Here is my pseudo code for my invoice creation. The problem is it creates an invoice but that invoice is always blank (not showing products and quantity)

<?php 

$proxy = new SoapClient('http://myurl/api/soap?wsdl');
$sessionId = $proxy->login('apiuser', 'apikey');

// item array with sku and quantity
$invoiceItems = array(
    '002' => '1', '003' => '1', '004' => '1', '005' => '1'
);

// Create new invoice
$newInvoiceId = $proxy->call($sessionId, 'sales_order_invoice.create', array($saleorderno, $invoiceItems, 'Invoice Created', true, true));

?>

但是当我创建这样的销售订单发票时(销售订单的数量没有变化),它可以正常工作

But when I'm creating an sales order invoice like this (there's no changes in quantity from sales order), it works properly

$newInvoiceId = $proxy->call($sessionId, 'sales_order_invoice.create', array($saleorderno, array(), 'Invoice Created', true, true));

我的代码是否有任何错误? 有人可以给我一些建议吗?

Is there any mistakes with my code? Can any one give some advice for me?

推荐答案

在数组变量"$invoiceItems"中,您将提供以下值:-

In the array variable "$invoiceItems", you are providing this value:-

$invoiceItems = array(
    '002' => '1',
    '003' => '1',
    '004' => '1',
    '005' => '1'
);

以上数组的键必须对应于订单商品ID,而不是商品SKU.这意味着每下一个订单,每个订购的商品都会获得其唯一的订购商品ID,该ID与对应的SKU或商品ID完全不同.

The keys for the above array must correspond to the Order Item ID and not to the Item SKU. This means that whenever an order is placed, each ordered item get its own unique Order Item ID, which is not at all same as that of the corresponding SKU or the corresponding Product ID.

因此,您需要从订单ID"加载订单集合",并按如下所示获取项目集合"列表:-

So to get this, you need to load the Order Collection from the Order ID, and fetch the Items Collection list as below:-

$saleorderno = 'SOME VALID ORDER INCREMENT ID';
$order = Mage::getModel('sales/order')->loadByIncrementId($saleorderno);

$orderItems = $order->getAllItems();
$invoiceItems = array();

foreach ($orderItems as $_eachItem) {
    $invoiceItems[$_eachItem->getItemId()] = $_eachItem->getQtyOrdered();
}

$newInvoiceId = $proxy->call($sessionId, 'sales_order_invoice.create', array($saleorderno, $invoiceItems, 'Invoice Created', true, true));

现在上面的代码应该对您有用.

Now this above code should work for you.

希望有帮助.

这篇关于使用API​​更新产品数量的Magento销售订单发票无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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