I'm getting "One item of products do not have identifier or sku" error when attempting to submit shoppingCartProductAdd API request
I'm submitting both a valid SKU and Product_ID. So the error doesn't make sense to me.
Here's some of the relevant code…
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
API documentation for shoppingCartProductAdd: http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html
First you have enabled the WS-I compliance in Magento
Magento admin -> System -> Configuration -> Services -> Magento Core API
then set "WS-I Compliance
" to "yes
".
Get the WSDL with WS-I compliance from your host
http://mymagentohost/index.php/api/v2_soap?wsdl=1
Configure the SOAP/XML-RPC users and roles from
Magento admin -> System -> Web Services -> SOAP/XML-RPC-Users & SOAP/XML-RPC-Roles
and set permissions.
Now you can generate your client Proxy classes (Axis, Axis2, Microsoft WSDL tool... etc)
Check your endpoint URL, it should be
http://mymagentohost/index.php/api/v2_soap/index/
My functional testing code using 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();
}
}
}
Hope this helps you.