public function init()
 {
     parent::init();
     global $smarty;
     require_once _PS_MODULE_DIR_ . 'belvg_staticblocks/classes/BelvgStaticBlocks.php';
     smartyRegisterFunction($smarty, 'function', 'getBelvgBlockContent', array('BelvgStaticBlocks', 'getBlockContent'));
 }
 public function init()
 {
     if (parent::$initialized) {
         return;
     }
     $ret = parent::init();
     if (!self::_isActive()) {
         return $ret;
     }
     $assign_array = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     /* // Add the images directory for mobile */
     /* if ($this->context->getMobileDevice() != false) */
     /* 	$assign_array['img_mobile_dir'] = _THEME_MOBILE_IMG_DIR_; */
     /* // Add the CSS directory for mobile */
     /* if ($this->context->getMobileDevice() != false) */
     /* 	$assign_array['css_mobile_dir'] = _THEME_MOBILE_CSS_DIR_; */
     $httHost = Tools::getHttpHost();
     $protocol_content = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? 'https://' : 'http://';
     foreach ($assign_array as $assignKey => $assignValue) {
         if (substr($assignValue, 0, 1) == '/' || $protocol_content == 'https://') {
             $this->context->smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue);
         } else {
             $this->context->smarty->assign($assignKey, $assignValue);
         }
     }
     return $ret;
 }
 public function init()
 {
     if (parent::$initialized) {
         return;
     }
     $ret = parent::init();
     // This override is part of the cloudcache module, so the cloudcache.php file exists
     require_once dirname(__FILE__) . '/../../modules/cloudcache/cloudcache.php';
     // As parent::init() set the parent::$initialized flag, all below will be done only once.
     $module = new CloudCache();
     if (!$module->active || !Configuration::get('CLOUDCACHE_API_ACTIVE')) {
         return $ret;
     }
     // Use global because 1.4 only, 1.5 is in an other file
     global $smarty;
     $assignArray = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_);
     $httHost = Tools::getHttpHost();
     $useSSL = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') && Tools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     foreach ($assignArray as $assignKey => $assignValue) {
         if (substr($assignValue, 0, 1) == '/' || $protocol_content == 'https://') {
             $smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue);
         } else {
             $smarty->assign($assignKey, $assignValue);
         }
     }
     return $ret;
 }
Beispiel #4
0
 public function displayTopNews()
 {
     if (!self::$initialized) {
         parent::init();
     }
     self::$smarty->assign(array('NEWS_HOOK' => Module::hookExec('newshook')));
     returnparent::displayTopNews();
 }
 protected function canonicalRedirection($canonical_url = '')
 {
     $excluded_keys = array('product_rewrite', 'category_rewrite', 'manufacturer_rewrite', 'supplier_rewrite', 'cms_rewrite', 'cms_category_rewrite');
     // hack original behavior on cananocalRedirection: remove *_rewrite from _GET
     $unfiltered_GET = $_GET;
     $_GET = array_diff_key($_GET, array_flip($excluded_keys));
     parent::canonicalRedirection($canonical_url);
     $_GET = $unfiltered_GET;
 }
Beispiel #6
0
 public function init()
 {
     if (Module::isInstalled('magicredirect') && Module::isEnabled('magicredirect')) {
         require_once _PS_MODULE_DIR_ . 'magicredirect/magicredirect.php';
         $mod = new MagicRedirect();
         $mod->catchUrls();
     }
     return parent::init();
 }
 public function init()
 {
     require_once _PS_MODULE_DIR_ . 'belvg_staticblocks/classes/BelvgStaticBlocks.php';
     if (!self::$initialized) {
         global $smarty;
         smartyRegisterFunction($smarty, 'function', 'getBelvgBlockContent', array('BelvgStaticBlocks', 'getBlockContent'));
         smartyRegisterFunction($smarty, 'function', 'getBelvgBlockTitle', array('BelvgStaticBlocks', 'getBlockTitle'));
     }
     parent::init();
 }
 public function display()
 {
     if (!Configuration::get('PS_CSS_THEME_CACHE')) {
         PSM::amendCSS($this->css_files);
     }
     if (!Configuration::get('PS_JS_THEME_CACHE')) {
         PSM::amendJS($this->js_files);
     }
     return parent::display();
 }
 public function setMedia()
 {
     parent::setMedia();
     $this->addCSS(_THEME_CSS_DIR_ . 'font.css', 'all');
     $this->addCSS(_THEME_CSS_DIR_ . 'adaptive.css', 'all');
     $this->addJS(_THEME_JS_DIR_ . 'backForm.js');
     $this->addCSS(_THEME_CSS_DIR_ . 'bootstrap-timepicker.min.css', 'all');
     $this->addJS(_THEME_JS_DIR_ . 'bootstrap-timepicker.min.js');
     $this->addCSS(_THEME_CSS_DIR_ . 'jquery.mCustomScrollbar.css', 'all');
     $this->addJS(_THEME_JS_DIR_ . 'jquery.mCustomScrollbar.concat.min.js');
 }
 /**
  * Redirects to canonical URL.
  *
  * Excludes "*_rewrite" URLs from being treated as non-canonical
  *
  * @param string $canonical_url
  */
 protected function canonicalRedirection($canonical_url = '')
 {
     $_unfiltered_GET = $_GET;
     // hack original behavior on cananocalRedirection: remove *_rewrite from _GET
     $_GET = array_filter($_GET, function ($v) {
         return '_rewrite' === substr($v, -8);
     });
     parent::canonicalRedirection($canonical_url);
     //restore original _GET
     $_GET = $_unfiltered_GET;
 }
 public static function getCurrentCustomerGroups()
 {
     if (!Group::isFeatureActive()) {
         return array();
     }
     $context = Context::getContext();
     if (!isset($context->customer) || !$context->customer->id) {
         return array();
     }
     if (!is_array(self::$currentCustomerGroups)) {
         self::$currentCustomerGroups = array();
         $result = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . (int) $context->customer->id);
         foreach ($result as $row) {
             self::$currentCustomerGroups[] = $row['id_group'];
         }
     }
     return self::$currentCustomerGroups;
 }
Beispiel #12
0
 public function _cacheProducts()
 {
     if (!isset(HomeFeatured::$cache_products)) {
         $category = new Category((int) Configuration::get('HOME_FEATURED_CAT'), (int) Context::getContext()->language->id);
         $nb = (int) Configuration::get('HOME_FEATURED_NBR');
         if (Configuration::get('HOME_FEATURED_RANDOMIZE')) {
             HomeFeatured::$cache_products = $category->getProducts((int) Context::getContext()->language->id, 1, $nb ? $nb : 8, null, null, false, true, true, $nb ? $nb : 8);
         } else {
             HomeFeatured::$cache_products = $category->getProducts((int) Context::getContext()->language->id, 1, $nb ? $nb : 8, 'position');
         }
         $controller = new FrontControllerCore();
         $controller->addColorsToProductList(HomeFeatured::$cache_products);
     }
     if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products)) {
         return false;
     }
 }
Beispiel #13
0
    public function displayFooter()
    {
        global $start_time;
        if (self::$_footer) {
            parent::displayFooter();
        }
        if (!$this->ini_get_display_errors()) {
            return;
        }
        $this->_memory[6] = memory_get_usage();
        $this->_time[6] = microtime(true);
        $hr = '<hr style="color:#F5F5F5;margin:2px" />';
        $totalSize = 0;
        foreach (get_included_files() as $file) {
            $totalSize += filesize($file);
        }
        $totalQueryTime = 0;
        foreach (Db::getInstance()->queriesTime as $time) {
            $totalQueryTime += $time;
        }
        $hooktime = Module::getHookTime();
        arsort($hooktime);
        $totalHookTime = 0;
        foreach ($hooktime as $time) {
            $totalHookTime += $time;
        }
        $globalSize = array();
        $totalGlobalSize = 0;
        foreach ($GLOBALS as $key => $value) {
            if ($key != 'GLOBALS') {
                $totalGlobalSize += $size = $this->sizeofvar($value);
                if ($size > 1024) {
                    $globalSize[$key] = round($size / 1024, 1);
                }
            }
        }
        arsort($globalSize);
        echo '<br /><br />
		<div class="rte" style="text-align:left;padding:8px;float:left">
			<b>Load time</b>: ' . $this->displayLoadTimeColor($this->_time[6] - $start_time, true) . '';
        if (self::$_footer) {
            echo '
			<ul>
				<li>Config: ' . $this->displayLoadTimeColor($this->_time[-3] - $start_time) . '</li>
				<li>Init: ' . $this->displayLoadTimeColor($this->_time[-2] - $this->_time[-3]) . '</li>
				<li>Constructor: ' . $this->displayLoadTimeColor($this->_time[-1] - $this->_time[-2]) . '</li>
				<li>preProcess: ' . $this->displayLoadTimeColor($this->_time[1] - $this->_time[0]) . '</li>
				<li>setMedia: ' . $this->displayLoadTimeColor($this->_time[2] - $this->_time[1]) . '</li>
				<li>displayHeader: ' . $this->displayLoadTimeColor($this->_time[3] - $this->_time[2]) . '</li>
				<li>process: ' . $this->displayLoadTimeColor($this->_time[4] - $this->_time[3]) . '</li>
				<li>displayContent: ' . $this->displayLoadTimeColor($this->_time[5] - $this->_time[4]) . '</li>
				<li>displayFooter: ' . $this->displayLoadTimeColor($this->_time[6] - $this->_time[5]) . '</li>
			</ul>';
        }
        echo '</div>
		<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
			<b>Hook processing</b>: ' . $this->displayLoadTimeColor($totalHookTime) . '
			<ul>';
        foreach ($hooktime as $hook => $time) {
            echo '<li>' . $hook . ': ' . $this->displayLoadTimeColor($time) . '</li>';
        }
        echo '</ul>
		</div>
		<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
			<b>Memory peak usage</b>: ' . $this->displayMemoryColor(memory_get_peak_usage()) . '';
        if (self::$_footer) {
            echo '
			<ul>
				<li>Config: ' . $this->displayMemoryColor($this->_memory[-3]) . '</li>
				<li>Init: ' . $this->displayMemoryColor($this->_memory[-2] - $this->_memory[-3]) . '</li>
				<li>Constructor: ' . $this->displayMemoryColor($this->_memory[-1] - $this->_memory[-2]) . '</li>
				<li>preProcess: ' . $this->displayMemoryColor($this->_memory[1] - $this->_memory[0]) . '</li>
				<li>setMedia: ' . $this->displayMemoryColor($this->_memory[2] - $this->_memory[1]) . '</li>
				<li>displayHeader: ' . $this->displayMemoryColor($this->_memory[3] - $this->_memory[2]) . '</li>
				<li>process: ' . $this->displayMemoryColor($this->_memory[4] - $this->_memory[3]) . '</li>
				<li>displayContent: ' . $this->displayMemoryColor($this->_memory[5] - $this->_memory[4]) . '</li><li>displayFooter: ' . $this->displayMemoryColor($this->_memory[6] - $this->_memory[5]) . '</li>
			</ul>';
        }
        echo '</div>';
        $countByTypes = '';
        foreach (Db::getInstance()->countTypes as $type => $count) {
            if ($count) {
                $countByTypes .= '<li>' . $count . ' x ' . $type . '</li>';
            }
        }
        $countByTypes = rtrim($countByTypes, ' |');
        echo '
		<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
			<b>SQL Queries</b>: ' . $this->displaySQLQueries(Db::getInstance()->count) . '
			<ul>' . $countByTypes . '</ul>
			<br /><b>Time spent querying</b>: ' . $this->displayLoadTimeColor($totalQueryTime) . '
		</div>
		<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
			<b>Included files</b>: ' . sizeof(get_included_files()) . '<br />
			<b>Size of included files</b>: ' . $this->displayMemoryColor($totalSize) . '
		</div>
		<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
			<b>Globals (&gt; 1 Ko only): ' . round($totalGlobalSize / 1024) . ' Ko</b>
			<ul>';
        foreach ($globalSize as $global => $size) {
            echo '<li>' . $global . ' &asymp; ' . $size . ' Ko</li>';
        }
        echo '</ul>
		</div>';
        echo '
		<div class="rte" style="text-align:left;padding:8px;clear:both;margin-top:20px">
			<ul>
				<li><a href="#stopwatch">Go to Stopwatch</a></li>
				<li><a href="#doubles">Go to Doubles</a></li>
				<li><a href="#tables">Go to Tables</a></li>
			</ul>
		</div>
		<div class="rte" style="text-align:left;padding:8px">
		<h3><a name="stopwatch">Stopwatch (with SQL_NO_CACHE)</a></h3>';
        $queries = Db::getInstance()->queriesTime;
        arsort($queries);
        foreach ($queries as $q => $time) {
            echo $hr . '<b ' . $this->getTimeColor($time * 1000) . '>' . round($time * 1000, 3) . ' ms</b> ' . $q;
        }
        echo '</div>
		<div class="rte" style="text-align:left;padding:8px">
		<h3><a name="doubles">Doubles (IDs replaced by "XX")</a></h3>';
        $queries = Db::getInstance()->queries;
        arsort($queries);
        foreach ($queries as $q => $nb) {
            echo $hr . '<b ' . $this->getQueryColor($nb) . '>' . $nb . '</b> ' . $q;
        }
        echo '</div>
		<div class="rte" style="text-align:left;padding:8px">
		<h3><a name="tables">Tables stress</a></h3>';
        $tables = Db::getInstance()->tables;
        arsort($tables);
        foreach ($tables as $table => $nb) {
            echo $hr . '<b ' . $this->getTableColor($nb) . '>' . $nb . '</b> ' . $table;
        }
        echo '</div>';
    }
Beispiel #14
0
 protected function getBestSellers($params)
 {
     if (Configuration::get('PS_CATALOG_MODE')) {
         return false;
     }
     if (!($result = ProductSale::getBestSalesLight((int) $params['cookie']->id_lang, 0, (int) Configuration::get('PS_BLOCK_BESTSELLERS_TO_DISPLAY')))) {
         return Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false;
     }
     $controller = new FrontControllerCore();
     $controller->addColorsToProductList($result);
     $currency = new Currency($params['cookie']->id_currency);
     $usetax = Product::getTaxCalculationMethod((int) $this->context->customer->id) != PS_TAX_EXC;
     foreach ($result as &$row) {
         $row['price'] = Tools::displayPrice(Product::getPriceStatic((int) $row['id_product'], $usetax), $currency);
     }
     return $result;
 }
 public function preProcess()
 {
     global $smarty;
     self::$smarty->assign('HOOK_FACEBOOK_LIKE', Module::hookExec('facebookLike'));
     parent::preProcess();
 }
Beispiel #16
0
 public static function getCurrentCustomerGroups()
 {
     if (!isset(self::$cookie) || !self::$cookie->id_customer) {
         return array();
     }
     if (!is_array(self::$currentCustomerGroups)) {
         self::$currentCustomerGroups = array();
         $result = Db::getInstance()->ExecuteS('SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . (int) self::$cookie->id_customer);
         foreach ($result as $row) {
             self::$currentCustomerGroups[] = $row['id_group'];
         }
     }
     return self::$currentCustomerGroups;
 }
Beispiel #17
0
 public function postProcess()
 {
     parent::postProcess();
     if (Tools::isSubmit('feedbackSubmit')) {
         $iso = Language::getIsoById(intval($this->context->language->id));
         $template = 'feedback';
         $subject = 'Сообщение с формы обратный звонок';
         $templateVars = array('{email}' => Tools::getValue('feedback_email'), '{name}' => Tools::getValue('feedback_name'), '{mess}' => Tools::getValue('feedback_mess'));
         //                echo  $f =_PS_ROOT_DIR_.'/mails/'.$iso.'/'.$template.'.txt';
         //                echo file_exists($f);
         //                die();
         $admin_mails = Configuration::get('PS_SHOP_EMAIL');
         if (file_exists(_PS_ROOT_DIR_ . '/mails/' . $iso . '/' . $template . '.txt') and file_exists(_PS_ROOT_DIR_ . '/mails/' . $iso . '/' . $template . '.html')) {
             if (Mail::Send($this->context->language->id, $template, $subject, $templateVars, $admin_mails)) {
                 die(Tools::jsonEncode(1));
             }
         }
         die(Tools::jsonEncode(0));
     }
 }
 public function init()
 {
     Hook::exec('controllerConstruct');
     parent::init();
 }
Beispiel #19
0
        public function init()
	{
		/*
		 * Globals are DEPRECATED as of version 1.5.
		 * Use the Context to access objects instead.
		 * Example: $this->context->cart
		 */
		global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;

		if (self::$initialized)
			return;
		self::$initialized = true;

		parent::init();

		// If current URL use SSL, set it true (used a lot for module redirect)
		if (Tools::usingSecureMode())
			$useSSL = true;

		// For compatibility with globals, DEPRECATED as of version 1.5
		$css_files = $this->css_files;
		$js_files = $this->js_files;

		// If we call a SSL controller without SSL or a non SSL controller with SSL, we redirect with the right protocol
		if (Configuration::get('PS_SSL_ENABLED') && $_SERVER['REQUEST_METHOD'] != 'POST' && $this->ssl != Tools::usingSecureMode())
		{	
			header('HTTP/1.1 301 Moved Permanently');
			header('Cache-Control: no-cache');
			if ($this->ssl)					
				header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
			else						
				header('Location: '.Tools::getShopDomain(true).$_SERVER['REQUEST_URI']);
			exit();
		}
		
		if ($this->ajax)
		{
			$this->display_header = false;
			$this->display_footer = false;
		}

		// if account created with the 2 steps register process, remove 'accoun_created' from cookie
		if (isset($this->context->cookie->account_created))
		{
			$this->context->smarty->assign('account_created', 1);
			unset($this->context->cookie->account_created);
		}

		ob_start();

		// Init cookie language
		// @TODO This method must be moved into switchLanguage
		Tools::setCookieLanguage($this->context->cookie);

		$protocol_link = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
		$useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
		$protocol_content = ($useSSL) ? 'https://' : 'http://';
		$link = new Link($protocol_link, $protocol_content);
		$this->context->link = $link;

		if ($id_cart = (int)$this->recoverCart())
			$this->context->cookie->id_cart = (int)$id_cart;

		if ($this->auth && !$this->context->customer->isLogged($this->guestAllowed))
			Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));

		/* Theme is missing */
		if (!is_dir(_PS_THEME_DIR_))
			throw new PrestaShopException((sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\')))));

		if (Configuration::get('PS_GEOLOCATION_ENABLED'))
			if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
				$this->context->country = $newDefault;

		$currency = Tools::setCurrency($this->context->cookie);

		if (isset($_GET['logout']) || ($this->context->customer->logged && Customer::isBanned($this->context->customer->id)))
		{
			$this->context->customer->logout();

			Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
		}
		elseif (isset($_GET['mylogout']))
		{
			$this->context->customer->mylogout();
			Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
		}

		/* Cart already exists */
		if ((int)$this->context->cookie->id_cart)
		{
			$cart = new Cart($this->context->cookie->id_cart);
			if ($cart->OrderExists())
			{
				unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
				$this->context->cookie->check_cgv = false;
			}
			/* Delete product of cart, if user can't make an order from his country */
			elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) &&
					!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) &&
					$cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 &&
					!FrontController::isInWhitelistForGeolocation() &&
					!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
				unset($this->context->cookie->id_cart, $cart);
			// update cart values
			elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency)
			{
				if ($this->context->cookie->id_customer)
					$cart->id_customer = (int)($this->context->cookie->id_customer);
				$cart->id_lang = (int)($this->context->cookie->id_lang);
				$cart->id_currency = (int)$currency->id;
				$cart->update();
			}
			/* Select an address if not set */
			if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 ||
				!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer)
			{
				$to_update = false;
				if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0)
				{
					$to_update = true;
					$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
				}
				if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0)
				{
					$to_update = true;
					$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
				}
				if ($to_update)
					$cart->update();
			}
		}

		if (!isset($cart) || !$cart->id)
		{
			$cart = new Cart();
			$cart->id_lang = (int)($this->context->cookie->id_lang);
			$cart->id_currency = (int)($this->context->cookie->id_currency);
			$cart->id_guest = (int)($this->context->cookie->id_guest);
			$cart->id_shop_group = (int)$this->context->shop->id_shop_group;
			$cart->id_shop = $this->context->shop->id;
			if ($this->context->cookie->id_customer)
			{
				$cart->id_customer = (int)($this->context->cookie->id_customer);
				$cart->id_address_delivery = (int)(Address::getFirstCustomerAddressId($cart->id_customer));
				$cart->id_address_invoice = $cart->id_address_delivery;
			}
			else
			{
				$cart->id_address_delivery = 0;
				$cart->id_address_invoice = 0;
			}

			// Needed if the merchant want to give a free product to every visitors
			$this->context->cart = $cart;
			CartRule::autoAddToCart($this->context);
		}
		else
			$this->context->cart = $cart;	

		/* get page name to display it in body id */

		// Are we in a payment module
		$module_name = '';
		if (Validate::isModuleName(Tools::getValue('module')))
			$module_name = Tools::getValue('module');

		if (!empty($this->page_name))
			$page_name = $this->page_name;
		elseif (!empty($this->php_self))
			$page_name = $this->php_self;
		elseif (Tools::getValue('fc') == 'module' && $module_name != '' && (Module::getInstanceByName($module_name) instanceof PaymentModule))
			$page_name = 'module-payment-submit';
		// @retrocompatibility Are we in a module ?
		elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m))
			$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
		else
		{
			$page_name = Dispatcher::getInstance()->getController();
			$page_name = (preg_match('/^[0-9]/', $page_name) ? 'page_'.$page_name : $page_name);
		}

		$this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
		$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));

		/* Breadcrumb */
		$navigationPipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
		$this->context->smarty->assign('navigationPipe', $navigationPipe);

		// Automatically redirect to the canonical URL if needed
		if (!empty($this->php_self) && !Tools::getValue('ajax'))
			$this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));

		Product::initPricesComputation();

		$display_tax_label = $this->context->country->display_tax_label;
		if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
		{
			$infos = Address::getCountryAndState((int)($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
			$country = new Country((int)$infos['id_country']);
			$this->context->country = $country;
			if (Validate::isLoadedObject($country))
				$display_tax_label = $country->display_tax_label;
		}

		$languages = Language::getLanguages(true, $this->context->shop->id);
		$meta_language = array();
		foreach ($languages as $lang)
			$meta_language[] = $lang['iso_code'];

		$compared_products = array();
		if (Configuration::get('PS_COMPARATOR_MAX_ITEM') && isset($this->context->cookie->id_compare))
			$compared_products = CompareProduct::getCompareProducts($this->context->cookie->id_compare);

                $cat_main = new Category(2);
                $tree = $cat_main->recurseLiteCategTree(1);
                $start_cats = array();
                
                foreach ($tree['children'] as $k => $child){
                    $start_cats[$child['id']]['name'] = $child['name'];
                    $start_cats[$child['id']]['id'] = $child['id'];
                }
                $best_presetage = 0;
                if(isset($this->context->customer->id_default_group) && isset($this->context->customer->id) && !empty($this->context->customer->id_default_group)){
                    $customer_groups = Db::getInstance()->executeS("SELECT id_group FROM ps_customer_group WHERE id_customer={$this->context->customer->id}"); 
                    $date_now = new DateTime(date('Y-m-d H:i:s'));
                    if(is_array($customer_groups) && count($customer_groups) > 0)
                        foreach ($customer_groups as $row_group){
                            $id_default_group = $row_group['id_group'];
                            $sql = "SELECT * FROM ps_specific_price_rule WHERE (id_shop={$this->context->shop->id} OR id_shop=0)
                            AND (id_group={$id_default_group} OR id_group=0)
                            AND (id_currency={$this->context->cookie->id_currency} OR id_currency=0)
                            AND (id_country={$this->context->country->id} OR id_country=0)
                            AND reduction_type = 'percentage'
                            ORDER BY reduction DESC";
                            $result = Db::getInstance()->executeS($sql);
                            foreach ($result as $row){
                                if(!empty($row['from'])){
                                    $date_from = new DateTime(date($row['from']));
                                    if($date_from->format('U') > $date_now->format('U'))
                                        continue;
                                }
                                if(!empty($row['to'])){
                                    $date_to = new DateTime(date($row['to']));
                                    if($date_to->format('U') < $date_now->format('U'))
                                        continue;
                                }
                                if($row['reduction'] > $best_presetage)
                                    $best_presetage = $row['reduction'];
                            }
                        }
                        
                    if($best_presetage > 0)
                        $best_presetage = round($best_presetage);
                }
                
                if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
                    if(isset($_GET['translit']) && $_GET['translit'] == 'on'){
                        $this->context->cookie->shut_off_transit = 0;
                    }
                    if(isset($_GET['translit']) && $_GET['translit'] == 'off'){
                        $this->context->cookie->shut_off_transit = 1;
                    }
                    die(Tools::jsonEncode(1));
                }
                
                $mod_translit = false;
                if($this->context->language->id != 1)
                    if(!isset($this->context->cookie->shut_off_transit) || $this->context->cookie->shut_off_transit == 0){
                        $mod_translit = 'yes';
                    }
                    else{
                        $mod_translit = 'no';
                    }
        
                    
                   
                    
		$this->context->smarty->assign(array(
			// Usefull for layout.tpl
                        'mod_translit' =>   $mod_translit,
                        'best_presetage' => $best_presetage > 0 ? $best_presetage : null,
                        'start_cats' => $start_cats,
			'mobile_device' => $this->context->getMobileDevice(),
			'link' => $link,
			'cart' => $cart,
			'currency' => $currency,
			'cookie' => $this->context->cookie,
			'page_name' => $page_name,
			'hide_left_column' => !$this->display_column_left,
			'hide_right_column' => !$this->display_column_right,
			'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
			'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,
			'content_dir' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__,
			'base_uri' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''),
			'tpl_dir' => _PS_THEME_DIR_,
			'modules_dir' => _MODULE_DIR_,
			'mail_dir' => _MAIL_DIR_,
			'lang_iso' => $this->context->language->iso_code,
			'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))),
			'cart_qties' => (int)$cart->nbProducts(),
			'currencies' => Currency::getCurrencies(),
			'languages' => $languages,
			'meta_language' => implode(',', $meta_language),
			'priceDisplay' => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer),
			'is_logged' => (bool)$this->context->customer->isLogged(),
			'is_guest' => (bool)$this->context->customer->isGuest(),
			'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
			'shop_name' => Configuration::get('PS_SHOP_NAME'),
			'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
			'use_taxes' => (int)Configuration::get('PS_TAX'),
			'show_taxes' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),
			'display_tax_label' => (bool)$display_tax_label,
			'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
			'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
			'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || !(bool)Group::getCurrent()->show_prices,
			'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE'),
			'request' => $link->getPaginationLink(false, false, false, true),
			'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'),
			'quick_view' => (bool)Configuration::get('PS_QUICK_VIEW'),
			'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
			'compared_products' => is_array($compared_products) ? $compared_products : array(),
			'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM')
		));

		// Add the tpl files directory for mobile
		if ($this->useMobileTheme())
			$this->context->smarty->assign(array(
				'tpl_mobile_uri' => _PS_THEME_MOBILE_DIR_,
			));

		// Deprecated
		$this->context->smarty->assign(array(
			'id_currency_cookie' => (int)$currency->id,
			'logged' => $this->context->customer->isLogged(),
			'customerName' => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
		));

		$assign_array = array(
			'img_ps_dir' => _PS_IMG_,
			'img_cat_dir' => _THEME_CAT_DIR_,
			'img_lang_dir' => _THEME_LANG_DIR_,
			'img_prod_dir' => _THEME_PROD_DIR_,
			'img_manu_dir' => _THEME_MANU_DIR_,
			'img_sup_dir' => _THEME_SUP_DIR_,
			'img_ship_dir' => _THEME_SHIP_DIR_,
			'img_store_dir' => _THEME_STORE_DIR_,
			'img_col_dir' => _THEME_COL_DIR_,
			'img_dir' => _THEME_IMG_DIR_,
			'css_dir' => _THEME_CSS_DIR_,
			'js_dir' => _THEME_JS_DIR_,
			'pic_dir' => _THEME_PROD_PIC_DIR_
		);

		// Add the images directory for mobile
		if ($this->useMobileTheme())
			$assign_array['img_mobile_dir'] = _THEME_MOBILE_IMG_DIR_;

		// Add the CSS directory for mobile
		if ($this->useMobileTheme())
			$assign_array['css_mobile_dir'] = _THEME_MOBILE_CSS_DIR_;

		foreach ($assign_array as $assign_key => $assign_value)
			if (substr($assign_value, 0, 1) == '/' || $protocol_content == 'https://')
				$this->context->smarty->assign($assign_key, $protocol_content.Tools::getMediaServer($assign_value).$assign_value);
			else
				$this->context->smarty->assign($assign_key, $assign_value);

		/*
		 * These shortcuts are DEPRECATED as of version 1.5.
		 * Use the Context to access objects instead.
		 * Example: $this->context->cart
		 */
		self::$cookie = $this->context->cookie;
		self::$cart = $cart;
		self::$smarty = $this->context->smarty;
		self::$link = $link;
		$defaultCountry = $this->context->country;

		$this->displayMaintenancePage();
		if ($this->restrictedCountry)
			$this->displayRestrictedCountryPage();

		if (Tools::isSubmit('live_edit') && !$this->checkLiveEditAccess())
			Tools::redirect('index.php?controller=404');

		$this->iso = $iso;

		$this->context->cart = $cart;
		$this->context->currency = $currency;
                
                $orderTotal = $this->context->cart->getOrderTotal();
		$this->context->smarty->assign('global_order_total', $orderTotal);
	}
 public function setTemplate($default_template)
 {
     require_once dirname(__FILE__) . '../../../../modules/designerpreview/defines.inc.php';
     $preview_template = str_replace(_PS_THEME_DIR_, getThemeDir(), $default_template);
     parent::setTemplate($preview_template);
 }
Beispiel #21
0
 public function preProcess()
 {
     global $cookie, $smarty;
     $smarty->assign('HOOK_CART_SHIPPING_PREVIEW', Module::hookExec('cartShippingPreview'));
     parent::preProcess();
 }
Beispiel #22
-1
 public function initHeader()
 {
     parent::initHeader();
     if (Module::isInstalled('agilemultipleshop')) {
         include_once _PS_ROOT_DIR_ . "/modules/agilemultipleshop/agilemultipleshop.php";
         AgileMultipleShop::init_shop_header();
         AgileMultipleShop::clear_blockcategory_cache();
     }
 }