Magento XML-RPC API - 从Java创建货件

时间:2013-01-15 13:19:13

标签: java api magento xml-rpc

我尝试使用XML-RPC API从我的第三方应用程序创建magento订单的货件。当我使用订单增量ID调用“sales_order_shipment.create”时,一切都很有效,但是如果我尝试使用订单增量ID和一组项目和数量进行相同的调用,它会说“请求的订单不是存在“。这是为什么?我做错了什么?什么类型应该是itemQuantity)

继承我的代码

package magentoapiclient;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class XMLRPCAPIClient {

    public static void main(String[] args) {
        createShipment("100000005", 5, 1.0);
    }

    public static XmlRpcClient prepareClient() throws MalformedURLException {
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("myHost"));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        client.setTypeFactory(new MyTypeFactory(client));
        return client;
    }

    public static void createShipment(String orderIncrementId, int itemId, double quantity) {
        try {
            XmlRpcClient client = prepareClient();
            String sessionId = login("myUser", "myKey", client);
            System.out.println(sessionId);
            Object[] request = {orderIncrementId, new HashMap()};
            client.execute("call", new Object[]{sessionId, "sales_order_shipment.create", request});
            endSession(sessionId, client);
        } catch (XmlRpcException | MalformedURLException ex) {
            Logger.getLogger(XMLRPCAPIClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static String login(String user, String password, XmlRpcClient client) throws XmlRpcException {
        String sessionId = (String) client.execute("login", new Object[]{user, password});
        return sessionId;
    }

    public static void endSession(String sessionToken, XmlRpcClient client) throws XmlRpcException {
        client.execute("endSession", new Object[]{sessionToken});
    }
}

正如你在行中看到的那样

  

Object [] request = {orderIncrementId,new HashMap()};

我尝试发送一个实际应该包含订单商品ID和数量的hashMap。我也试过发送一个对象数组,它不适用于任何一个。如果地图或数组都不可用,那么应该是什么呢?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

订单ID和订单增量ID不同。您应该发送订单增量ID。

http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.info.html