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_Adminhtml
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: * Adminhtml quote session
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Model_Session_Quote extends Mage_Core_Model_Session_Abstract
35: {
36: const XML_PATH_DEFAULT_CREATEACCOUNT_GROUP = 'customer/create_account/default_group';
37:
38: /**
39: * Quote model object
40: *
41: * @var Mage_Sales_Model_Quote
42: */
43: protected $_quote = null;
44:
45: /**
46: * Customer mofrl object
47: *
48: * @var Mage_Customer_Model_Customer
49: */
50: protected $_customer= null;
51:
52: /**
53: * Store model object
54: *
55: * @var Mage_Core_Model_Store
56: */
57: protected $_store = null;
58:
59: /**
60: * Order model object
61: *
62: * @var Mage_Sales_Model_Order
63: */
64: protected $_order = null;
65:
66: public function __construct()
67: {
68: $this->init('adminhtml_quote');
69: if (Mage::app()->isSingleStoreMode()) {
70: $this->setStoreId(Mage::app()->getStore(true)->getId());
71: }
72: }
73:
74: /**
75: * Retrieve quote model object
76: *
77: * @return Mage_Sales_Model_Quote
78: */
79: public function getQuote()
80: {
81: if (is_null($this->_quote)) {
82: $this->_quote = Mage::getModel('sales/quote');
83: if ($this->getStoreId() && $this->getQuoteId()) {
84: $this->_quote->setStoreId($this->getStoreId())
85: ->load($this->getQuoteId());
86: }
87: elseif($this->getStoreId() && $this->hasCustomerId()) {
88: $this->_quote->setStoreId($this->getStoreId())
89: ->setCustomerGroupId(Mage::getStoreConfig(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP))
90: ->assignCustomer($this->getCustomer())
91: ->setIsActive(false)
92: ->save();
93: $this->setQuoteId($this->_quote->getId());
94: }
95: $this->_quote->setIgnoreOldQty(true);
96: $this->_quote->setIsSuperMode(true);
97: }
98: return $this->_quote;
99: }
100:
101: /**
102: * Set customer model object
103: * To enable quick switch of preconfigured customer
104: * @param Mage_Customer_Model_Customer $customer
105: * @return Mage_Adminhtml_Model_Session_Quote
106: */
107: public function setCustomer(Mage_Customer_Model_Customer $customer)
108: {
109: $this->_customer = $customer;
110: return $this;
111: }
112:
113: /**
114: * Retrieve customer model object
115: * @param bool $forceReload
116: * @param bool $useSetStore
117: * @return Mage_Customer_Model_Customer
118: */
119: public function getCustomer($forceReload=false, $useSetStore=false)
120: {
121: if (is_null($this->_customer) || $forceReload) {
122: $this->_customer = Mage::getModel('customer/customer');
123: if ($useSetStore && $this->getStore()->getId()) {
124: $this->_customer->setStore($this->getStore());
125: }
126: if ($customerId = $this->getCustomerId()) {
127: $this->_customer->load($customerId);
128: }
129: }
130: return $this->_customer;
131: }
132:
133: /**
134: * Retrieve store model object
135: *
136: * @return Mage_Core_Model_Store
137: */
138: public function getStore()
139: {
140: if (is_null($this->_store)) {
141: $this->_store = Mage::app()->getStore($this->getStoreId());
142: if ($currencyId = $this->getCurrencyId()) {
143: $this->_store->setCurrentCurrencyCode($currencyId);
144: }
145: }
146: return $this->_store;
147: }
148:
149: /**
150: * Retrieve order model object
151: *
152: * @return Mage_Sales_Model_Order
153: */
154: public function getOrder()
155: {
156: if (is_null($this->_order)) {
157: $this->_order = Mage::getModel('sales/order');
158: if ($this->getOrderId()) {
159: $this->_order->load($this->getOrderId());
160: }
161: }
162: return $this->_order;
163: }
164: }
165: