Create Invoice Method is not working properly of Magento API

亡梦爱人 提交于 2019-12-13 15:12:15

问题


I am trying to create sales order Invoice using Magento API in android application using XMLRPC.I am using the method "sales_order_invoice.create" for creating invoice.This method is giving me Invoice Id in the response for given quantity as mention in magento wiki.But the problem is that the Invoice qty isn't updated on magento store.Other thing is Order status is changing to Processing which is correct and the entry of created invoice is also present in invoice list of store but It is displaying the paid amount as $0.0 which is not correct.

I don't know if I need to call another method before calling sales_order_invoice.create or is there any problem in the method??
Below is some part of my code for calling method:

import java.util.HashMap;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MagentoStore extends Activity {

private XMLRPCClient client;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
            String sessionId = "";


client = new XMLRPCClient("http://www.mystore.com/index.php/api/xmlrpc");
        try {

            sessionId = (String)client.call("login", "tester", "tester");
            Log.d("MY_XMLRPC_SUCCESS_SESSION_ID", sessionId);
            }
         catch (XMLRPCException e) {

            Log.d("MY_XMLRPCException_MSG", e.getMessage());
        }

        Object salesorderInfo = null;
        Object[] methodParams = new Object[]{"100000028"};
        Object[] callParams = new Object[]{sessionId,"sales_order.info", methodParams};
        String salesorderinvoice= null;
        try {
             salesorderInfo = (Object)client.callEx("call",callParams);
             HashMap map = (HashMap)salesorderInfo;
             Object[]items=(Object[])map.get("items");
             for(Object item :items)
             {
                 HashMap itemlist=(HashMap)item;
                 String item_id=(String)itemlist.get("item_id");
                 int itemids=Integer.parseInt(item_id);
                 String base_price=(String)itemlist.get("base_price");
                 if(base_price.equals("0.0000"))
                 {
                  continue;  
                 }   
                 String name=(String)itemlist.get("name");
                 Double qty=1.0;
                 String qty_ordered =(String)itemlist.get("qty_ordered");
                 String qty_invoiced=(String)itemlist.get("qty_invoiced");
                 Object[] methodParams1 = new Object[]{"100000028",itemids,qty};
                 Object[] callParams1 = new Object[]{sessionId,"sales_order_invoice.create", methodParams1};
                 salesorderinvoice= (String)client.callEx("call",callParams1);

             } 
            } catch (Exception e) {
            Log.d("APP_INFO", "Exception: " + e.getMessage());
            }               
    }
}

Anyone have any Idea?? Thanks in advance


回答1:


FYI

when you call the API sales_order_invoice.create, you must assign the array pointer name.

String qty_ordered =(String)itemlist.get("qty_ordered");
                 String qty_invoiced=(String)itemlist.get("qty_invoiced");
                 Object[] methodParams1 = new Object[]{"100000028",itemids,qty};

try to var_dump the methodParams1 with

methodParams1.toString();

it must be same with

array(
      'orderIncrementId' => '200000008', 
      array(
            'order_item_id' => '11', 
            'qty' => '1'
      )
);

because this is the way to put the parameter to sales_order_invoice.create

$result = $client->call(
    $session,
    'sales_order_invoice.create',
    array('orderIncrementId' => '200000008', array('order_item_id' => '11', 'qty' => '1'))
);


来源:https://stackoverflow.com/questions/11499043/create-invoice-method-is-not-working-properly-of-magento-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!