Search code examples
phpmagentomagento-soap-api

Magento SOAP API and PHP: One item of products do not have identifier or sku


Good Day, need help on this scenario. We have a client who has a Magento ver 1.9 system which I don't have access. They have asked us to create a mobile app and we are using as PHP Laravel 5.1 as a proxy rest api to call Magento's SOAP API V2. One of the services was to add a product to the cart. I've used this reference http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html but unfortunately when I call the service I'm getting this error

"One item of products do not have identifier or sku"

Here is the snippet of the php code:

$data = array_add($data, 'product_id', $request->json('product_id'));
$data = array_add($data, 'sku', $request->json('sku'));
$data = array_add($data, 'qty', $request->json('qty'));
$data = array_add($data, 'options', $request->json('options'));
$data = array_add($data, 'bundleOption', $request->json('bundleOption'));
$data = array_add($data, 'bundleOptionQty', $request->json('bundleOptionQty'));
$data = array_add($data, 'links', $request->json('links'));

try {
    $result = $client->shoppingCartProductAdd($sessionId,$cartId,$data);

    if ($result) {
        return $this->respond([
            'message' => 'Product Successfully added to Cart.'
        ]);
    }

} catch (SoapFault $e) {
    $message = $e->getMessage();
    return $this->respondInternalError($message);
}

Here is the Json request

{"product_id":"13","sku":"Warm-Welcome-Coat","qty":"5","options":"","bundleOption":"","bundleOptionQty":"","links":""}

I'm sure that the product is existing as I used the api to call the product list. I've tried this solution -> Magento SOAP API v2 shoppingCartProductAdd error “One item of products do not have identifier or sku” but it is not working for me.


Solution

  • I just solved in this problem. It seems that the format of my data array is incorrect as the sample from the Magento states that:

    $result = $proxy->shoppingCartProductAdd($sessionId, 10, array(array(
    'product_id' => '4',
    'sku' => 'simple_product',
    'qty' => '5',
    'options' => null,
    'bundle_option' => null,
    'bundle_option_qty' => null,
    'links' => null
    )));
    

    While the $data from my example is just an array.