添加到购物车中,并在Magento中提供产品定制选项

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

?>

Please try following code to add option to your product :

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

Ref Here : add product to cart with custom options