I have a virtual product with custom option (type-1 and type-2). Price may change depend on type. How can I add to cart with this option directly and change the price depend on custom option. I tried this code but it doesn't work.
<?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');
?>