PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/code/custom_forms/checkout/SilvercartCheckoutFormStepPaymentInit.php

https://bitbucket.org/silvercart/silvercart/
PHP | 148 lines | 52 code | 13 blank | 83 comment | 7 complexity | 33ad31fae8e465c419151e8e55e4b793 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2010, 2011 pixeltricks GmbH
  4. *
  5. * This file is part of SilverCart.
  6. *
  7. * SilverCart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SilverCart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with SilverCart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @package Silvercart
  21. * @subpackage Forms Checkout
  22. */
  23. /**
  24. * CheckoutProcessPaymentBeforeOrder
  25. *
  26. * Ruft die Methode "processPaymentBeforeOrder" im gewaehlten Zahlungsmodul
  27. * auf.
  28. *
  29. * @package Silvercart
  30. * @subpackage Forms Checkout
  31. * @author Roland Lehmann <rlehmann@pixeltricks.de>
  32. * @copyright Pixeltricks GmbH
  33. * @since 03.01.2011
  34. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  35. */
  36. class SilvercartCheckoutFormStepPaymentInit extends CustomHtmlForm {
  37. protected $paymentMethodObj = null;
  38. /**
  39. * constructor
  40. *
  41. * @param Controller $controller the controller object
  42. * @param array $params additional parameters
  43. * @param array $preferences array with preferences
  44. * @param bool $barebone is the form initialized completely?
  45. *
  46. * @return void
  47. *
  48. * @author Sascha Koehler <skoehler@pixeltricks.de>
  49. * @copyright 2011 pixeltricks GmbH
  50. * @since 07.01.2011
  51. */
  52. public function __construct($controller, $params = null, $preferences = null, $barebone = false) {
  53. $member = Member::currentUser();
  54. $checkoutData = $controller->getCombinedStepData();
  55. if ($member) {
  56. if (array_key_exists('PaymentMethod', $checkoutData)) {
  57. $this->paymentMethodObj = DataObject::get_by_id(
  58. 'SilvercartPaymentMethod',
  59. $checkoutData['PaymentMethod']
  60. );
  61. if ($this->paymentMethodObj) {
  62. $this->paymentMethodObj->setController($controller);
  63. $this->paymentMethodObj->setCancelLink(Director::absoluteURL($controller->Link()) . 'GotoStep/2');
  64. $this->paymentMethodObj->setReturnLink(Director::absoluteURL($controller->Link()));
  65. $this->paymentMethodObj->setCustomerDetailsByCheckoutData($checkoutData);
  66. $this->paymentMethodObj->setInvoiceAddressByCheckoutData($checkoutData);
  67. $this->paymentMethodObj->setShippingAddressByCheckoutData($checkoutData);
  68. $this->paymentMethodObj->setShoppingCart($member->SilvercartShoppingCart());
  69. }
  70. }
  71. }
  72. parent::__construct($controller, $params, $preferences, $barebone);
  73. if (!$barebone) {
  74. /*
  75. * redirect a user if his cart is empty and no order exists
  76. */
  77. $checkoutData = $this->controller->getCombinedStepData();
  78. if (!Member::currentUser() ||
  79. (!Member::currentUser()->SilvercartShoppingCart()->isFilled() &&
  80. !array_key_exists('orderId', $checkoutData))) {
  81. $frontPage = SilvercartPage_Controller::PageByIdentifierCode();
  82. Director::redirect($frontPage->RelativeLink());
  83. }
  84. }
  85. }
  86. /**
  87. * Here we set some preferences.
  88. *
  89. * @return void
  90. *
  91. * @author Sascha Koehler <skoehler@pixeltricks.de>
  92. * @copyright 2011 pixeltricks GmbH
  93. * @since 31.03.2011
  94. */
  95. public function preferences() {
  96. $this->preferences['stepIsVisible'] = false;
  97. parent::preferences();
  98. }
  99. /**
  100. * processor method
  101. *
  102. * @return void
  103. *
  104. * @author Sascha Koehler <skoehler@pixeltricks.de>
  105. * @copyright 2010 pixeltricks GmbH
  106. * @since 16.11.2010
  107. */
  108. public function process() {
  109. if ($this->paymentMethodObj) {
  110. return true;
  111. } else {
  112. return false;
  113. }
  114. }
  115. /**
  116. * Render the error template.
  117. *
  118. * @return string
  119. *
  120. * @author Sascha Koehler <skoehler@pixeltricks.de>
  121. * @copyright 2011 pixeltricks GmbH
  122. * @since 04.04.2011
  123. */
  124. public function renderError() {
  125. return $this->renderWith('SilvercartCheckoutFormStepPaymentError');
  126. }
  127. /**
  128. * Returns the PaymentMethod to use in template
  129. *
  130. * @return SilvercartPaymentMethod
  131. */
  132. public function getPaymentMethod() {
  133. return $this->paymentMethodObj;
  134. }
  135. }