当前位置: 首页>>代码示例>>PHP>>正文


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怎么用?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();
     }
 }
开发者ID:jun283,项目名称:magento-rest-cordova-mobile-app,代码行数:62,代码来源:CartController.php


注:本文中的Mage_Core_Controller_Front_Action::addAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。