Mage_Checkout_CartController
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
$cart = $this->_getCart();
$params = $this->getRequest()->getParams();
try {
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
$product = $this->_initProduct();
/**
* clear cart when product not in cart
* byfeng
*/
if(!$this->_getQuote()->getItemByProduct($product)){
$cart->truncate();
}
...
}
这个方法适用于产品简单,没有custome option的情况下