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 model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Checkout
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Checkout_Model_Cart extends Varien_Object implements Mage_Checkout_Model_Cart_Interface
 35: {
 36:     /**
 37:      * Shopping cart items summary quantity(s)
 38:      *
 39:      * @var int|null
 40:      */
 41:     protected $_summaryQty;
 42: 
 43:     /**
 44:      * List of product ids in shopping cart
 45:      *
 46:      * @var array|null
 47:      */
 48:     protected $_productIds;
 49: 
 50:     /**
 51:      * Get shopping cart resource model
 52:      *
 53:      * @return Mage_Checkout_Model_Resource_Cart
 54:      */
 55:     protected function _getResource()
 56:     {
 57:         return Mage::getResourceSingleton('checkout/cart');
 58:     }
 59: 
 60:     /**
 61:      * Retrieve checkout session model
 62:      *
 63:      * @return Mage_Checkout_Model_Session
 64:      */
 65:     public function getCheckoutSession()
 66:     {
 67:         return Mage::getSingleton('checkout/session');
 68:     }
 69: 
 70:     /**
 71:      * Retrieve customer session model
 72:      *
 73:      * @return Mage_Customer_Model_Customer
 74:      */
 75:     public function getCustomerSession()
 76:     {
 77:         return Mage::getSingleton('customer/session');
 78:     }
 79: 
 80:     /**
 81:      * List of shopping cart items
 82:      *
 83:      * @return Mage_Eav_Model_Entity_Collection_Abstract|array
 84:      */
 85:     public function getItems()
 86:     {
 87:         if (!$this->getQuote()->getId()) {
 88:             return array();
 89:         }
 90:         return $this->getQuote()->getItemsCollection();
 91:     }
 92: 
 93:     /**
 94:      * Retrieve array of cart product ids
 95:      *
 96:      * @return array
 97:      */
 98:     public function getQuoteProductIds()
 99:     {
100:         $products = $this->getData('product_ids');
101:         if (is_null($products)) {
102:             $products = array();
103:             foreach ($this->getQuote()->getAllItems() as $item) {
104:                 $products[$item->getProductId()] = $item->getProductId();
105:             }
106:             $this->setData('product_ids', $products);
107:         }
108:         return $products;
109:     }
110: 
111:     /**
112:      * Get quote object associated with cart. By default it is current customer session quote
113:      *
114:      * @return Mage_Sales_Model_Quote
115:      */
116:     public function getQuote()
117:     {
118:         if (!$this->hasData('quote')) {
119:             $this->setData('quote', $this->getCheckoutSession()->getQuote());
120:         }
121:         return $this->_getData('quote');
122:     }
123: 
124:     /**
125:      * Set quote object associated with the cart
126:      *
127:      * @param Mage_Sales_Model_Quote $quote
128:      * @return Mage_Checkout_Model_Cart
129:      */
130:     public function setQuote(Mage_Sales_Model_Quote $quote)
131:     {
132:         $this->setData('quote', $quote);
133:         return $this;
134:     }
135: 
136:     /**
137:      * Initialize cart quote state to be able use it on cart page
138:      *
139:      * @return Mage_Checkout_Model_Cart
140:      */
141:     public function init()
142:     {
143:         $this->getQuote()->setCheckoutMethod('');
144: 
145:         /**
146:          * If user try do checkout, reset shipping and payment data
147:          */
148:         if ($this->getCheckoutSession()->getCheckoutState() !== Mage_Checkout_Model_Session::CHECKOUT_STATE_BEGIN) {
149:             $this->getQuote()
150:                 ->removeAllAddresses()
151:                 ->removePayment();
152:             $this->getCheckoutSession()->resetCheckout();
153:         }
154: 
155:         if (!$this->getQuote()->hasItems()) {
156:             $this->getQuote()->getShippingAddress()
157:                 ->setCollectShippingRates(false)
158:                 ->removeAllShippingRates();
159:         }
160: 
161:         return $this;
162:     }
163: 
164:     /**
165:      * Convert order item to quote item
166:      *
167:      * @param Mage_Sales_Model_Order_Item $orderItem
168:      * @param mixed $qtyFlag if is null set product qty like in order
169:      * @return Mage_Checkout_Model_Cart
170:      */
171:     public function addOrderItem($orderItem, $qtyFlag=null)
172:     {
173:         /* @var $orderItem Mage_Sales_Model_Order_Item */
174:         if (is_null($orderItem->getParentItem())) {
175:             $product = Mage::getModel('catalog/product')
176:                 ->setStoreId(Mage::app()->getStore()->getId())
177:                 ->load($orderItem->getProductId());
178:             if (!$product->getId()) {
179:                 return $this;
180:             }
181: 
182:             $info = $orderItem->getProductOptionByCode('info_buyRequest');
183:             $info = new Varien_Object($info);
184:             if (is_null($qtyFlag)) {
185:                 $info->setQty($orderItem->getQtyOrdered());
186:             } else {
187:                 $info->setQty(1);
188:             }
189: 
190:             $this->addProduct($product, $info);
191:         }
192:         return $this;
193:     }
194: 
195:     /**
196:      * Get product object based on requested product information
197:      *
198:      * @param   mixed $productInfo
199:      * @return  Mage_Catalog_Model_Product
200:      */
201:     protected function _getProduct($productInfo)
202:     {
203:         $product = null;
204:         if ($productInfo instanceof Mage_Catalog_Model_Product) {
205:             $product = $productInfo;
206:         } elseif (is_int($productInfo) || is_string($productInfo)) {
207:             $product = Mage::getModel('catalog/product')
208:                 ->setStoreId(Mage::app()->getStore()->getId())
209:                 ->load($productInfo);
210:         }
211:         $currentWebsiteId = Mage::app()->getStore()->getWebsiteId();
212:         if (!$product
213:             || !$product->getId()
214:             || !is_array($product->getWebsiteIds())
215:             || !in_array($currentWebsiteId, $product->getWebsiteIds())
216:         ) {
217:             Mage::throwException(Mage::helper('checkout')->__('The product could not be found.'));
218:         }
219:         return $product;
220:     }
221: 
222:     /**
223:      * Get request for product add to cart procedure
224:      *
225:      * @param   mixed $requestInfo
226:      * @return  Varien_Object
227:      */
228:     protected function _getProductRequest($requestInfo)
229:     {
230:         if ($requestInfo instanceof Varien_Object) {
231:             $request = $requestInfo;
232:         } elseif (is_numeric($requestInfo)) {
233:             $request = new Varien_Object(array('qty' => $requestInfo));
234:         } else {
235:             $request = new Varien_Object($requestInfo);
236:         }
237: 
238:         if (!$request->hasQty()) {
239:             $request->setQty(1);
240:         }
241: 
242:         return $request;
243:     }
244: 
245:     /**
246:      * Add product to shopping cart (quote)
247:      *
248:      * @param   int|Mage_Catalog_Model_Product $productInfo
249:      * @param   mixed $requestInfo
250:      * @return  Mage_Checkout_Model_Cart
251:      */
252:     public function addProduct($productInfo, $requestInfo=null)
253:     {
254:         $product = $this->_getProduct($productInfo);
255:         $request = $this->_getProductRequest($requestInfo);
256: 
257:         $productId = $product->getId();
258: 
259:         if ($product->getStockItem()) {
260:             $minimumQty = $product->getStockItem()->getMinSaleQty();
261:             //If product was not found in cart and there is set minimal qty for it
262:             if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty
263:                 && !$this->getQuote()->hasProductId($productId)
264:             ){
265:                 $request->setQty($minimumQty);
266:             }
267:         }
268: 
269:         if ($productId) {
270:             try {
271:                 $result = $this->getQuote()->addProduct($product, $request);
272:             } catch (Mage_Core_Exception $e) {
273:                 $this->getCheckoutSession()->setUseNotice(false);
274:                 $result = $e->getMessage();
275:             }
276:             /**
277:              * String we can get if prepare process has error
278:              */
279:             if (is_string($result)) {
280:                 $redirectUrl = ($product->hasOptionsValidationFail())
281:                     ? $product->getUrlModel()->getUrl(
282:                         $product,
283:                         array('_query' => array('startcustomization' => 1))
284:                     )
285:                     : $product->getProductUrl();
286:                 $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
287:                 if ($this->getCheckoutSession()->getUseNotice() === null) {
288:                     $this->getCheckoutSession()->setUseNotice(true);
289:                 }
290:                 Mage::throwException($result);
291:             }
292:         } else {
293:             Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
294:         }
295: 
296:         Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
297:         $this->getCheckoutSession()->setLastAddedProductId($productId);
298:         return $this;
299:     }
300: 
301:     /**
302:      * Adding products to cart by ids
303:      *
304:      * @param   array $productIds
305:      * @return  Mage_Checkout_Model_Cart
306:      */
307:     public function addProductsByIds($productIds)
308:     {
309:         $allAvailable = true;
310:         $allAdded     = true;
311: 
312:         if (!empty($productIds)) {
313:             foreach ($productIds as $productId) {
314:                 $productId = (int) $productId;
315:                 if (!$productId) {
316:                     continue;
317:                 }
318:                 $product = $this->_getProduct($productId);
319:                 if ($product->getId() && $product->isVisibleInCatalog()) {
320:                     try {
321:                         $this->getQuote()->addProduct($product);
322:                     } catch (Exception $e){
323:                         $allAdded = false;
324:                     }
325:                 } else {
326:                     $allAvailable = false;
327:                 }
328:             }
329: 
330:             if (!$allAvailable) {
331:                 $this->getCheckoutSession()->addError(
332:                     Mage::helper('checkout')->__('Some of the requested products are unavailable.')
333:                 );
334:             }
335:             if (!$allAdded) {
336:                 $this->getCheckoutSession()->addError(
337:                     Mage::helper('checkout')->__('Some of the requested products are not available in the desired quantity.')
338:                 );
339:             }
340:         }
341:         return $this;
342:     }
343: 
344:     /**
345:      * Returns suggested quantities for items.
346:      * Can be used to automatically fix user entered quantities before updating cart
347:      * so that cart contains valid qty values
348:      *
349:      * $data is an array of ($quoteItemId => (item info array with 'qty' key), ...)
350:      *
351:      * @param   array $data
352:      * @return  array
353:      */
354:     public function suggestItemsQty($data)
355:     {
356:         foreach ($data as $itemId => $itemInfo) {
357:             if (!isset($itemInfo['qty'])) {
358:                 continue;
359:             }
360:             $qty = (float) $itemInfo['qty'];
361:             if ($qty <= 0) {
362:                 continue;
363:             }
364: 
365:             $quoteItem = $this->getQuote()->getItemById($itemId);
366:             if (!$quoteItem) {
367:                 continue;
368:             }
369: 
370:             $product = $quoteItem->getProduct();
371:             if (!$product) {
372:                 continue;
373:             }
374: 
375:             /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
376:             $stockItem = $product->getStockItem();
377:             if (!$stockItem) {
378:                 continue;
379:             }
380: 
381:             $data[$itemId]['before_suggest_qty'] = $qty;
382:             $data[$itemId]['qty'] = $stockItem->suggestQty($qty);
383:         }
384: 
385:         return $data;
386:     }
387: 
388:     /**
389:      * Update cart items information
390:      *
391:      * @param   array $data
392:      * @return  Mage_Checkout_Model_Cart
393:      */
394:     public function updateItems($data)
395:     {
396:         Mage::dispatchEvent('checkout_cart_update_items_before', array('cart'=>$this, 'info'=>$data));
397: 
398:         /* @var $messageFactory Mage_Core_Model_Message */
399:         $messageFactory = Mage::getSingleton('core/message');
400:         $session = $this->getCheckoutSession();
401:         $qtyRecalculatedFlag = false;
402:         foreach ($data as $itemId => $itemInfo) {
403:             $item = $this->getQuote()->getItemById($itemId);
404:             if (!$item) {
405:                 continue;
406:             }
407: 
408:             if (!empty($itemInfo['remove']) || (isset($itemInfo['qty']) && $itemInfo['qty']=='0')) {
409:                 $this->removeItem($itemId);
410:                 continue;
411:             }
412: 
413:             $qty = isset($itemInfo['qty']) ? (float) $itemInfo['qty'] : false;
414:             if ($qty > 0) {
415:                 $item->setQty($qty);
416: 
417:                 $itemInQuote = $this->getQuote()->getItemById($item->getId());
418: 
419:                 if (!$itemInQuote && $item->getHasError()) {
420:                     Mage::throwException($item->getMessage());
421:                 }
422: 
423:                 if (isset($itemInfo['before_suggest_qty']) && ($itemInfo['before_suggest_qty'] != $qty)) {
424:                     $qtyRecalculatedFlag = true;
425:                     $message = $messageFactory->notice(Mage::helper('checkout')->__('Quantity was recalculated from %d to %d', $itemInfo['before_suggest_qty'], $qty));
426:                     $session->addQuoteItemMessage($item->getId(), $message);
427:                 }
428:             }
429:         }
430: 
431:         if ($qtyRecalculatedFlag) {
432:             $session->addNotice(
433:                 Mage::helper('checkout')->__('Some products quantities were recalculated because of quantity increment mismatch')
434:             );
435:         }
436: 
437:         Mage::dispatchEvent('checkout_cart_update_items_after', array('cart'=>$this, 'info'=>$data));
438:         return $this;
439:     }
440: 
441:     /**
442:      * Remove item from cart
443:      *
444:      * @param   int $itemId
445:      * @return  Mage_Checkout_Model_Cart
446:      */
447:     public function removeItem($itemId)
448:     {
449:         $this->getQuote()->removeItem($itemId);
450:         return $this;
451:     }
452: 
453:     /**
454:      * Save cart
455:      *
456:      * @return Mage_Checkout_Model_Cart
457:      */
458:     public function save()
459:     {
460:         Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));
461: 
462:         $this->getQuote()->getBillingAddress();
463:         $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
464:         $this->getQuote()->collectTotals();
465:         $this->getQuote()->save();
466:         $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
467:         /**
468:          * Cart save usually called after changes with cart items.
469:          */
470:         Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
471:         return $this;
472:     }
473: 
474:     /**
475:      * Save cart (implement interface method)
476:      */
477:     public function saveQuote()
478:     {
479:         $this->save();
480:     }
481: 
482:     /**
483:      * Mark all quote items as deleted (empty shopping cart)
484:      *
485:      * @return Mage_Checkout_Model_Cart
486:      */
487:     public function truncate()
488:     {
489:         $this->getQuote()->removeAllItems();
490:         return $this;
491:     }
492: 
493:     public function getProductIds()
494:     {
495:         $quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
496:         if (null === $this->_productIds) {
497:             $this->_productIds = array();
498:             if ($this->getSummaryQty()>0) {
499:                foreach ($this->getQuote()->getAllItems() as $item) {
500:                    $this->_productIds[] = $item->getProductId();
501:                }
502:             }
503:             $this->_productIds = array_unique($this->_productIds);
504:         }
505:         return $this->_productIds;
506:     }
507: 
508:     /**
509:      * Get shopping cart items summary (includes config settings)
510:      *
511:      * @return int|float
512:      */
513:     public function getSummaryQty()
514:     {
515:         $quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
516: 
517:         //If there is no quote id in session trying to load quote
518:         //and get new quote id. This is done for cases when quote was created
519:         //not by customer (from backend for example).
520:         if (!$quoteId && Mage::getSingleton('customer/session')->isLoggedIn()) {
521:             $quote = Mage::getSingleton('checkout/session')->getQuote();
522:             $quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
523:         }
524: 
525:         if ($quoteId && $this->_summaryQty === null) {
526:             if (Mage::getStoreConfig('checkout/cart_link/use_qty')) {
527:                 $this->_summaryQty = $this->getItemsQty();
528:             } else {
529:                 $this->_summaryQty = $this->getItemsCount();
530:             }
531:         }
532:         return $this->_summaryQty;
533:     }
534: 
535:     /**
536:      * Get shopping cart items count
537:      *
538:      * @return int
539:      */
540:     public function getItemsCount()
541:     {
542:         return $this->getQuote()->getItemsCount()*1;
543:     }
544: 
545:     /**
546:      * Get shopping cart summary qty
547:      *
548:      * @return int|float
549:      */
550:     public function getItemsQty()
551:     {
552:         return $this->getQuote()->getItemsQty()*1;
553:     }
554: 
555:     /**
556:      * Update item in shopping cart (quote)
557:      * $requestInfo - either qty (int) or buyRequest in form of array or Varien_Object
558:      * $updatingParams - information on how to perform update, passed to Quote->updateItem() method
559:      *
560:      * @param int $itemId
561:      * @param int|array|Varien_Object $requestInfo
562:      * @param null|array|Varien_Object $updatingParams
563:      * @return Mage_Sales_Model_Quote_Item|string
564:      *
565:      * @see Mage_Sales_Model_Quote::updateItem()
566:      */
567:     public function updateItem($itemId, $requestInfo = null, $updatingParams = null)
568:     {
569:         try {
570:             $item = $this->getQuote()->getItemById($itemId);
571:             if (!$item) {
572:                 Mage::throwException(Mage::helper('checkout')->__('Quote item does not exist.'));
573:             }
574:             $productId = $item->getProduct()->getId();
575:             $product = $this->_getProduct($productId);
576:             $request = $this->_getProductRequest($requestInfo);
577: 
578:             if ($product->getStockItem()) {
579:                 $minimumQty = $product->getStockItem()->getMinSaleQty();
580:                 // If product was not found in cart and there is set minimal qty for it
581:                 if ($minimumQty && ($minimumQty > 0)
582:                     && ($request->getQty() < $minimumQty)
583:                     && !$this->getQuote()->hasProductId($productId)
584:                 ) {
585:                     $request->setQty($minimumQty);
586:                 }
587:             }
588: 
589:             $result = $this->getQuote()->updateItem($itemId, $request, $updatingParams);
590:         } catch (Mage_Core_Exception $e) {
591:             $this->getCheckoutSession()->setUseNotice(false);
592:             $result = $e->getMessage();
593:         }
594: 
595:         /**
596:          * We can get string if updating process had some errors
597:          */
598:         if (is_string($result)) {
599:             if ($this->getCheckoutSession()->getUseNotice() === null) {
600:                 $this->getCheckoutSession()->setUseNotice(true);
601:             }
602:             Mage::throwException($result);
603:         }
604: 
605:         Mage::dispatchEvent('checkout_cart_product_update_after', array(
606:             'quote_item' => $result,
607:             'product' => $product
608:         ));
609:         $this->getCheckoutSession()->setLastAddedProductId($productId);
610:         return $result;
611:     }
612: }
613: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0