PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/code/custom_forms/checkout/SilvercartCheckoutFormStep2.php

https://bitbucket.org/silvercart/silvercart/
PHP | 116 lines | 38 code | 11 blank | 67 comment | 5 complexity | 34fb5bb253696c231f7c7a733bddf7a6 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. * form step for customers invoice/shipping address. Adds a form for LOGGED IN
  25. * or ANONYMOUS customers.
  26. *
  27. * @package Silvercart
  28. * @subpackage Forms Checkout
  29. * @author Roland Lehmann <rlehmann@pixeltricks.de>, Sebastian Diel <sdiel@pixeltricks.de>
  30. * @copyright pixeltricks GmbH
  31. * @since 01.07.2011
  32. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  33. */
  34. class SilvercartCheckoutFormStep2 extends CustomHtmlForm {
  35. /**
  36. * init
  37. *
  38. * @param Controller $controller the controller object
  39. * @param array $params additional parameters
  40. * @param array $preferences array with preferences
  41. * @param bool $barebone is the form initialized completely?
  42. *
  43. * @return void
  44. *
  45. * @author Sascha Koehler <skoehler@pixeltricks.de>
  46. * @copyright 2011 pixeltricks GmbH
  47. * @since 07.01.2011
  48. */
  49. public function __construct($controller, $params = null, $preferences = null, $barebone = false) {
  50. parent::__construct($controller, $params, $preferences, $barebone);
  51. if (!$barebone) {
  52. /*
  53. * redirect a user if his cart is empty and no order exists
  54. */
  55. $checkoutData = $this->controller->getCombinedStepData();
  56. if (!Member::currentUser() ||
  57. (!Member::currentUser()->SilvercartShoppingCart()->isFilled() &&
  58. !array_key_exists('orderId', $checkoutData))) {
  59. $frontPage = SilvercartPage_Controller::PageByIdentifierCode();
  60. Director::redirect($frontPage->RelativeLink());
  61. }
  62. if ($this->isCustomerLoggedIn()) {
  63. $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Regular', new SilvercartCheckoutFormStep2Regular($this->controller));
  64. Session::set("redirect", $this->controller->Link());
  65. $this->registerCustomHtmlForm('SilvercartAddAddressForm', new SilvercartAddAddressForm($this->controller));
  66. } else {
  67. $this->registerCustomHtmlForm('SilvercartCheckoutFormStep2Anonymous', new SilvercartCheckoutFormStep2Anonymous($this->controller));
  68. }
  69. }
  70. }
  71. /**
  72. * Is customer logged in?
  73. *
  74. * @return bool
  75. *
  76. * @author Sebastian Diel <sdiel@pixeltricks.de>
  77. * @copyright 2011 pixeltricks GmbH
  78. * @since 01.07.2011
  79. */
  80. public function isCustomerLoggedIn() {
  81. $isLoggedIn = false;
  82. if (SilvercartCustomer::currentRegisteredCustomer()) {
  83. $isLoggedIn = true;
  84. }
  85. return $isLoggedIn;
  86. }
  87. /**
  88. * Here we set some preferences.
  89. *
  90. * @return void
  91. *
  92. * @author Sascha Koehler <skoehler@pixeltricks.de>
  93. * @copyright 2011 pixeltricks GmbH
  94. * @since 31.03.2011
  95. */
  96. public function preferences() {
  97. $this->preferences['stepIsVisible'] = true;
  98. $this->preferences['stepTitle'] = _t('SilvercartCheckoutFormStep2.TITLE', 'Addresses');
  99. $this->preferences['submitButtonTitle'] = _t('SilvercartCheckoutFormStep.FORWARD', 'Next');
  100. $this->preferences['fillInRequestValues'] = true;
  101. $this->preferences['loadShoppingcartModules'] = false;
  102. $this->preferences['createShoppingcartForms'] = false;
  103. parent::preferences();
  104. }
  105. }