Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * 2007-2014 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2014 PrestaShop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- class OrderConfirmationControllerCore extends FrontController
- {
- public $ssl = true;
- public $php_self = 'order-confirmation';
- public $id_cart;
- public $id_module;
- public $id_order;
- public $reference;
- public $secure_key;
- /**
- * Initialize order confirmation controller
- * @see FrontController::init()
- */
- public function init()
- {
- parent::init();
- $this->id_cart = (int)(Tools::getValue('id_cart', 0));
- $is_guest = false;
- /* check if the cart has been made by a Guest customer, for redirect link */
- if (Cart::isGuestCartByCartId($this->id_cart))
- {
- $is_guest = true;
- $redirectLink = 'index.php?controller=guest-tracking';
- }
- else
- $redirectLink = 'index.php?controller=history';
- $this->id_module = (int)(Tools::getValue('id_module', 0));
- $this->id_order = Order::getOrderByCartId((int)($this->id_cart));
- $this->secure_key = Tools::getValue('key', false);
- $order = new Order((int)($this->id_order));
- if ($is_guest)
- {
- $customer = new Customer((int)$order->id_customer);
- $redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
- }
- if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key))
- Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
- $this->reference = $order->reference;
- if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key)
- Tools::redirect($redirectLink);
- $module = Module::getInstanceById((int)($this->id_module));
- if ($order->payment != $module->displayName)
- Tools::redirect($redirectLink);
- }
- /**
- * Assign template vars related to page content
- * @see FrontController::initContent()
- */
- public function initContent()
- {
- parent::initContent();
- $this->context->smarty->assign(array(
- 'is_guest' => $this->context->customer->is_guest,
- 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
- 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn(),
- 'HOOK_LOKALINC_CONVERSION_CODE' => $this->getLokalincConversionCode()
- ));
- if ($this->context->customer->is_guest)
- {
- $this->context->smarty->assign(array(
- 'id_order' => $this->id_order,
- 'reference_order' => $this->reference,
- 'id_order_formatted' => sprintf('#%06d', $this->id_order),
- 'email' => $this->context->customer->email
- ));
- /* If guest we clear the cookie for security reason */
- $this->context->customer->mylogout();
- }
- $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
- }
- public function getLokalincConversionCode()
- {
- $lokalincShopId = 138;
- $lokalincConversionCode = <<<EOT
- <!-- Lokalinc Code for Tracking Conversions -->
- <script type="text/javascript">
- /* <![CDATA[ */
- var lokalinc_shop_id = $lokalincShopId;
- var lokalinc_order = [
- EOT;
- $order = new Order((int)($this->id_order));
- $orderProducts = $order->getProducts();
- $jsObjLiteral = '';
- $queryString = '';
- $productNum = 1;
- foreach ($orderProducts as $product)
- {
- if ($productNum > 1)
- {
- $jsObjLiteral .= ",\n";
- $queryString .= '&';
- }
- $productName = $product['product_name'];
- $productPrice = $product['total_price_tax_incl'];
- $productQuantity = $product['product_quantity'];
- $jsObjLiteral .= '{ ';
- $jsObjLiteral .= "'p" . $productNum . "_name': '" . addslashes($productName) . "', " .
- "'p" . $productNum . "_price': '" . $productPrice . "', " .
- "'p" . $productNum . "_quantity': '" . $productQuantity . "'";
- $jsObjLiteral .= ' }';
- $queryString .= 'p' . $productNum . '_name=' . urlencode($productName) . '&' .
- 'p' . $productNum . '_price=' . $productPrice . '&' .
- 'p' . $productNum . '_quantity=' . $productQuantity;
- $productNum++;
- }
- $jsObjLiteral .= "\n";
- $lokalincConversionCode .= <<<EOT
- $jsObjLiteral
- ];
- /* ]]> */
- </script>
- <script type="text/javascript" src="//www.lokalinc.nl/resources/javascript/conversion.js"></script>
- <noscript>
- EOT;
- $lokalincConversionCode .= <<<EOT
- <img height="1" width="1" border="0" src="//www.lokalinc.nl/affiliate/conversion/?lokalinc_shop_id=$lokalincShopId&$queryString&script=1">
- </noscript>
- EOT;
- if (0 && $_SERVER['REMOTE_ADDR'] == '1.2.3.4') /* Original IP obscured. */
- {
- echo $lokalincConversionCode;
- exit;
- }
- return $lokalincConversionCode;
- }
- /**
- * Execute the hook displayPaymentReturn
- */
- public function displayPaymentReturn()
- {
- if (Validate::isUnsignedId($this->id_order) && Validate::isUnsignedId($this->id_module))
- {
- $params = array();
- $order = new Order($this->id_order);
- $currency = new Currency($order->id_currency);
- if (Validate::isLoadedObject($order))
- {
- $params['total_to_pay'] = $order->getOrdersTotalPaid();
- $params['currency'] = $currency->sign;
- $params['objOrder'] = $order;
- $params['currencyObj'] = $currency;
- return Hook::exec('displayPaymentReturn', $params, $this->id_module);
- }
- }
- return false;
- }
- /**
- * Execute the hook displayOrderConfirmation
- */
- public function displayOrderConfirmation()
- {
- if (Validate::isUnsignedId($this->id_order))
- {
- $params = array();
- $order = new Order($this->id_order);
- $currency = new Currency($order->id_currency);
- if (Validate::isLoadedObject($order))
- {
- $params['total_to_pay'] = $order->getOrdersTotalPaid();
- $params['currency'] = $currency->sign;
- $params['objOrder'] = $order;
- $params['currencyObj'] = $currency;
- return Hook::exec('displayOrderConfirmation', $params);
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement