Magento将可配置产品添加到购物车

时间:2014-10-22 06:18:36

标签: php magento shopping-cart configurable-product

如何在magento中将可配置产品添加到购物车?我尝试使用此代码将简单的产品添加到购物车,但它不适用于可配置产品

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

我如何为可配置产品做到这一点? 感谢

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情

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