Magento – add product to cart with product options

apicustom-optionsproduct-attributeshopping-cartsoap

i try to add product to cart wih this code :

    $proxy = new SoapClient('http://example.com/index.php/api/v2_soap/?wsdl'); 
    try{
    $result = $proxy->shoppingCartProductAdd($sessionID, $cartID, array(array(
    'product_id' => $productID,
    'sku' => $sku,
    'qty' => $qty,
    'options' => null,
    'bundle_option' => null,
    'bundle_option_qty' => null,
    'links' => null
    )));  

    } catch(SoapFault $e){

       $result = $e->getMessage();
       }

i found it from this link : Magento API

on link example it`s pass null for options if i want to add options like color or size or … to product and then add the prodoct to cart what should i do ?

Best Answer

As you can see in the documentation from your link above, the shoppingCartProductEntity array attribute "options" is an associativeArray in the form of option_id => content.

I found a nice answer on stackoverflow "Setting Custom Options while adding a product to cart via SOAP in Magento" regarding this problem and the declaration as provided in the documentation does not seem correct.

The right way seems to be:

'options' => 
        array(
          0 => 
            array(
              'key' => 1
              'value' => 2),
          1 => 
            array(
              'key' => 3
              'value' => 4),              
        )