实际上,我已经将这段代码写入“CartController.php”文件。
public function newAction() {
$cart = $this->_getCart();
try {
//getting list of products
$filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
for ($i = 1; $i <= 4; $i++) {
echo '<br>';
$param = $_GET['product' . $i];
if (isset($param)) {
$param = explode("/", $param);
print_r($param);
$productId = $param[0];
$product = $this->addNewProduct($productId);
$quantity = $filter->filter($param[1]);
$params['product'] = $product;
$params['qty'] = $quantity;
$cart->addProduct($product);
}// if over
}//for over
$cart->save();
$message = $this->__('Added to Your Cart Successfully', Mage::helper('core')->escapeHtml());
$this->_getSession()->addSuccess($message);
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$this->_redirect("checkout/cart/");
} catch (Mage_Core_Exception $e) {}
现在,我们可以添加产品,如下所示:http://localhost/magento/index.php/checkout/cart/new?product1=2/3&product2=3/3&product3=4/1
其中,在“product1=2/3”中,2=>productId & 3=> 是数量。
此代码工作正常。但是,我想在不修改客户端代码的情况下做到这一点。