Advertisement
Guest User

Untitled

a guest
Oct 11th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2014 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-2014 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.  
  27. class OrderConfirmationControllerCore extends FrontController
  28. {
  29. public $ssl = true;
  30. public $php_self = 'order-confirmation';
  31.  
  32. public $id_cart;
  33. public $id_module;
  34. public $id_order;
  35. public $reference;
  36. public $secure_key;
  37.  
  38. /**
  39. * Initialize order confirmation controller
  40. * @see FrontController::init()
  41. */
  42. public function init()
  43. {
  44. parent::init();
  45.  
  46. $this->id_cart = (int)(Tools::getValue('id_cart', 0));
  47. $is_guest = false;
  48.  
  49. /* check if the cart has been made by a Guest customer, for redirect link */
  50. if (Cart::isGuestCartByCartId($this->id_cart))
  51. {
  52. $is_guest = true;
  53. $redirectLink = 'index.php?controller=guest-tracking';
  54. }
  55. else
  56. $redirectLink = 'index.php?controller=history';
  57.  
  58. $this->id_module = (int)(Tools::getValue('id_module', 0));
  59. $this->id_order = Order::getOrderByCartId((int)($this->id_cart));
  60. $this->secure_key = Tools::getValue('key', false);
  61. $order = new Order((int)($this->id_order));
  62. if ($is_guest)
  63. {
  64. $customer = new Customer((int)$order->id_customer);
  65. $redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
  66. }
  67. if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key))
  68. Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
  69. $this->reference = $order->reference;
  70. if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key)
  71. Tools::redirect($redirectLink);
  72. $module = Module::getInstanceById((int)($this->id_module));
  73. if ($order->payment != $module->displayName)
  74. Tools::redirect($redirectLink);
  75. }
  76.  
  77. /**
  78. * Assign template vars related to page content
  79. * @see FrontController::initContent()
  80. */
  81. public function initContent()
  82. {
  83. parent::initContent();
  84.  
  85. $this->context->smarty->assign(array(
  86. 'is_guest' => $this->context->customer->is_guest,
  87. 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
  88. 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn(),
  89. 'HOOK_LOKALINC_CONVERSION_CODE' => $this->getLokalincConversionCode()
  90. ));
  91.  
  92. if ($this->context->customer->is_guest)
  93. {
  94. $this->context->smarty->assign(array(
  95. 'id_order' => $this->id_order,
  96. 'reference_order' => $this->reference,
  97. 'id_order_formatted' => sprintf('#%06d', $this->id_order),
  98. 'email' => $this->context->customer->email
  99. ));
  100. /* If guest we clear the cookie for security reason */
  101. $this->context->customer->mylogout();
  102. }
  103.  
  104. $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
  105. }
  106.  
  107. public function getLokalincConversionCode()
  108. {
  109. $lokalincShopId = 138;
  110.  
  111. $lokalincConversionCode = <<<EOT
  112. <!-- Lokalinc Code for Tracking Conversions -->
  113. <script type="text/javascript">
  114. /* <![CDATA[ */
  115. var lokalinc_shop_id = $lokalincShopId;
  116. var lokalinc_order = [
  117.  
  118. EOT;
  119.  
  120. $order = new Order((int)($this->id_order));
  121. $orderProducts = $order->getProducts();
  122.  
  123. $jsObjLiteral = '';
  124. $queryString = '';
  125. $productNum = 1;
  126. foreach ($orderProducts as $product)
  127. {
  128. if ($productNum > 1)
  129. {
  130. $jsObjLiteral .= ",\n";
  131. $queryString .= '&amp;';
  132. }
  133.  
  134. $productName = $product['product_name'];
  135. $productPrice = $product['total_price_tax_incl'];
  136. $productQuantity = $product['product_quantity'];
  137.  
  138. $jsObjLiteral .= '{ ';
  139. $jsObjLiteral .= "'p" . $productNum . "_name': '" . addslashes($productName) . "', " .
  140. "'p" . $productNum . "_price': '" . $productPrice . "', " .
  141. "'p" . $productNum . "_quantity': '" . $productQuantity . "'";
  142. $jsObjLiteral .= ' }';
  143.  
  144. $queryString .= 'p' . $productNum . '_name=' . urlencode($productName) . '&amp;' .
  145. 'p' . $productNum . '_price=' . $productPrice . '&amp;' .
  146. 'p' . $productNum . '_quantity=' . $productQuantity;
  147.  
  148. $productNum++;
  149. }
  150. $jsObjLiteral .= "\n";
  151.  
  152. $lokalincConversionCode .= <<<EOT
  153. $jsObjLiteral
  154. ];
  155. /* ]]> */
  156. </script>
  157. <script type="text/javascript" src="//www.lokalinc.nl/resources/javascript/conversion.js"></script>
  158. <noscript>
  159. EOT;
  160.  
  161. $lokalincConversionCode .= <<<EOT
  162. <img height="1" width="1" border="0" src="//www.lokalinc.nl/affiliate/conversion/?lokalinc_shop_id=$lokalincShopId&amp;$queryString&amp;script=1">
  163. </noscript>
  164. EOT;
  165.  
  166. if (0 && $_SERVER['REMOTE_ADDR'] == '1.2.3.4') /* Original IP obscured. */
  167. {
  168. echo $lokalincConversionCode;
  169. exit;
  170. }
  171.  
  172. return $lokalincConversionCode;
  173. }
  174.  
  175. /**
  176. * Execute the hook displayPaymentReturn
  177. */
  178. public function displayPaymentReturn()
  179. {
  180. if (Validate::isUnsignedId($this->id_order) && Validate::isUnsignedId($this->id_module))
  181. {
  182. $params = array();
  183. $order = new Order($this->id_order);
  184. $currency = new Currency($order->id_currency);
  185.  
  186. if (Validate::isLoadedObject($order))
  187. {
  188. $params['total_to_pay'] = $order->getOrdersTotalPaid();
  189. $params['currency'] = $currency->sign;
  190. $params['objOrder'] = $order;
  191. $params['currencyObj'] = $currency;
  192.  
  193. return Hook::exec('displayPaymentReturn', $params, $this->id_module);
  194. }
  195. }
  196. return false;
  197. }
  198.  
  199. /**
  200. * Execute the hook displayOrderConfirmation
  201. */
  202. public function displayOrderConfirmation()
  203. {
  204. if (Validate::isUnsignedId($this->id_order))
  205. {
  206. $params = array();
  207. $order = new Order($this->id_order);
  208. $currency = new Currency($order->id_currency);
  209.  
  210. if (Validate::isLoadedObject($order))
  211. {
  212. $params['total_to_pay'] = $order->getOrdersTotalPaid();
  213. $params['currency'] = $currency->sign;
  214. $params['objOrder'] = $order;
  215. $params['currencyObj'] = $currency;
  216.  
  217. return Hook::exec('displayOrderConfirmation', $params);
  218. }
  219. }
  220. return false;
  221. }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement