2013-11-26 146 views
0

我有一個虛擬產品與自定義選項(類型1和類型2)。價格可能會因類型而異。如何直接使用此選項添加到購物車,並根據自定義選項更改價格。我試過這段代碼,但它不起作用。添加到購物車在Magento產品定製選項

<?php 
// the ID of the product 
$product_id = "123"; 

$product  = Mage::getModel('catalog/product')->load($product_id); 

$cart = Mage::getModel('checkout/cart'); 
$cart->init(); 
$params = array(
    'product' => $product_id, 
    'qty' => 1, 
    'options' => array(
     'options' => array(
      '7462' => 'Type Option Id' , 
      '3731' => 'Type-1', 
     ) 

    ) 
); 

$cart->addProduct($product, $params); 
$cart->save(); 

Mage::getSingleton('checkout/session')->setCartWasUpdated(true); 
$this->_redirect('checkout/cart'); 

?> 

回答

0

請嘗試以下代碼以添加選項,你的產品:

$quoteItem->addOption(new Varien_Object(
    array(
     'product' => $quoteItem->getProduct(), 
     'code' => 'additional_options', 
     'value' => serialize($a_options) 
    ) 
)); 

參考這裏:add product to cart with custom options

相關問題