简体   繁体   中英

Magento XML-RPC API - Create Shipment From Java

Im trying to create shipments for magento orders from my third party app using the XML-RPC API. Everything works great when i make the call to "sales_order_shipment.create" with just the order increment id, but if i try making the same call with both an order increment id and a set of items and quantities, it will say "Requested order not exists." Why is that? what im doing wrong? what type should be the itemQuantity)

heres my code

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});
    }
}

As you see in the line

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

i try sending a hashMap that actually should contain the order item id and quantity. Ive also tried sending an array of objects and it doesnt work for any of them. What sould be there instead then if neither a Map or an Array is available?

Thank you for your help

Order Id and Order increment id are different. You should send order increment id.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM