我正在使用自定义选项类型文件将产品添加到 Magento 中:
$cart = Mage::getModel('checkout/cart');
$cart->init();
$pModel = Mage::getSingleton('catalog/product');
foreach($prodArray as $_prod){
$products = explode("=",$_prod);
$product_id = $products[0];
$prod_qty = $products[1];
$pModel->unsetData();
$pModel = Mage::getModel('catalog/product')->load($product_id);
try {
$cart->addProduct($pModel,$prod_qty);
}
catch (Exception $e) { continue; }
echo "<br>Product has been added to Cart of id: $product_id with Quantity: $prod_qty";
}
$cart->save();