3

I am trying to create an invoice via API. I am using Soap V2 and VB.net. I am have trouble creating an array of OrderItmeIdQty. I keep getting a Null Reference Exception was Unhanded. I do not understand how to create the array. Below is my code so far.

 Dim mage As New MagentoSOAPV2.Mage_Api_Model_Server_V2_HandlerPortTypeClient

 Dim sessionId = mage.login("xxxx", "xxxxxx")

 Dim order = mage.salesOrderInfo(sessionId, "100000020")

 Dim qty(0) As orderItemIdQty

 For Each item As salesOrderItemEntity In order.items

      qty(0).order_item_id = item.order_id
      qty(0).qty = item.qty_ordered

 Next

 Dim invoice As String = mage.salesOrderInvoiceCreate(sessionId, "100000020", qty, Nothing, Nothing, Nothing)

Here is the sample code that magento provides.

$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary

//Create invoice for order
$qty = array(array('order_item_id' => '15', 'qty' => '1'));
$invoiceIncrementId = $proxy->salesOrderInvoiceCreate($sessionID,'200000008',$qty);
var_dump($invoiceIncrementId);

2 Answers 2

2

I got my code to work. I was creating an array of objects correctly. Below is the working code.

Dim order = mage.salesOrderInfo(sessionId, "100000023")
Dim count As Integer = 0
Dim qty(order.items.Length) As orderItemIdQty

For Each item As salesOrderItemEntity In order.items
    qty(count) = New orderItemIdQty
    qty(count).order_item_id = item.item_id
    qty(count).qty = item.qty_ordered
    count = count + 1
Next

Dim invoice As String = mage.salesOrderInvoiceCreate(sessionId, "100000023", qty, Nothing, Nothing, Nothing)
1

steve

array should like this

$items = array();
     foreach ($order->getAllItems() as $item) {
        $items[$item->getId()] = $item->getQtyOrdered();
        }

Example an order have two Order items in sales_flat_order_item table

OrderItemId OrderQty
15           6
16           2

then array should be

$arr=array('15'=>6,'16'=>2);

check here http://www.amitbera.com/programmatically-create-invoice-of-a-new-order-in-magento/

2
  • Thanks for the reference, but I wanted to do this in VB.net. I figured it out though! Aug 15, 2014 at 16:54
  • sorry ,dude i am not a VB developer
    – Amit Bera
    Aug 15, 2014 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.