简体   繁体   中英

Magento Add Configurable Product to shopping cart

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM