PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Checkout/Model/Type/Abstract.php

https://github.com/FiveDigital/magento2
PHP | 152 lines | 78 code | 8 blank | 66 comment | 8 complexity | 25aaa2d093af3ee0f986c45e15bb1000 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  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. * Cehckout type abstract class
  28. *
  29. * @category Mage
  30. * @package Mage_Checkout
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. abstract class Mage_Checkout_Model_Type_Abstract extends Varien_Object
  34. {
  35. /**
  36. * Retrieve checkout session model
  37. *
  38. * @return Mage_Checkout_Model_Session
  39. */
  40. public function getCheckoutSession()
  41. {
  42. $checkout = $this->getData('checkout_session');
  43. if (is_null($checkout)) {
  44. $checkout = Mage::getSingleton('Mage_Checkout_Model_Session');
  45. $this->setData('checkout_session', $checkout);
  46. }
  47. return $checkout;
  48. }
  49. /**
  50. * Retrieve quote model
  51. *
  52. * @return Mage_Sales_Model_Quote
  53. */
  54. public function getQuote()
  55. {
  56. return $this->getCheckoutSession()->getQuote();
  57. }
  58. /**
  59. * Retrieve quote items
  60. *
  61. * @return array
  62. */
  63. public function getQuoteItems()
  64. {
  65. return $this->getQuote()->getAllItems();
  66. }
  67. /**
  68. * Retrieve customer session vodel
  69. *
  70. * @return Mage_Customer_Model_Session
  71. */
  72. public function getCustomerSession()
  73. {
  74. $customer = $this->getData('customer_session');
  75. if (is_null($customer)) {
  76. $customer = Mage::getSingleton('Mage_Customer_Model_Session');
  77. $this->setData('customer_session', $customer);
  78. }
  79. return $customer;
  80. }
  81. /**
  82. * Retrieve customer object
  83. *
  84. * @return Mage_Customer_Model_Customer
  85. */
  86. public function getCustomer()
  87. {
  88. return $this->getCustomerSession()->getCustomer();
  89. }
  90. /**
  91. * Retrieve customer default shipping address
  92. *
  93. * @return Mage_Customer_Model_Address || false
  94. */
  95. public function getCustomerDefaultShippingAddress()
  96. {
  97. $address = $this->getData('customer_default_shipping_address');
  98. if (is_null($address)) {
  99. $address = $this->getCustomer()->getDefaultShippingAddress();
  100. if (!$address) {
  101. foreach ($this->getCustomer()->getAddresses() as $address) {
  102. if($address){
  103. break;
  104. }
  105. }
  106. }
  107. $this->setData('customer_default_shipping_address', $address);
  108. }
  109. return $address;
  110. }
  111. /**
  112. * Retrieve customer default billing address
  113. *
  114. * @return Mage_Customer_Model_Address || false
  115. */
  116. public function getCustomerDefaultBillingAddress()
  117. {
  118. $address = $this->getData('customer_default_billing_address');
  119. if (is_null($address)) {
  120. $address = $this->getCustomer()->getDefaultBillingAddress();
  121. if (!$address) {
  122. foreach ($this->getCustomer()->getAddresses() as $address) {
  123. if($address){
  124. break;
  125. }
  126. }
  127. }
  128. $this->setData('customer_default_billing_address', $address);
  129. }
  130. return $address;
  131. }
  132. protected function _createOrderFromAddress($address)
  133. {
  134. $order = Mage::getModel('Mage_Sales_Model_Order')->createFromQuoteAddress($address)
  135. ->setCustomerId($this->getCustomer()->getId())
  136. ->setGlobalCurrencyCode('USD')
  137. ->setBaseCurrencyCode('USD')
  138. ->setStoreCurrencyCode('USD')
  139. ->setOrderCurrencyCode('USD')
  140. ->setStoreToBaseRate(1)
  141. ->setStoreToOrderRate(1);
  142. return $order;
  143. }
  144. }