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: * Cehckout type abstract class
29: *
30: * @category Mage
31: * @package Mage_Checkout
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Checkout_Model_Type_Abstract extends Varien_Object
35: {
36: /**
37: * Retrieve checkout session model
38: *
39: * @return Mage_Checkout_Model_Session
40: */
41: public function getCheckoutSession()
42: {
43: $checkout = $this->getData('checkout_session');
44: if (is_null($checkout)) {
45: $checkout = Mage::getSingleton('checkout/session');
46: $this->setData('checkout_session', $checkout);
47: }
48: return $checkout;
49: }
50:
51: /**
52: * Retrieve quote model
53: *
54: * @return Mage_Sales_Model_Quote
55: */
56: public function getQuote()
57: {
58: return $this->getCheckoutSession()->getQuote();
59: }
60:
61: /**
62: * Retrieve quote items
63: *
64: * @return array
65: */
66: public function getQuoteItems()
67: {
68: return $this->getQuote()->getAllItems();
69: }
70:
71: /**
72: * Retrieve customer session vodel
73: *
74: * @return Mage_Customer_Model_Session
75: */
76: public function getCustomerSession()
77: {
78: $customer = $this->getData('customer_session');
79: if (is_null($customer)) {
80: $customer = Mage::getSingleton('customer/session');
81: $this->setData('customer_session', $customer);
82: }
83: return $customer;
84: }
85:
86: /**
87: * Retrieve customer object
88: *
89: * @return Mage_Customer_Model_Customer
90: */
91: public function getCustomer()
92: {
93: return $this->getCustomerSession()->getCustomer();
94: }
95:
96: /**
97: * Retrieve customer default shipping address
98: *
99: * @return Mage_Customer_Model_Address || false
100: */
101: public function getCustomerDefaultShippingAddress()
102: {
103: $address = $this->getData('customer_default_shipping_address');
104: if (is_null($address)) {
105: $address = $this->getCustomer()->getDefaultShippingAddress();
106: if (!$address) {
107: foreach ($this->getCustomer()->getAddresses() as $address) {
108: if($address){
109: break;
110: }
111: }
112: }
113: $this->setData('customer_default_shipping_address', $address);
114: }
115: return $address;
116: }
117:
118: /**
119: * Retrieve customer default billing address
120: *
121: * @return Mage_Customer_Model_Address || false
122: */
123: public function getCustomerDefaultBillingAddress()
124: {
125: $address = $this->getData('customer_default_billing_address');
126: if (is_null($address)) {
127: $address = $this->getCustomer()->getDefaultBillingAddress();
128: if (!$address) {
129: foreach ($this->getCustomer()->getAddresses() as $address) {
130: if($address){
131: break;
132: }
133: }
134: }
135: $this->setData('customer_default_billing_address', $address);
136: }
137: return $address;
138: }
139:
140: protected function _createOrderFromAddress($address)
141: {
142: $order = Mage::getModel('sales/order')->createFromQuoteAddress($address)
143: ->setCustomerId($this->getCustomer()->getId())
144: ->setGlobalCurrencyCode('USD')
145: ->setBaseCurrencyCode('USD')
146: ->setStoreCurrencyCode('USD')
147: ->setOrderCurrencyCode('USD')
148: ->setStoreToBaseRate(1)
149: ->setStoreToOrderRate(1);
150: return $order;
151: }
152:
153: /**
154: * @deprecated after 1.4.0.0-rc1
155: */
156: protected function _emailOrderConfirmation($email, $name, $order)
157: {
158: $mailer = Mage::getModel('core/email')
159: ->setTemplate('email/order.phtml')
160: ->setType('html')
161: ->setTemplateVar('order', $order)
162: ->setTemplateVar('quote', $this->getQuote())
163: ->setTemplateVar('name', $name)
164: ->setToName($name)
165: ->setToEmail($email)
166: ->send();
167: }
168: }
169: