使用我自己的控制器,我将产品添加到Magento购物车.它有3个自定义选项:2个下拉选项(颜色和大小)和文件选项(设计).将产品添加到购物车的代码是
// obtain the shopping cart
$cart = Mage::getSingleton('checkout/cart');
// load the product
$product = Mage::getModel('catalog/product')
->load($productId);
// do some magic to obtain the select ids for color and size ($selectedSize and $selectedColor)
// ...
// define the buy request params
$params = array(
'product' => $productId,
'qty' => $quantity,
'options' => array(
$customOptionSize->getId() => $selectedSize,
$customOptionColor->getId() => $selectedColor,
// set the file option, but how?
),
);
// add this configuration to cart
$cart->addProduct($product, $paramObject);
$cart->save();
// set the …Run Code Online (Sandbox Code Playgroud)