/app/code/community/TBT/Rewards/Block/Checkout/Onepage/Link.php

https://bitbucket.org/acidel/buykoala · PHP · 147 lines · 73 code · 14 blank · 60 comment · 5 complexity · 160dad26557733d856c9e527d996aa49 MD5 · raw file

  1. <?php
  2. /**
  3. * WDCA - Sweet Tooth
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS
  8. * License, which extends the Open Software License (OSL 3.0).
  9. * The Sweet Tooth License is available at this URL:
  10. * http://www.wdca.ca/sweet_tooth/sweet_tooth_license.txt
  11. * The Open Software License is available at this URL:
  12. * http://opensource.org/licenses/osl-3.0.php
  13. *
  14. * DISCLAIMER
  15. *
  16. * By adding to, editing, or in any way modifying this code, WDCA is
  17. * not held liable for any inconsistencies or abnormalities in the
  18. * behaviour of this code.
  19. * By adding to, editing, or in any way modifying this code, the Licensee
  20. * terminates any agreement of support offered by WDCA, outlined in the
  21. * provided Sweet Tooth License.
  22. * Upon discovery of modified code in the process of support, the Licensee
  23. * is still held accountable for any and all billable time WDCA spent
  24. * during the support process.
  25. * WDCA does not guarantee compatibility with any other framework extension.
  26. * WDCA is not responsbile for any inconsistencies or abnormalities in the
  27. * behaviour of this code if caused by other framework extension.
  28. * If you did not receive a copy of the license, please send an email to
  29. * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy
  30. * immediately.
  31. *
  32. * @category [TBT]
  33. * @package [TBT_Rewards]
  34. * @copyright Copyright (c) 2009 Web Development Canada (http://www.wdca.ca)
  35. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  36. */
  37. /**
  38. * ONE page checkout progress sidebox that tells the customer how many points they
  39. * are spending/earning
  40. *
  41. * @category TBT
  42. * @package TBT_Rewards
  43. * @author WDCA Sweet Tooth Team <contact@wdca.ca>
  44. */
  45. class TBT_Rewards_Block_Checkout_Onepage_Link extends Mage_Checkout_Block_Onepage_Link
  46. {
  47. protected function _construct()
  48. {
  49. parent::_construct();
  50. $this->setTemplate('rewards/checkout/onepage/link.phtml');
  51. }
  52. public function getBilling()
  53. {
  54. return $this->getQuote()->getBillingAddress();
  55. }
  56. public function getShipping()
  57. {
  58. return $this->getQuote()->getShippingAddress();
  59. }
  60. public function getShippingMethod()
  61. {
  62. return $this->getQuote()->getShippingAddress()->getShippingMethod();
  63. }
  64. public function getShippingDescription()
  65. {
  66. return $this->getQuote()->getShippingAddress()->getShippingDescription();
  67. }
  68. public function getShippingAmount()
  69. {
  70. /*$amount = $this->getQuote()->getShippingAddress()->getShippingAmount();
  71. $filter = Mage::app()->getStore()->getPriceFilter();
  72. return $filter->filter($amount);*/
  73. //return $this->helper('checkout')->formatPrice(
  74. // $this->getQuote()->getShippingAddress()->getShippingAmount()
  75. //);
  76. return $this->getQuote()->getShippingAddress()->getShippingAmount();
  77. }
  78. public function getShippingPriceInclTax()
  79. {
  80. $exclTax = $this->getQuote()->getShippingAddress()->getShippingAmount();
  81. $taxAmount = $this->getQuote()->getShippingAddress()->getShippingTaxAmount();
  82. return $this->formatPrice($exclTax + $taxAmount);
  83. }
  84. public function getShippingPriceExclTax()
  85. {
  86. return $this->formatPrice($this->getQuote()->getShippingAddress()->getShippingAmount());
  87. }
  88. public function formatPrice($price)
  89. {
  90. return $this->getQuote()->getStore()->formatPrice($price);
  91. }
  92. public function getTotalPointsSpending() {
  93. $spending = $this->_getRewardsSess()->getTotalPointsSpendingAsString();
  94. return $spending;
  95. }
  96. public function getTotalPointsEarning() {
  97. $spending = $this->_getRewardsSess()->getTotalPointsEarningAsString();
  98. return $spending;
  99. }
  100. /**
  101. * True if the customer can checkout given the current cart redemptions, false otherwise.
  102. *
  103. * @return TBT_Rewards_Model_Checkout_Cart_Observer
  104. */
  105. public function canCheckout() {
  106. // die(print_r($points_spent, true));
  107. $customer_is_logged_in = $this->_getRewardsSess()->isCustomerLoggedIn();
  108. if($customer_is_logged_in) {
  109. $is_cart_overspent = $this->_getRewardsSess()->isCartOverspent();
  110. if($is_cart_overspent) {
  111. return false;
  112. }
  113. } else {
  114. $has_redemptions = $this->_getRewardsSess()->hasRedemptions();
  115. $cant_use_redemptions_if_not_logged_in = !Mage::helper('rewards/config')->canUseRedemptionsIfNotLoggedIn();
  116. if($has_redemptions && $cant_use_redemptions_if_not_logged_in) {
  117. return false;
  118. }
  119. }
  120. return true;
  121. }
  122. public function isLoggedIn() {
  123. return Mage::getSingleton('rewards/session')->isCustomerLoggedIn();
  124. }
  125. /**
  126. * Fetches the customer session singleton
  127. *
  128. * @return TBT_Rewards_Model_Session
  129. */
  130. protected function _getRewardsSess() {
  131. return Mage::getSingleton('rewards/session');
  132. }
  133. }