Advertisement
Guest User

Untitled

a guest
Mar 10th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.71 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2012 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-2012 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 $php_self = 'order-confirmation';
  30.  
  31.     public $id_cart;
  32.     public $id_module;
  33.     public $id_order;
  34.     public $reference;
  35.     public $secure_key;
  36.  
  37.     /**
  38.      * Initialize order confirmation controller
  39.      * @see FrontController::init()
  40.      */
  41.     public function init()
  42.     {
  43.         parent::init();
  44.  
  45.         $this->id_cart = (int)(Tools::getValue('id_cart', 0));
  46.         $is_guest = false;
  47.  
  48.         /* check if the cart has been made by a Guest customer, for redirect link */
  49.         if (Cart::isGuestCartByCartId($this->id_cart))
  50.         {
  51.             $is_guest = true;
  52.             $redirectLink = 'index.php?controller=guest-tracking';
  53.         }
  54.         else
  55.             $redirectLink = 'index.php?controller=history';
  56.  
  57.         $this->id_module = (int)(Tools::getValue('id_module', 0));
  58.         $this->id_order = Order::getOrderByCartId((int)($this->id_cart));
  59.         $this->secure_key = Tools::getValue('key', false);
  60.         $order = new Order((int)($this->id_order));
  61.         if ($is_guest)
  62.         {
  63.             $customer = new Customer((int)$order->id_customer);
  64.             $redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
  65.         }
  66.         if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key))
  67.             Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
  68.         $this->reference = $order->reference;
  69.         if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key)
  70.             Tools::redirect($redirectLink);
  71.         $module = Module::getInstanceById((int)($this->id_module));
  72.         if ($order->payment != $module->displayName)
  73.             Tools::redirect($redirectLink);
  74.     }
  75.  
  76.     /**
  77.      * Assign template vars related to page content
  78.      * @see FrontController::initContent()
  79.      */
  80.     public function initContent()
  81.     {
  82.         parent::initContent();
  83.  
  84.         $this->context->smarty->assign(array(
  85.             'is_guest' => $this->context->customer->is_guest,
  86.             'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
  87.             'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()
  88.         ));
  89.  
  90.         if ($this->context->customer->is_guest)
  91.         {
  92.             $this->context->smarty->assign(array(
  93.                 'id_order' => $this->id_order,
  94.                 'reference_order' => $this->reference,
  95.                 'id_order_formatted' => sprintf('#%06d', $this->id_order),
  96.                 'email' => $this->context->customer->email
  97.             ));
  98.             /* If guest we clear the cookie for security reason */
  99.             $this->context->customer->mylogout();
  100.         }
  101.  
  102.         $this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
  103.     }
  104.  
  105.     /**
  106.      * Execute the hook displayPaymentReturn
  107.      */
  108.     public function displayPaymentReturn()
  109.     {
  110.         if (Validate::isUnsignedId($this->id_order) && Validate::isUnsignedId($this->id_module))
  111.         {
  112.             $params = array();
  113.             $order = new Order($this->id_order);
  114.             $currency = new Currency($order->id_currency);
  115.  
  116.             if (Validate::isLoadedObject($order))
  117.             {
  118.                 $params['total_to_pay'] = $order->getOrdersTotalPaid();
  119.                 $params['currency'] = $currency->sign;
  120.                 $params['objOrder'] = $order;
  121.                 $params['currencyObj'] = $currency;
  122.  
  123.                 return Hook::exec('displayPaymentReturn', $params, $this->id_module);
  124.             }
  125.         }
  126.         return false;
  127.     }
  128.  
  129.     /**
  130.      * Execute the hook displayOrderConfirmation
  131.      */
  132.     public function displayOrderConfirmation()
  133.     {
  134.         if (Validate::isUnsignedId($this->id_order))
  135.         {
  136.             $params = array();
  137.             $order = new Order($this->id_order);
  138.             $currency = new Currency($order->id_currency);
  139.  
  140.             if (Validate::isLoadedObject($order))
  141.             {
  142.                 $params['total_to_pay'] = $order->getOrdersTotalPaid();
  143.                 $params['currency'] = $currency->sign;
  144.                 $params['objOrder'] = $order;
  145.                 $params['currencyObj'] = $currency;
  146.  
  147.                 return Hook::exec('displayOrderConfirmation', $params);
  148.             }
  149.         }
  150.         return false;
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement