我必须创建一个(虚拟的、简单的)产品,然后以编程方式添加到购物车,到目前为止我已经这样做了。现在我必须在此产品添加到购物车时设置自定义选项。但什么也没发生。这是我的代码
$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();
}