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: class Mage_Checkout_Model_Session extends Mage_Core_Model_Session_Abstract
 29: {
 30:     const CHECKOUT_STATE_BEGIN = 'begin';
 31: 
 32:     /**
 33:      * Quote instance
 34:      *
 35:      * @var null|Mage_Sales_Model_Quote
 36:      */
 37:     protected $_quote;
 38: 
 39:     /**
 40:      * Customer instance
 41:      *
 42:      * @var null|Mage_Customer_Model_Customer
 43:      */
 44:     protected $_customer;
 45: 
 46:     /**
 47:      * Whether load only active quote
 48:      *
 49:      * @var bool
 50:      */
 51:     protected $_loadInactive = false;
 52: 
 53:     /**
 54:      * Class constructor. Initialize checkout session namespace
 55:      */
 56:     public function __construct()
 57:     {
 58:         $this->init('checkout');
 59:     }
 60: 
 61:     /**
 62:      * Unset all data associated with object
 63:      */
 64:     public function unsetAll()
 65:     {
 66:         parent::unsetAll();
 67:         $this->_quote = null;
 68:     }
 69: 
 70:     /**
 71:      * Set customer instance
 72:      *
 73:      * @param Mage_Customer_Model_Customer|null $customer
 74:      * @return Mage_Checkout_Model_Session
 75:      */
 76:     public function setCustomer($customer)
 77:     {
 78:         $this->_customer = $customer;
 79:         return $this;
 80:     }
 81: 
 82:     /**
 83:      * Check whether current session has quote
 84:      *
 85:      * @return bool
 86:      */
 87:     public function hasQuote()
 88:     {
 89:         return isset($this->_quote);
 90:     }
 91: 
 92:     /**
 93:      * Set quote to be loaded even if inactive
 94:      *
 95:      * @param bool $load
 96:      * @return Mage_Checkout_Model_Session
 97:      */
 98:     public function setLoadInactive($load = true)
 99:     {
100:         $this->_loadInactive = $load;
101:         return $this;
102:     }
103: 
104:     /**
105:      * Get checkout quote instance by current session
106:      *
107:      * @return Mage_Sales_Model_Quote
108:      */
109:     public function getQuote()
110:     {
111:         Mage::dispatchEvent('custom_quote_process', array('checkout_session' => $this));
112: 
113:         if ($this->_quote === null) {
114:             /** @var $quote Mage_Sales_Model_Quote */
115:             $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
116:             if ($this->getQuoteId()) {
117:                 if ($this->_loadInactive) {
118:                     $quote->load($this->getQuoteId());
119:                 } else {
120:                     $quote->loadActive($this->getQuoteId());
121:                 }
122:                 if ($quote->getId()) {
123:                     /**
124:                      * If current currency code of quote is not equal current currency code of store,
125:                      * need recalculate totals of quote. It is possible if customer use currency switcher or
126:                      * store switcher.
127:                      */
128:                     if ($quote->getQuoteCurrencyCode() != Mage::app()->getStore()->getCurrentCurrencyCode()) {
129:                         $quote->setStore(Mage::app()->getStore());
130:                         $quote->collectTotals()->save();
131:                         /*
132:                          * We mast to create new quote object, because collectTotals()
133:                          * can to create links with other objects.
134:                          */
135:                         $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
136:                         $quote->load($this->getQuoteId());
137:                     }
138:                 } else {
139:                     $this->setQuoteId(null);
140:                 }
141:             }
142: 
143:             $customerSession = Mage::getSingleton('customer/session');
144: 
145:             if (!$this->getQuoteId()) {
146:                 if ($customerSession->isLoggedIn() || $this->_customer) {
147:                     $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
148:                     $quote->loadByCustomer($customer);
149:                     $this->setQuoteId($quote->getId());
150:                 } else {
151:                     $quote->setIsCheckoutCart(true);
152:                     Mage::dispatchEvent('checkout_quote_init', array('quote'=>$quote));
153:                 }
154:             }
155: 
156:             if ($this->getQuoteId()) {
157:                 if ($customerSession->isLoggedIn() || $this->_customer) {
158:                     $customer = ($this->_customer) ? $this->_customer : $customerSession->getCustomer();
159:                     $quote->setCustomer($customer);
160:                 }
161:             }
162: 
163:             $quote->setStore(Mage::app()->getStore());
164:             $this->_quote = $quote;
165:         }
166: 
167:         if ($remoteAddr = Mage::helper('core/http')->getRemoteAddr()) {
168:             $this->_quote->setRemoteIp($remoteAddr);
169:             $xForwardIp = Mage::app()->getRequest()->getServer('HTTP_X_FORWARDED_FOR');
170:             $this->_quote->setXForwardedFor($xForwardIp);
171:         }
172:         return $this->_quote;
173:     }
174: 
175:     protected function _getQuoteIdKey()
176:     {
177:         return 'quote_id_' . Mage::app()->getStore()->getWebsiteId();
178:     }
179: 
180:     public function setQuoteId($quoteId)
181:     {
182:         $this->setData($this->_getQuoteIdKey(), $quoteId);
183:     }
184: 
185:     public function getQuoteId()
186:     {
187:         return $this->getData($this->_getQuoteIdKey());
188:     }
189: 
190:     /**
191:      * Load data for customer quote and merge with current quote
192:      *
193:      * @return Mage_Checkout_Model_Session
194:      */
195:     public function loadCustomerQuote()
196:     {
197:         if (!Mage::getSingleton('customer/session')->getCustomerId()) {
198:             return $this;
199:         }
200: 
201:         Mage::dispatchEvent('load_customer_quote_before', array('checkout_session' => $this));
202: 
203:         $customerQuote = Mage::getModel('sales/quote')
204:             ->setStoreId(Mage::app()->getStore()->getId())
205:             ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId());
206: 
207:         if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
208:             if ($this->getQuoteId()) {
209:                 $customerQuote->merge($this->getQuote())
210:                     ->collectTotals()
211:                     ->save();
212:             }
213: 
214:             $this->setQuoteId($customerQuote->getId());
215: 
216:             if ($this->_quote) {
217:                 $this->_quote->delete();
218:             }
219:             $this->_quote = $customerQuote;
220:         } else {
221:             $this->getQuote()->getBillingAddress();
222:             $this->getQuote()->getShippingAddress();
223:             $this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer())
224:                 ->setTotalsCollectedFlag(false)
225:                 ->collectTotals()
226:                 ->save();
227:         }
228:         return $this;
229:     }
230: 
231:     public function setStepData($step, $data, $value=null)
232:     {
233:         $steps = $this->getSteps();
234:         if (is_null($value)) {
235:             if (is_array($data)) {
236:                 $steps[$step] = $data;
237:             }
238:         } else {
239:             if (!isset($steps[$step])) {
240:                 $steps[$step] = array();
241:             }
242:             if (is_string($data)) {
243:                 $steps[$step][$data] = $value;
244:             }
245:         }
246:         $this->setSteps($steps);
247: 
248:         return $this;
249:     }
250: 
251:     public function getStepData($step=null, $data=null)
252:     {
253:         $steps = $this->getSteps();
254:         if (is_null($step)) {
255:             return $steps;
256:         }
257:         if (!isset($steps[$step])) {
258:             return false;
259:         }
260:         if (is_null($data)) {
261:             return $steps[$step];
262:         }
263:         if (!is_string($data) || !isset($steps[$step][$data])) {
264:             return false;
265:         }
266:         return $steps[$step][$data];
267:     }
268: 
269:     /**
270:      * Retrieves list of all saved additional messages for different instances (e.g. quote items) in checkout session
271:      * Returned: array(itemKey => messageCollection, ...)
272:      * where itemKey is a unique hash (e.g 'quote_item17') to distinguish item messages among message collections
273:      *
274:      * @param bool $clear
275:      *
276:      * @return array
277:      */
278:     public function getAdditionalMessages($clear = false)
279:     {
280:         $additionalMessages = $this->getData('additional_messages');
281:         if (!$additionalMessages) {
282:             return array();
283:         }
284:         if ($clear) {
285:             $this->setData('additional_messages', null);
286:         }
287:         return $additionalMessages;
288:     }
289: 
290:     /**
291:      * Retrieves list of item additional messages
292:      * itemKey is a unique hash (e.g 'quote_item17') to distinguish item messages among message collections
293:      *
294:      * @param string $itemKey
295:      * @param bool $clear
296:      *
297:      * @return null|Mage_Core_Model_Message_Collection
298:      */
299:     public function getItemAdditionalMessages($itemKey, $clear = false)
300:     {
301:         $allMessages = $this->getAdditionalMessages();
302:         if (!isset($allMessages[$itemKey])) {
303:             return null;
304:         }
305: 
306:         $messages = $allMessages[$itemKey];
307:         if ($clear) {
308:             unset($allMessages[$itemKey]);
309:             $this->setAdditionalMessages($allMessages);
310:         }
311:         return $messages;
312:     }
313: 
314:     /**
315:      * Adds new message in this session to a list of additional messages for some item
316:      * itemKey is a unique hash (e.g 'quote_item17') to distinguish item messages among message collections
317:      *
318:      * @param string $itemKey
319:      * @param Mage_Core_Model_Message $message
320:      *
321:      * @return Mage_Checkout_Model_Session
322:      */
323:     public function addItemAdditionalMessage($itemKey, $message)
324:     {
325:         $allMessages = $this->getAdditionalMessages();
326:         if (!isset($allMessages[$itemKey])) {
327:             $allMessages[$itemKey] = Mage::getModel('core/message_collection');
328:         }
329:         $allMessages[$itemKey]->add($message);
330:         $this->setAdditionalMessages($allMessages);
331: 
332:         return $this;
333:     }
334: 
335:     /**
336:      * Retrieves list of quote item messages
337:      * @param int $itemId
338:      * @param bool $clear
339:      *
340:      * @return null|Mage_Core_Model_Message_Collection
341:      */
342:     public function getQuoteItemMessages($itemId, $clear = false)
343:     {
344:         return $this->getItemAdditionalMessages('quote_item' . $itemId, $clear);
345:     }
346: 
347:     /**
348:      * Adds new message to a list of quote item messages, saved in this session
349:      *
350:      * @param int $itemId
351:      * @param Mage_Core_Model_Message $message
352:      *
353:      * @return Mage_Checkout_Model_Session
354:      */
355:     function addQuoteItemMessage($itemId, $message)
356:     {
357:         return $this->addItemAdditionalMessage('quote_item' . $itemId, $message);
358:     }
359: 
360:     public function clear()
361:     {
362:         Mage::dispatchEvent('checkout_quote_destroy', array('quote'=>$this->getQuote()));
363:         $this->_quote = null;
364:         $this->setQuoteId(null);
365:         $this->setLastSuccessQuoteId(null);
366:     }
367: 
368:     /**
369:      * Clear misc checkout parameters
370:      */
371:     public function clearHelperData()
372:     {
373:         $this->setLastBillingAgreementId(null)
374:             ->setRedirectUrl(null)
375:             ->setLastOrderId(null)
376:             ->setLastRealOrderId(null)
377:             ->setLastRecurringProfileIds(null)
378:             ->setAdditionalMessages(null)
379:         ;
380:     }
381: 
382:     public function resetCheckout()
383:     {
384:         $this->setCheckoutState(self::CHECKOUT_STATE_BEGIN);
385:         return $this;
386:     }
387: 
388:     public function replaceQuote($quote)
389:     {
390:         $this->_quote = $quote;
391:         $this->setQuoteId($quote->getId());
392:         return $this;
393:     }
394: }
395: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0