00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 abstract class Mage_Checkout_Model_Type_Abstract extends Varien_Object
00035 {
00036
00037
00038
00039
00040
00041 public function getCheckoutSession()
00042 {
00043 $checkout = $this->getData('checkout_session');
00044 if (is_null($checkout)) {
00045 $checkout = Mage::getSingleton('checkout/session');
00046 $this->setData('checkout_session', $checkout);
00047 }
00048 return $checkout;
00049 }
00050
00051
00052
00053
00054
00055
00056 public function getQuote()
00057 {
00058 return $this->getCheckoutSession()->getQuote();
00059 }
00060
00061
00062
00063
00064
00065
00066 public function getQuoteItems()
00067 {
00068 return $this->getQuote()->getAllItems();
00069 }
00070
00071
00072
00073
00074
00075
00076 public function getCustomerSession()
00077 {
00078 $customer = $this->getData('customer_session');
00079 if (is_null($customer)) {
00080 $customer = Mage::getSingleton('customer/session');
00081 $this->setData('customer_session', $customer);
00082 }
00083 return $customer;
00084 }
00085
00086
00087
00088
00089
00090
00091 public function getCustomer()
00092 {
00093 return $this->getCustomerSession()->getCustomer();
00094 }
00095
00096
00097
00098
00099
00100
00101 public function getCustomerDefaultShippingAddress()
00102 {
00103 $address = $this->getData('customer_default_shipping_address');
00104 if (is_null($address)) {
00105 $address = $this->getCustomer()->getDefaultShippingAddress();
00106 if (!$address) {
00107 foreach ($this->getCustomer()->getAddresses() as $address) {
00108 if($address){
00109 break;
00110 }
00111 }
00112 }
00113 $this->setData('customer_default_shipping_address', $address);
00114 }
00115 return $address;
00116 }
00117
00118
00119
00120
00121
00122
00123 public function getCustomerDefaultBillingAddress()
00124 {
00125 $address = $this->getData('customer_default_billing_address');
00126 if (is_null($address)) {
00127 $address = $this->getCustomer()->getDefaultBillingAddress();
00128 $this->setData('customer_default_billing_address', $address);
00129 }
00130 return $address;
00131 }
00132
00133 protected function _createOrderFromAddress($address)
00134 {
00135 $order = Mage::getModel('sales/order')->createFromQuoteAddress($address)
00136 ->setCustomerId($this->getCustomer()->getId())
00137 ->setGlobalCurrencyCode('USD')
00138 ->setBaseCurrencyCode('USD')
00139 ->setStoreCurrencyCode('USD')
00140 ->setOrderCurrencyCode('USD')
00141 ->setStoreToBaseRate(1)
00142 ->setStoreToOrderRate(1);
00143 return $order;
00144 }
00145
00146 protected function _emailOrderConfirmation($email, $name, $order)
00147 {
00148 $mailer = Mage::getModel('core/email')
00149 ->setTemplate('email/order.phtml')
00150 ->setType('html')
00151 ->setTemplateVar('order', $order)
00152 ->setTemplateVar('quote', $this->getQuote())
00153 ->setTemplateVar('name', $name)
00154 ->setToName($name)
00155 ->setToEmail($email)
00156 ->send();
00157 }
00158 }