1

I want to create invoice in to magento store using magento api in php.For that I want to create invoice for particular quantity and item means If anyone wants to invoice one item in paricular quantity then It shoud be done.My code is working for array() or all quantity. Below is pseudo code for creating invoice

$client = new Zend_XmlRpc_Client('http://127.0.0.1:8080/AndroidMagento/api/xmlrpc')
$session = $client->call('login', array('tester','tester'));
$saleorderno = '100000007';

Mage::init();
$order = Mage::getModel('sales/order')->load($saleorderno);
$orderItems = $order->getAllItems();
$invoiceItems = array();


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

$result = $client->call('call',array($session,'sales_order_invoice.create',array($saleorderno,array('order_item_id' => 9474, 'qty' => 1),'Invoice Created by Test',false,false)));

I have seen this link where i found somewhat idea but i can't understand exactly.I can't understand how to get value of order_item_id.???
Any idea??? Please suggest me Thanks in advance...

Community
  • 1
  • 1
krushnakant
  • 431
  • 9
  • 21

2 Answers2

1

item_id and product_id are different id.

order or quote has item_id and product_id.

You can try this:

$order = Mage::getModel('sales/order')->load($saleorderno);
$orderItems = $order->getAllItems();

foreach ($orderItems as $item){
      print_r($item->getData());
      print_r($item->getItemId()); //magic function to get ['item_id']
}

You can do it in 'sales/quote' Model.

Cheers ^^

  • 2
    Thanks for the reply.But by using this I will get item_id not order_item_id and these two are different.I have to pass the value of order_item_id with create_invoice method of magento api. – krushnakant Aug 03 '12 at 05:44
0

Try this,

echo "<pre>";
$result = $client->call($session, 'sales_order.info', 'orderIncrementId');
print_r($result['item_id']);
print_r($result['product_id']);

and the $result will return all info of order including item_id and product_id,

with $result['item_id'] you can pass it to call

sales_order_invoice.create

then do

$result = $client->call(
    $session,
    'sales_order_invoice.create',
    array('orderIncrementId' => '200000008', 
         array('order_item_id' => $result['item_id'], 
               'qty'           => $result['total_qty_ordered'])
    )
);

and the qty, You have to get it from $result['total_qty_ordered']

First, try to print_r[$result]; then You'll get some hints from it.

^^

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
  • 2
    Thanks for the reply.I have tried by passing the item_id as suggested by you which is returning me invoice_incrementid.But invoice is not created with paid amount at magento store.May be item_id and order_item_id are different as I had seen http://www.magentocommerce.com/api/soap/sales/salesOrderInvoice/sales_order_invoice.info.html – krushnakant Aug 06 '12 at 05:57
  • sales_order.info will return an array of items (Array of salesOrderItemEntity). You will need to loop through all items in the result for each item on the order to get the 'item_id' which is an order_item_id it is a key for the list of items on an order and isn't the same as the product_id which is the key for the item. http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.info.html – mttjohnson Aug 15 '12 at 15:55
  • 2
    Thanks.But I have done the same thing at http://stackoverflow.com/questions/11499043/create-invoice-method-is-not-working-properly-of-magento-api in android but it is not working – krushnakant Aug 17 '12 at 04:26