add product to cart with custom options
cart, magento, product
Solution
Here is the code i was come up with success.
$a_options = array(
'options' => array(
'label' => 'Choice',
'value' => $pkg_selected_products,
)
);
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'additional_options',
'value' => serialize($a_options)
)
));
$quote->addItem($quoteItem);
$quote->save();
Problem
I have to create a (virtual, simple )product and then add to cart both programmatically, i have done this so far. now i have to set custom options when this product add to cart. but nothing happens . here is my code ``` $product = Mage::getModel('catalog/product')->load($product_id); $cart = Mage::getModel('checkout/cart'); $cart->init(); $params = array( 'product' => $product->getId(), // This would be $product->getId() 'qty' => 1, 'options' => array( 34 => "value", 35 => "other value", 53 => "some other value" ) ); try { $cart->addProduct($product, new Varien_Object($params)); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); $cart->save(); } catch (Exception $ex) { echo $ex->getMessage(); } ```