我在尝试提交shoppingCartProductAdd API请求时收到“一项产品没有标识符或sku”错误
我正在提交有效的SKU和Product_ID。所以错误对我没有意义。
以下是一些相关代码......
Dim pendingCartItems As New List(Of shoppingCartProductEntity)
If qtyAustin > 0 Then
Dim ticketRequest As New shoppingCartProductEntity
ticketRequest.sku = "RH_00001"
ticketRequest.product_id = "2"
ticketRequest.qty = qtyAustin
pendingCartItems.Add(ticketRequest)
End If
AddToCart(pendingCartItems)
Public Sub AddToCart(ByVal cartItems As List(Of shoppingCartProductEntity))
mClient.shoppingCartProductAdd(mSession, mCart, cartItems.ToArray(), mStore)
End Sub
shoppingCartProductAdd的API文档:http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html
答案 0 :(得分:0)
首先,您已启用Magento中的WS-I compliance
Magento admin -> System -> Configuration -> Services -> Magento Core API
然后将“WS-I Compliance
”设置为“yes
”。
从主机获取符合WS-I的WSDL
http://mymagentohost/index.php/api/v2_soap?wsdl=1
从
配置SOAP / XML-RPC用户和角色Magento admin -> System -> Web Services -> SOAP/XML-RPC-Users & SOAP/XML-RPC-Roles
并设置权限。
现在您可以生成客户端代理类(Axis,Axis2,Microsoft WSDL工具等)
检查您的终端网址,它应该是
http://mymagentohost/index.php/api/v2_soap/index/
我使用Axis2的功能测试代码
package magento;
import java.rmi.RemoteException;
import magento.MagentoServiceStub.EndSessionParam;
import magento.MagentoServiceStub.LoginParam;
import magento.MagentoServiceStub.LoginResponseParam;
import magento.MagentoServiceStub.ShoppingCartCreateRequestParam;
import magento.MagentoServiceStub.ShoppingCartCreateResponseParam;
import magento.MagentoServiceStub.ShoppingCartProductAddRequestParam;
import magento.MagentoServiceStub.ShoppingCartProductAddResponseParam;
import magento.MagentoServiceStub.ShoppingCartProductEntity;
import magento.MagentoServiceStub.ShoppingCartProductEntityArray;
import org.apache.axis2.AxisFault;
public class Test {
public static void main(String[] args) {
try {
MagentoServiceStub stub = new MagentoServiceStub();
LoginParam loginParam = new LoginParam();
loginParam.setUsername("myuser");
loginParam.setApiKey("1b6bf41e547e06b5b795d44b2f8f8f54");
LoginResponseParam p = stub.login(loginParam);
String sessionId = p.getResult();
ShoppingCartCreateRequestParam createParam = new ShoppingCartCreateRequestParam();
createParam.setSessionId(sessionId);
//param2.setStore("1");
ShoppingCartCreateResponseParam resp = stub.shoppingCartCreate(createParam);
int sr = resp.getResult();
ShoppingCartProductAddRequestParam prodcutAddParam = new ShoppingCartProductAddRequestParam();
prodcutAddParam.setSessionId(sessionId);
prodcutAddParam.setQuoteId(sr);
ShoppingCartProductEntityArray array = new ShoppingCartProductEntityArray();
ShoppingCartProductEntity producto = new ShoppingCartProductEntity();
producto.setSku("prueba");
producto.setQty(1);
array.addComplexObjectArray(producto);
prodcutAddParam.setProductsData(array);
ShoppingCartProductAddResponseParam prodAddResult = stub.shoppingCartProductAdd(prodcutAddParam);
System.out.println("product added? " + prodAddResult.getResult());
EndSessionParam endSessionParam = new EndSessionParam();
endSessionParam.setSessionId(sessionId);
stub.endSession(endSessionParam);
} catch (AxisFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
希望这会对你有所帮助。