/controllers/front/OrderConfirmationController.php

https://gitlab.com/staging06/myproject · PHP · 148 lines · 93 code · 15 blank · 40 comment · 20 complexity · b2a97281a7e15fe3e19b2d69c4851425 MD5 · raw file

  1. <?php
  2. /*
  3. * 2007-2015 PrestaShop
  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@prestashop.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 PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2015 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. class OrderConfirmationControllerCore extends FrontController
  27. {
  28. public $ssl = true;
  29. public $php_self = 'order-confirmation';
  30. public $id_cart;
  31. public $id_module;
  32. public $id_order;
  33. public $reference;
  34. public $secure_key;
  35. /**
  36. * Initialize order confirmation controller
  37. * @see FrontController::init()
  38. */
  39. public function init()
  40. {
  41. parent::init();
  42. $this->id_cart = (int)(Tools::getValue('id_cart', 0));
  43. $is_guest = false;
  44. /* check if the cart has been made by a Guest customer, for redirect link */
  45. if (Cart::isGuestCartByCartId($this->id_cart)) {
  46. $is_guest = true;
  47. $redirectLink = 'index.php?controller=guest-tracking';
  48. } else {
  49. $redirectLink = 'index.php?controller=history';
  50. }
  51. $this->id_module = (int)(Tools::getValue('id_module', 0));
  52. $this->id_order = Order::getOrderByCartId((int)($this->id_cart));
  53. $this->secure_key = Tools::getValue('key', false);
  54. $order = new Order((int)($this->id_order));
  55. if ($is_guest) {
  56. $customer = new Customer((int)$order->id_customer);
  57. $redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
  58. }
  59. if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
  60. Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
  61. }
  62. $this->reference = $order->reference;
  63. if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
  64. Tools::redirect($redirectLink);
  65. }
  66. $module = Module::getInstanceById((int)($this->id_module));
  67. if ($order->module != $module->name) {
  68. Tools::redirect($redirectLink);
  69. }
  70. }
  71. /**
  72. * Assign template vars related to page content
  73. * @see FrontController::initContent()
  74. */
  75. public function initContent()
  76. {
  77. parent::initContent();
  78. $this->context->smarty->assign(array(
  79. 'is_guest' => $this->context->customer->is_guest,
  80. 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
  81. 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()
  82. ));
  83. if ($this->context->customer->is_guest) {
  84. $this->context->smarty->assign(array(
  85. 'id_order' => $this->id_order,
  86. 'reference_order' => $this->reference,
  87. 'id_order_formatted' => sprintf('#%06d', $this->id_order),
  88. 'email' => $this->context->customer->email
  89. ));
  90. /* If guest we clear the cookie for security reason */
  91. $this->context->customer->mylogout();
  92. }
  93. $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
  94. }
  95. /**
  96. * Execute the hook displayPaymentReturn
  97. */
  98. public function displayPaymentReturn()
  99. {
  100. if (Validate::isUnsignedId($this->id_order) && Validate::isUnsignedId($this->id_module)) {
  101. $params = array();
  102. $order = new Order($this->id_order);
  103. $currency = new Currency($order->id_currency);
  104. if (Validate::isLoadedObject($order)) {
  105. $params['total_to_pay'] = $order->getOrdersTotalPaid();
  106. $params['currency'] = $currency->sign;
  107. $params['objOrder'] = $order;
  108. $params['currencyObj'] = $currency;
  109. return Hook::exec('displayPaymentReturn', $params, $this->id_module);
  110. }
  111. }
  112. return false;
  113. }
  114. /**
  115. * Execute the hook displayOrderConfirmation
  116. */
  117. public function displayOrderConfirmation()
  118. {
  119. if (Validate::isUnsignedId($this->id_order)) {
  120. $params = array();
  121. $order = new Order($this->id_order);
  122. $currency = new Currency($order->id_currency);
  123. if (Validate::isLoadedObject($order)) {
  124. $params['total_to_pay'] = $order->getOrdersTotalPaid();
  125. $params['currency'] = $currency->sign;
  126. $params['objOrder'] = $order;
  127. $params['currencyObj'] = $currency;
  128. return Hook::exec('displayOrderConfirmation', $params);
  129. }
  130. }
  131. return false;
  132. }
  133. }