<?php
/**
 *---------------------------------------------------------------------------------------
 * @package      VP Conversion Tracking - Joomla! System Plugin
 * @subpackage   For VirtueMart 3+
 *---------------------------------------------------------------------------------------
 * @copyright    Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license      GNU General Public License version 2 or later; see LICENSE.txt
 * @authors      Abhishek Das
 * @email        info@virtueplanet.com
 * @link         https://www.virtueplanet.com
 *---------------------------------------------------------------------------------------
*/
defined('_JEXEC') or die;

// Load the controller framework
jimport('joomla.application.component.controller');

/**
 * Controller for the thankyou view
 */
class VirtueMartControllerThankyou extends JControllerLegacy
{
	protected $helper;
	
	public function __construct()
	{
		// Register view
		JLoader::register('VirtueMartViewThankyou', VPCT_PATH . '/views/thankyou/view.html.php');
		
		// Get an instance of helper
		$this->helper = plgSystemVPConversionTrackingHelper::getInstance();
		
		// Load required languages
		$this->helper->loadLanguages(true);
		
		parent::__construct();
	}
	
	public function display($cachable = false, $urlparams = false)
	{
		$order = $this->helper->getOrder();
		
		if(empty($order))
		{
			$app = JFactory::getApplication();
			$app->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart', false));
			return false;
		}
		
		parent::display($cachable, $urlparams);
	}
}