简体   繁体   English

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

[英]Magento Add Configurable Product to shopping cart

how can i add Configurable Product to shopping cart in magento ? 如何在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(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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