cannot add configurable product to cart in magento

1.7k views Asked by At

i want to add a product to cart in magento , product details is :

type = configurable
product id = 1300
product sku = FCC100
Attribute Code= color
Attribute Label= color
Attribute Id= 152
options value = 28,43
options label = blue,red

this configurable product have two color option red and blue, there is two simple product atached to this configurable product.

i try with this code :

 $product = array(
    "product_id" =>"1300",
    "qty" => 2,
    "super_attribute" => array(152 => 28));
    $result = $proxy->shoppingCartProductAdd($sessionID, $cartID, array($product));

but this code return me this message :

please specify product option(s)

i use this code to add simple product and it`s work fine :

$result = $proxy->shoppingCartProductAdd($sessionID, $cartID, array(array(
        'product_id' =>   $productID  ,
        'sku' =>  $sku  ,
        'qty' => $qty,
        'options' =>array(0 =>array('key' => $option1id ,'value' => $option1value),1 =>array('key' => $option2id ,'value' => $option2value)),

        'bundle_option' => null,
        'bundle_option_qty' => null,
        'links' => null
        )));    

my problem is with configurable product. i try to add with simple child products but problem of this way is often child products have not price and price is setted to parent product. what is the problem in my code ? is there any way to add configurable product to cart with out using API ?

this is what i found in product page source:

Product.Config({"attributes":{"152":{"id":"152","code":"color","label":"\u0631\u0646\u06af","options":[{"id":"28","label":"\u0622\u0628\u06cc","price":"0","oldPrice":"0","products":["1301"]},{"id":"47","label":"\u0632\u0631\u0634\u06a9\u06cc","price":"0","oldPrice":"0","products":["1302"]}]}},"template":"#{price}\u00a0\u0631\u06cc\u0627\u0644","basePrice":"550000","oldPrice":"550000","productId":"1300","chooseText":"\u0627\u0646\u062a\u062e\u0627\u0628 \u06cc\u06a9 \u06af\u0632\u06cc\u0646\u0647...","taxConfig":{"includeTax":false,"showIncludeTax":false,"showBothPrices":false,"defaultTax":0,"currentTax":0,"inclTaxTitle":"\u0634\u0627\u0645\u0644 \u0645\u0627\u0644\u06cc\u0627\u062a"}});
2

There are 2 answers

4
Axel On

Your $product array is missing the options key values.

You need to add options which should be An array in the form of option_id => content per the documentation.

$product = array(
              "product_id" => "1300",
              "qty" => 2,
              "options" => array(         
                                152 => 28
                           )
              );

Documentation: http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html

0
Kuldeep Singh On

Your array must be like below

$arrProducts = array(
array(
    "product_id" =>"21",
    "qty" => 2,
            "super_attribute" => array(         
                92 => 162

             )
));