0
votes

how can i add Configurable Product to shopping cart in magento ? i try this code to add simple product to shopping cart but it`s not work for configurable product

        $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
        )));

how can i do this for configurable products ? thanks

1

1 Answers

2
votes

You can try something like this

 $productId = 'your-product-id';
 $cart = Mage::getModel('checkout/cart');
 $cart->init();
 $productCollection = Mage::getModel('catalog/product')->load($productId);
 $cart->addProduct($productCollection , array( 'product_id' => $productId, 'qty' => 1,'options' => array( $optionId => $optionValue));
 $cart->save();