Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Checkout_Block_Agreements
  • Mage_Checkout_Block_Cart
  • Mage_Checkout_Block_Cart_Abstract
  • Mage_Checkout_Block_Cart_Coupon
  • Mage_Checkout_Block_Cart_Crosssell
  • Mage_Checkout_Block_Cart_Item_Configure
  • Mage_Checkout_Block_Cart_Item_Renderer
  • Mage_Checkout_Block_Cart_Item_Renderer_Configurable
  • Mage_Checkout_Block_Cart_Item_Renderer_Grouped
  • Mage_Checkout_Block_Cart_Shipping
  • Mage_Checkout_Block_Cart_Sidebar
  • Mage_Checkout_Block_Cart_Totals
  • Mage_Checkout_Block_Links
  • Mage_Checkout_Block_Multishipping_Abstract
  • Mage_Checkout_Block_Multishipping_Address_Select
  • Mage_Checkout_Block_Multishipping_Addresses
  • Mage_Checkout_Block_Multishipping_Billing
  • Mage_Checkout_Block_Multishipping_Billing_Items
  • Mage_Checkout_Block_Multishipping_Link
  • Mage_Checkout_Block_Multishipping_Overview
  • Mage_Checkout_Block_Multishipping_Payment_Info
  • Mage_Checkout_Block_Multishipping_Shipping
  • Mage_Checkout_Block_Multishipping_State
  • Mage_Checkout_Block_Multishipping_Success
  • Mage_Checkout_Block_Onepage
  • Mage_Checkout_Block_Onepage_Abstract
  • Mage_Checkout_Block_Onepage_Billing
  • Mage_Checkout_Block_Onepage_Failure
  • Mage_Checkout_Block_Onepage_Link
  • Mage_Checkout_Block_Onepage_Login
  • Mage_Checkout_Block_Onepage_Payment
  • Mage_Checkout_Block_Onepage_Payment_Info
  • Mage_Checkout_Block_Onepage_Payment_Methods
  • Mage_Checkout_Block_Onepage_Progress
  • Mage_Checkout_Block_Onepage_Review
  • Mage_Checkout_Block_Onepage_Review_Info
  • Mage_Checkout_Block_Onepage_Shipping
  • Mage_Checkout_Block_Onepage_Shipping_Method
  • Mage_Checkout_Block_Onepage_Shipping_Method_Additional
  • Mage_Checkout_Block_Onepage_Shipping_Method_Available
  • Mage_Checkout_Block_Onepage_Success
  • Mage_Checkout_Block_Success
  • Mage_Checkout_Block_Total_Default
  • Mage_Checkout_Block_Total_Nominal
  • Mage_Checkout_Block_Total_Tax
  • Mage_Checkout_CartController
  • Mage_Checkout_Controller_Action
  • Mage_Checkout_Exception
  • Mage_Checkout_Helper_Cart
  • Mage_Checkout_Helper_Data
  • Mage_Checkout_Helper_Url
  • Mage_Checkout_IndexController
  • Mage_Checkout_Model_Agreement
  • Mage_Checkout_Model_Api_Resource
  • Mage_Checkout_Model_Api_Resource_Customer
  • Mage_Checkout_Model_Api_Resource_Product
  • Mage_Checkout_Model_Cart
  • Mage_Checkout_Model_Cart_Api
  • Mage_Checkout_Model_Cart_Api_V2
  • Mage_Checkout_Model_Cart_Coupon_Api
  • Mage_Checkout_Model_Cart_Coupon_Api_V2
  • Mage_Checkout_Model_Cart_Customer_Api
  • Mage_Checkout_Model_Cart_Customer_Api_V2
  • Mage_Checkout_Model_Cart_Payment_Api
  • Mage_Checkout_Model_Cart_Payment_Api_V2
  • Mage_Checkout_Model_Cart_Product_Api
  • Mage_Checkout_Model_Cart_Product_Api_V2
  • Mage_Checkout_Model_Cart_Shipping_Api
  • Mage_Checkout_Model_Cart_Shipping_Api_V2
  • Mage_Checkout_Model_Config_Source_Cart_Summary
  • Mage_Checkout_Model_Mysql4_Agreement
  • Mage_Checkout_Model_Mysql4_Agreement_Collection
  • Mage_Checkout_Model_Mysql4_Cart
  • Mage_Checkout_Model_Mysql4_Setup
  • Mage_Checkout_Model_Observer
  • Mage_Checkout_Model_Resource_Agreement
  • Mage_Checkout_Model_Resource_Agreement_Collection
  • Mage_Checkout_Model_Resource_Cart
  • Mage_Checkout_Model_Resource_Setup
  • Mage_Checkout_Model_Session
  • Mage_Checkout_Model_Type_Abstract
  • Mage_Checkout_Model_Type_Multishipping
  • Mage_Checkout_Model_Type_Multishipping_State
  • Mage_Checkout_Model_Type_Onepage
  • Mage_Checkout_Multishipping_AddressController
  • Mage_Checkout_MultishippingController
  • Mage_Checkout_OnepageController

Interfaces

  • Mage_Checkout_Model_Cart_Interface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Checkout
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Shopping cart controller
 29:  */
 30: class Mage_Checkout_CartController extends Mage_Core_Controller_Front_Action
 31: {
 32:     /**
 33:      * Action list where need check enabled cookie
 34:      *
 35:      * @var array
 36:      */
 37:     protected $_cookieCheckActions = array('add');
 38: 
 39:     /**
 40:      * Retrieve shopping cart model object
 41:      *
 42:      * @return Mage_Checkout_Model_Cart
 43:      */
 44:     protected function _getCart()
 45:     {
 46:         return Mage::getSingleton('checkout/cart');
 47:     }
 48: 
 49:     /**
 50:      * Get checkout session model instance
 51:      *
 52:      * @return Mage_Checkout_Model_Session
 53:      */
 54:     protected function _getSession()
 55:     {
 56:         return Mage::getSingleton('checkout/session');
 57:     }
 58: 
 59:     /**
 60:      * Get current active quote instance
 61:      *
 62:      * @return Mage_Sales_Model_Quote
 63:      */
 64:     protected function _getQuote()
 65:     {
 66:         return $this->_getCart()->getQuote();
 67:     }
 68: 
 69:     /**
 70:      * Set back redirect url to response
 71:      *
 72:      * @return Mage_Checkout_CartController
 73:      */
 74:     protected function _goBack()
 75:     {
 76:         $returnUrl = $this->getRequest()->getParam('return_url');
 77:         if ($returnUrl) {
 78: 
 79:             if (!$this->_isUrlInternal($returnUrl)) {
 80:                 throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
 81:             }
 82: 
 83:             $this->_getSession()->getMessages(true);
 84:             $this->getResponse()->setRedirect($returnUrl);
 85:         } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
 86:             && !$this->getRequest()->getParam('in_cart')
 87:             && $backUrl = $this->_getRefererUrl()
 88:         ) {
 89:             $this->getResponse()->setRedirect($backUrl);
 90:         } else {
 91:             if (($this->getRequest()->getActionName() == 'add') && !$this->getRequest()->getParam('in_cart')) {
 92:                 $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
 93:             }
 94:             $this->_redirect('checkout/cart');
 95:         }
 96:         return $this;
 97:     }
 98: 
 99:     /**
100:      * Initialize product instance from request data
101:      *
102:      * @return Mage_Catalog_Model_Product || false
103:      */
104:     protected function _initProduct()
105:     {
106:         $productId = (int) $this->getRequest()->getParam('product');
107:         if ($productId) {
108:             $product = Mage::getModel('catalog/product')
109:                 ->setStoreId(Mage::app()->getStore()->getId())
110:                 ->load($productId);
111:             if ($product->getId()) {
112:                 return $product;
113:             }
114:         }
115:         return false;
116:     }
117: 
118:     /**
119:      * Shopping cart display action
120:      */
121:     public function indexAction()
122:     {
123:         $cart = $this->_getCart();
124:         if ($cart->getQuote()->getItemsCount()) {
125:             $cart->init();
126:             $cart->save();
127: 
128:             if (!$this->_getQuote()->validateMinimumAmount()) {
129:                 $minimumAmount = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())
130:                     ->toCurrency(Mage::getStoreConfig('sales/minimum_order/amount'));
131: 
132:                 $warning = Mage::getStoreConfig('sales/minimum_order/description')
133:                     ? Mage::getStoreConfig('sales/minimum_order/description')
134:                     : Mage::helper('checkout')->__('Minimum order amount is %s', $minimumAmount);
135: 
136:                 $cart->getCheckoutSession()->addNotice($warning);
137:             }
138:         }
139: 
140:         // Compose array of messages to add
141:         $messages = array();
142:         foreach ($cart->getQuote()->getMessages() as $message) {
143:             if ($message) {
144:                 // Escape HTML entities in quote message to prevent XSS
145:                 $message->setCode(Mage::helper('core')->escapeHtml($message->getCode()));
146:                 $messages[] = $message;
147:             }
148:         }
149:         $cart->getCheckoutSession()->addUniqueMessages($messages);
150: 
151:         /**
152:          * if customer enteres shopping cart we should mark quote
153:          * as modified bc he can has checkout page in another window.
154:          */
155:         $this->_getSession()->setCartWasUpdated(true);
156: 
157:         Varien_Profiler::start(__METHOD__ . 'cart_display');
158:         $this
159:             ->loadLayout()
160:             ->_initLayoutMessages('checkout/session')
161:             ->_initLayoutMessages('catalog/session')
162:             ->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart'));
163:         $this->renderLayout();
164:         Varien_Profiler::stop(__METHOD__ . 'cart_display');
165:     }
166: 
167:     /**
168:      * Add product to shopping cart action
169:      */
170:     public function addAction()
171:     {
172:         $cart   = $this->_getCart();
173:         $params = $this->getRequest()->getParams();
174:         try {
175:             if (isset($params['qty'])) {
176:                 $filter = new Zend_Filter_LocalizedToNormalized(
177:                     array('locale' => Mage::app()->getLocale()->getLocaleCode())
178:                 );
179:                 $params['qty'] = $filter->filter($params['qty']);
180:             }
181: 
182:             $product = $this->_initProduct();
183:             $related = $this->getRequest()->getParam('related_product');
184: 
185:             /**
186:              * Check product availability
187:              */
188:             if (!$product) {
189:                 $this->_goBack();
190:                 return;
191:             }
192: 
193:             $cart->addProduct($product, $params);
194:             if (!empty($related)) {
195:                 $cart->addProductsByIds(explode(',', $related));
196:             }
197: 
198:             $cart->save();
199: 
200:             $this->_getSession()->setCartWasUpdated(true);
201: 
202:             /**
203:              * @todo remove wishlist observer processAddToCart
204:              */
205:             Mage::dispatchEvent('checkout_cart_add_product_complete',
206:                 array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
207:             );
208: 
209:             if (!$this->_getSession()->getNoCartRedirect(true)) {
210:                 if (!$cart->getQuote()->getHasError()){
211:                     $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
212:                     $this->_getSession()->addSuccess($message);
213:                 }
214:                 $this->_goBack();
215:             }
216:         } catch (Mage_Core_Exception $e) {
217:             if ($this->_getSession()->getUseNotice(true)) {
218:                 $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
219:             } else {
220:                 $messages = array_unique(explode("\n", $e->getMessage()));
221:                 foreach ($messages as $message) {
222:                     $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
223:                 }
224:             }
225: 
226:             $url = $this->_getSession()->getRedirectUrl(true);
227:             if ($url) {
228:                 $this->getResponse()->setRedirect($url);
229:             } else {
230:                 $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
231:             }
232:         } catch (Exception $e) {
233:             $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
234:             Mage::logException($e);
235:             $this->_goBack();
236:         }
237:     }
238: 
239:     public function addgroupAction()
240:     {
241:         $orderItemIds = $this->getRequest()->getParam('order_items', array());
242:         if (is_array($orderItemIds)) {
243:             $itemsCollection = Mage::getModel('sales/order_item')
244:                 ->getCollection()
245:                 ->addIdFilter($orderItemIds)
246:                 ->load();
247:             /* @var $itemsCollection Mage_Sales_Model_Mysql4_Order_Item_Collection */
248:             $cart = $this->_getCart();
249:             foreach ($itemsCollection as $item) {
250:                 try {
251:                     $cart->addOrderItem($item, 1);
252:                 } catch (Mage_Core_Exception $e) {
253:                     if ($this->_getSession()->getUseNotice(true)) {
254:                         $this->_getSession()->addNotice($e->getMessage());
255:                     } else {
256:                         $this->_getSession()->addError($e->getMessage());
257:                     }
258:                 } catch (Exception $e) {
259:                     $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
260:                     Mage::logException($e);
261:                     $this->_goBack();
262:                 }
263:             }
264:             $cart->save();
265:             $this->_getSession()->setCartWasUpdated(true);
266:         }
267:         $this->_goBack();
268:     }
269: 
270:     /**
271:      * Action to reconfigure cart item
272:      */
273:     public function configureAction()
274:     {
275:         // Extract item and product to configure
276:         $id = (int) $this->getRequest()->getParam('id');
277:         $quoteItem = null;
278:         $cart = $this->_getCart();
279:         if ($id) {
280:             $quoteItem = $cart->getQuote()->getItemById($id);
281:         }
282: 
283:         if (!$quoteItem) {
284:             $this->_getSession()->addError($this->__('Quote item is not found.'));
285:             $this->_redirect('checkout/cart');
286:             return;
287:         }
288: 
289:         try {
290:             $params = new Varien_Object();
291:             $params->setCategoryId(false);
292:             $params->setConfigureMode(true);
293:             $params->setBuyRequest($quoteItem->getBuyRequest());
294: 
295:             Mage::helper('catalog/product_view')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params);
296:         } catch (Exception $e) {
297:             $this->_getSession()->addError($this->__('Cannot configure product.'));
298:             Mage::logException($e);
299:             $this->_goBack();
300:             return;
301:         }
302:     }
303: 
304:     /**
305:      * Update product configuration for a cart item
306:      */
307:     public function updateItemOptionsAction()
308:     {
309:         $cart   = $this->_getCart();
310:         $id = (int) $this->getRequest()->getParam('id');
311:         $params = $this->getRequest()->getParams();
312: 
313:         if (!isset($params['options'])) {
314:             $params['options'] = array();
315:         }
316:         try {
317:             if (isset($params['qty'])) {
318:                 $filter = new Zend_Filter_LocalizedToNormalized(
319:                     array('locale' => Mage::app()->getLocale()->getLocaleCode())
320:                 );
321:                 $params['qty'] = $filter->filter($params['qty']);
322:             }
323: 
324:             $quoteItem = $cart->getQuote()->getItemById($id);
325:             if (!$quoteItem) {
326:                 Mage::throwException($this->__('Quote item is not found.'));
327:             }
328: 
329:             $item = $cart->updateItem($id, new Varien_Object($params));
330:             if (is_string($item)) {
331:                 Mage::throwException($item);
332:             }
333:             if ($item->getHasError()) {
334:                 Mage::throwException($item->getMessage());
335:             }
336: 
337:             $related = $this->getRequest()->getParam('related_product');
338:             if (!empty($related)) {
339:                 $cart->addProductsByIds(explode(',', $related));
340:             }
341: 
342:             $cart->save();
343: 
344:             $this->_getSession()->setCartWasUpdated(true);
345: 
346:             Mage::dispatchEvent('checkout_cart_update_item_complete',
347:                 array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())
348:             );
349:             if (!$this->_getSession()->getNoCartRedirect(true)) {
350:                 if (!$cart->getQuote()->getHasError()){
351:                     $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->htmlEscape($item->getProduct()->getName()));
352:                     $this->_getSession()->addSuccess($message);
353:                 }
354:                 $this->_goBack();
355:             }
356:         } catch (Mage_Core_Exception $e) {
357:             if ($this->_getSession()->getUseNotice(true)) {
358:                 $this->_getSession()->addNotice($e->getMessage());
359:             } else {
360:                 $messages = array_unique(explode("\n", $e->getMessage()));
361:                 foreach ($messages as $message) {
362:                     $this->_getSession()->addError($message);
363:                 }
364:             }
365: 
366:             $url = $this->_getSession()->getRedirectUrl(true);
367:             if ($url) {
368:                 $this->getResponse()->setRedirect($url);
369:             } else {
370:                 $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
371:             }
372:         } catch (Exception $e) {
373:             $this->_getSession()->addException($e, $this->__('Cannot update the item.'));
374:             Mage::logException($e);
375:             $this->_goBack();
376:         }
377:         $this->_redirect('*/*');
378:     }
379: 
380:     /**
381:      * Update shopping cart data action
382:      */
383:     public function updatePostAction()
384:     {
385:         $updateAction = (string)$this->getRequest()->getParam('update_cart_action');
386: 
387:         switch ($updateAction) {
388:             case 'empty_cart':
389:                 $this->_emptyShoppingCart();
390:                 break;
391:             case 'update_qty':
392:                 $this->_updateShoppingCart();
393:                 break;
394:             default:
395:                 $this->_updateShoppingCart();
396:         }
397: 
398:         $this->_goBack();
399:     }
400: 
401:     /**
402:      * Update customer's shopping cart
403:      */
404:     protected function _updateShoppingCart()
405:     {
406:         try {
407:             $cartData = $this->getRequest()->getParam('cart');
408:             if (is_array($cartData)) {
409:                 $filter = new Zend_Filter_LocalizedToNormalized(
410:                     array('locale' => Mage::app()->getLocale()->getLocaleCode())
411:                 );
412:                 foreach ($cartData as $index => $data) {
413:                     if (isset($data['qty'])) {
414:                         $cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
415:                     }
416:                 }
417:                 $cart = $this->_getCart();
418:                 if (! $cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) {
419:                     $cart->getQuote()->setCustomerId(null);
420:                 }
421: 
422:                 $cartData = $cart->suggestItemsQty($cartData);
423:                 $cart->updateItems($cartData)
424:                     ->save();
425:             }
426:             $this->_getSession()->setCartWasUpdated(true);
427:         } catch (Mage_Core_Exception $e) {
428:             $this->_getSession()->addError(Mage::helper('core')->escapeHtml($e->getMessage()));
429:         } catch (Exception $e) {
430:             $this->_getSession()->addException($e, $this->__('Cannot update shopping cart.'));
431:             Mage::logException($e);
432:         }
433:     }
434: 
435:     /**
436:      * Empty customer's shopping cart
437:      */
438:     protected function _emptyShoppingCart()
439:     {
440:         try {
441:             $this->_getCart()->truncate()->save();
442:             $this->_getSession()->setCartWasUpdated(true);
443:         } catch (Mage_Core_Exception $exception) {
444:             $this->_getSession()->addError($exception->getMessage());
445:         } catch (Exception $exception) {
446:             $this->_getSession()->addException($exception, $this->__('Cannot update shopping cart.'));
447:         }
448:     }
449: 
450:     /**
451:      * Delete shoping cart item action
452:      */
453:     public function deleteAction()
454:     {
455:         $id = (int) $this->getRequest()->getParam('id');
456:         if ($id) {
457:             try {
458:                 $this->_getCart()->removeItem($id)
459:                   ->save();
460:             } catch (Exception $e) {
461:                 $this->_getSession()->addError($this->__('Cannot remove the item.'));
462:                 Mage::logException($e);
463:             }
464:         }
465:         $this->_redirectReferer(Mage::getUrl('*/*'));
466:     }
467: 
468:     /**
469:      * Initialize shipping information
470:      */
471:     public function estimatePostAction()
472:     {
473:         $country    = (string) $this->getRequest()->getParam('country_id');
474:         $postcode   = (string) $this->getRequest()->getParam('estimate_postcode');
475:         $city       = (string) $this->getRequest()->getParam('estimate_city');
476:         $regionId   = (string) $this->getRequest()->getParam('region_id');
477:         $region     = (string) $this->getRequest()->getParam('region');
478: 
479:         $this->_getQuote()->getShippingAddress()
480:             ->setCountryId($country)
481:             ->setCity($city)
482:             ->setPostcode($postcode)
483:             ->setRegionId($regionId)
484:             ->setRegion($region)
485:             ->setCollectShippingRates(true);
486:         $this->_getQuote()->save();
487:         $this->_goBack();
488:     }
489: 
490:     public function estimateUpdatePostAction()
491:     {
492:         $code = (string) $this->getRequest()->getParam('estimate_method');
493:         if (!empty($code)) {
494:             $this->_getQuote()->getShippingAddress()->setShippingMethod($code)/*->collectTotals()*/->save();
495:         }
496:         $this->_goBack();
497:     }
498: 
499:     /**
500:      * Initialize coupon
501:      */
502:     public function couponPostAction()
503:     {
504:         /**
505:          * No reason continue with empty shopping cart
506:          */
507:         if (!$this->_getCart()->getQuote()->getItemsCount()) {
508:             $this->_goBack();
509:             return;
510:         }
511: 
512:         $couponCode = (string) $this->getRequest()->getParam('coupon_code');
513:         if ($this->getRequest()->getParam('remove') == 1) {
514:             $couponCode = '';
515:         }
516:         $oldCouponCode = $this->_getQuote()->getCouponCode();
517: 
518:         if (!strlen($couponCode) && !strlen($oldCouponCode)) {
519:             $this->_goBack();
520:             return;
521:         }
522: 
523:         try {
524:             $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
525:             $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
526:                 ->collectTotals()
527:                 ->save();
528: 
529:             if (strlen($couponCode)) {
530:                 if ($couponCode == $this->_getQuote()->getCouponCode()) {
531:                     $this->_getSession()->addSuccess(
532:                         $this->__('Coupon code "%s" was applied.', Mage::helper('core')->htmlEscape($couponCode))
533:                     );
534:                 }
535:                 else {
536:                     $this->_getSession()->addError(
537:                         $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
538:                     );
539:                 }
540:             } else {
541:                 $this->_getSession()->addSuccess($this->__('Coupon code was canceled.'));
542:             }
543: 
544:         } catch (Mage_Core_Exception $e) {
545:             $this->_getSession()->addError($e->getMessage());
546:         } catch (Exception $e) {
547:             $this->_getSession()->addError($this->__('Cannot apply the coupon code.'));
548:             Mage::logException($e);
549:         }
550: 
551:         $this->_goBack();
552:     }
553: }
554: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0