本文整理汇总了PHP中Mage_Core_Controller_Front_Action::addAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Controller_Front_Action::addAction方法的具体用法?PHP Mage_Core_Controller_Front_Action::addAction怎么用?PHP Mage_Core_Controller_Front_Action::addAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Controller_Front_Action
的用法示例。
在下文中一共展示了Mage_Core_Controller_Front_Action::addAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _addToCart
public function _addToCart()
{
$cart = Mage::getSingleton('checkout/cart');
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
$params = $this->getRequest()->getParams();
if ($params['isAjax'] == 1) {
$response = array();
try {
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
$params['qty'] = $filter->filter($params['qty']);
}
$product = Mage::getModel('catalog/product')->load($params['product_id']);
$related = $this->getRequest()->getParam('related_product');
/**
* Check product availability
*/
if (!$product) {
$response['status'] = 'ERROR';
$response['message'] = $this->__('Unable to find Product ID');
}
$cart->addProduct($product, $params);
if (!empty($related)) {
$cart->addProductsByIds(explode(',', $related));
}
$cart->save();
$session->setCartWasUpdated(true);
/**
*
* @todo remove wishlist observer processAddToCart
*/
Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()));
if (!$session->getNoCartRedirect(true)) {
if (!$cart->getQuote()->getHasError()) {
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->htmlEscape($product->getName()));
$response['status'] = 'SUCCESS';
$response['message'] = $message;
}
}
} catch (Mage_Core_Exception $e) {
$msg = "";
if ($session->getUseNotice(true)) {
$msg = $e->getMessage();
} else {
$messages = array_unique(explode("\n", $e->getMessage()));
foreach ($messages as $message) {
$msg .= $message . '<br>';
}
}
$response['status'] = 'ERROR';
$response['message'] = $msg;
} catch (Exception $e) {
$response['status'] = 'ERROR';
$response['message'] = $this->__('Cannot add the item to shopping cart.');
Mage::logException($e);
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
return;
} else {
return parent::addAction();
}
}