Example #1
0
 /**
  * Recursive scan of subcategories
  *
  * @param integer $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth)
  * @param integer $current_depth specify the current depth in the tree (don't use it, only for rucursivity!)
  * @param integer $id_lang Specify the id of the language used
  * @param array $excluded_ids_array specify a list of ids to exclude of results
  *
  * @return array Subcategories lite tree
  */
 public function recurseLiteCategTree($max_depth = 3, $current_depth = 0, $id_lang = null, $excluded_ids_array = null)
 {
     $id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int) $id_lang;
     if (!(int) $id_lang) {
         $id_lang = _USER_ID_LANG_;
     }
     $children = array();
     $subcats = $this->getSubCategories($id_lang, true);
     if (($max_depth == 0 || $current_depth < $max_depth) && $subcats && count($subcats)) {
         foreach ($subcats as &$subcat) {
             if (!$subcat['id_category']) {
                 break;
             } else {
                 if (!is_array($excluded_ids_array) || !in_array($subcat['id_category'], $excluded_ids_array)) {
                     $categ = new Category($subcat['id_category'], $id_lang);
                     $children[] = $categ->recurseLiteCategTree($max_depth, $current_depth + 1, $id_lang, $excluded_ids_array);
                 }
             }
         }
     }
     if (is_array($this->description)) {
         foreach ($this->description as $lang => $description) {
             $this->description[$lang] = Category::getDescriptionClean($description);
         }
     } else {
         $this->description = Category::getDescriptionClean($this->description);
     }
     return array('id' => (int) $this->id, 'link' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children);
 }
Example #2
0
 /**
  * @return boolean if the supplier get the categorie or child in n+3
  **/
 public static function getCategoryByIdAndSupplier($id_supplier, $id_category, $category_root = 2, $id_lang = false)
 {
     $my_category = new Category($id_category, $id_lang);
     $sub_categories = $my_category->recurseLiteCategTree(3, 0, $id_lang, null)['children'];
     //$sub_categories = /*Category::getChildren($id_category, $id_lang, true, false);*/ $my_category->getSubCategories($id_lang,true);
     $sql = '
         SELECT c.id_category, cl.name, c.id_parent
         FROM `' . _DB_PREFIX_ . 'category` c
         ' . Shop::addSqlAssociation('category', 'c') . '
                     INNER JOIN ' . _DB_PREFIX_ . 'product p ON p.id_category_default = c.id_category
         LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category`' . Shop::addSqlRestrictionOnLang('cl') . '
         WHERE p.id_supplier=' . $id_supplier . ($id_lang ? 'AND `id_lang` = ' . (int) $id_lang : '') . ' ' . (!$id_lang ? 'GROUP BY c.id_category' : '') . '
         ORDER BY c.`level_depth` ASC, category_shop.`position` ASC';
     $resultWithShipper = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
     $supplierTmp = array();
     $boolPresent = false;
     foreach ($resultWithShipper as $key) {
         $boolPresent = false;
         foreach ($sub_categories as $key2) {
             if ($key['id_parent'] == $key2['id'] || $key['id_parent'] == $id_category) {
                 return true;
             }
             foreach ($key2['children'] as $key3) {
                 if ($key['id_parent'] == $key3['id']) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 /**
  * Recursive scan of subcategories
  *
  * @param integer $maxDepth Maximum depth of the tree (i.e. 2 => 3 levels depth)
  * @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!)
  * @param array $excludedIdsArray specify a list of ids to exclude of results
  * @param integer $idLang Specify the id of the language used
  *
  * @return array Subcategories lite tree
  */
 function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL)
 {
     global $link;
     //get idLang
     $idLang = is_null($idLang) ? _USER_ID_LANG_ : intval($idLang);
     //recursivity for subcategories
     $children = array();
     $subcats = $this->getSubCategories($idLang, true);
     if (sizeof($subcats) and ($maxDepth == 0 or $currentDepth < $maxDepth)) {
         foreach ($subcats as &$subcat) {
             if (!$subcat['id_category']) {
                 break;
             } elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray)) {
                 $categ = new Category($subcat['id_category'], $idLang);
                 $categ->name = Category::hideCategoryPosition($categ->name);
                 $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray);
             }
         }
     }
     return array('id' => $this->id_category, 'link' => $link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children);
 }
Example #4
0
 /**
  * Recursive scan of subcategories
  *
  * @param integer $maxDepth Maximum depth of the tree (i.e. 2 => 3 levels depth)
  * @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!)
  * @param array $excludedIdsArray specify a list of ids to exclude of results
  * @param integer $idLang Specify the id of the language used
  *
  * @return array Subcategories lite tree
  */
 function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL)
 {
     global $link;
     if (!(int) $id_lang) {
         $id_lang = _USER_ID_LANG_;
     }
     $children = array();
     if (($maxDepth == 0 or $currentDepth < $maxDepth) and $subcats = $this->getSubCategories((int) $id_lang, true) and sizeof($subcats)) {
         foreach ($subcats as &$subcat) {
             if (!$subcat['id_category']) {
                 break;
             } elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray)) {
                 $categ = new Category((int) $subcat['id_category'], (int) $id_lang);
                 $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, (int) $id_lang, $excludedIdsArray);
             }
         }
     }
     return array('id' => (int) $this->id_category, 'link' => $link->getCategoryLink((int) $this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children);
 }
Example #5
0
    public static function getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang)
    {
        $selectedCat = explode(',', str_replace(' ', '', $selectedCat));
        if (!is_array($selectedCat)) {
            $selectedCat = array();
        }
        if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')) {
            return Db::getInstance()->ExecuteS('
					SELECT c.`id_category`, c.`level_depth`, cl.`name`, IF((
					SELECT COUNT(*)
					FROM `' . _DB_PREFIX_ . 'category` c2
					WHERE c2.`id_parent` = c.`id_category`
			) > 0, 1, 0) AS has_children, ' . ($selectedCat ? '(
					SELECT count(c3.`id_category`)
					FROM `' . _DB_PREFIX_ . 'category` c3
					WHERE c3.`nleft` > c.`nleft`
					AND c3.`nright` < c.`nright`
					AND c3.`id_category`  IN (' . implode(',', array_map('intval', $selectedCat)) . ')
			)' : '0') . ' AS nbSelectedSubCat
					FROM `' . _DB_PREFIX_ . 'category` c
					LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category`' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlRestrictionOnLang('cl') : '') . ')
					WHERE `id_lang` = ' . (int) $id_lang . '
					AND c.`id_parent` = ' . (int) $id_parent . '
					ORDER BY `position` ASC');
        } else {
            $homecat = new Category((int) $id_parent, (int) $id_lang);
            $categories = $homecat->recurseLiteCategTree();
            $categories_table = array();
            if (self::_isFilledArray($categories)) {
                foreach ($categories['children'] as $categorie) {
                    $categorie_obj = new Category((int) $categorie['id'], (int) $id_lang);
                    $all_sub_categories = self::getAllSubCategories((int) $categorie['id'], (int) $id_lang);
                    $categories_table[] = array('id_category' => $categorie['id'], 'level_depth' => $categorie_obj->level_depth, 'name' => $categorie['name'], 'has_children' => (int) (is_array($categorie['children']) && sizeof($categorie['children'])), 'nbSelectedSubCat' => sizeof(array_intersect($selectedCat, array_values($all_sub_categories))));
                }
            }
            return $categories_table;
        }
    }
 private function displayCategoriesSelect($categories, $selected)
 {
     $this->_html .= '<label>' . $this->l('Category') . '</label>
   <div class="margin-form"><select name="id_category">
     <option value="">-- ' . $this->l('Choose') . ' --</option>';
     if (version_compare(_PS_VERSION_, '1.6.0.0', '>=') && method_exists('Category', 'getNestedCategories')) {
         foreach (Category::getNestedCategories(Configuration::get('PS_ROOT_CATEGORY'), $this->_cookie->id_lang) as $idCategory => $categoryInformations) {
             if (Configuration::get('PS_ROOT_CATEGORY') != $idCategory) {
                 $this->_html .= '<option value="' . $idCategory . '"' . ($selected == $idCategory ? ' selected="selected"' : '') . '>' . str_repeat('&#150 ', version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? $categoryInformations['level_depth'] - 1 : $categoryInformations['level_depth']) . $categoryInformations['name'] . '</option>';
             }
             $this->_getChildrensCategories($categoryInformations, $selected);
         }
     } else {
         if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && method_exists('Category', 'recurseLiteCategTree')) {
             $rootCategory = new Category((int) Category::getRootCategory()->id, $this->_cookie->id_lang);
             if (Configuration::get('PS_ROOT_CATEGORY') != $rootCategory->id) {
                 $this->_html .= '<option value="' . $rootCategory->id . '"' . ($selected == $rootCategory->id ? ' selected="selected"' : '') . '>' . $rootCategory->name . '</option>';
             }
             $this->_getChildrensCategories($rootCategory->recurseLiteCategTree(99999, 0, $this->_cookie->id_lang), $selected, 0);
         } else {
             $categories_bkup = $categories;
             $first_category = array_shift($categories_bkup);
             array_unshift($categories_bkup, $first_category);
             $first_category_final = array_shift($first_category);
             $this->recurseCategory($categories, $first_category_final, version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Category::getRootCategory()->id : 1, $selected);
         }
     }
     $this->_html .= ' </select></div>';
 }
Example #7
0
 public function generateFiltersBlock($selected_filters)
 {
     global $smarty;
     $id_category_layered = Tools::getValue('id_category_layered', Tools::getValue('id_category'));
     $category = new Category($id_category_layered, (int) Context::getContext()->cookie->id_lang);
     if ($category->is_all) {
         return $this->display(__FILE__, 'blocklayered_nofilters.tpl');
     }
     $parent_cat = new Category($category->id_parent, (int) Context::getContext()->cookie->id_lang);
     $children_cats = $parent_cat->recurseLiteCategTree(1);
     if ($filter_block = $this->getFilterBlock($selected_filters)) {
         if ($filter_block['nbr_filterBlocks'] == 0) {
             $smarty->assign(array('id_category_layered' => $id_category_layered, 'page_layered' => isset($_GET['p']) ? $_GET['p'] : 1, 'blocklayered_children_cat' => $children_cats, 'controller_layered' => $_GET['controller']));
             return $this->display(__FILE__, 'blocklayered_nofilters.tpl');
         }
         $translate = array();
         $translate['price'] = $this->l('price');
         $translate['weight'] = $this->l('weight');
         $smarty->assign($filter_block);
         $smarty->assign(array('hide_0_values' => Configuration::get('PS_LAYERED_HIDE_0_VALUES'), 'page_layered' => isset($_GET['p']) ? $_GET['p'] : 1, 'blocklayeredSliderName' => $translate, 'blocklayeredSliderName_js' => json_encode($translate), 'filters_js' => json_encode($filter_block['filters'])));
         return $this->display(__FILE__, 'blocklayered.tpl');
     } else {
         $parent_cat = new Category(Configuration::get('PS_HOME_CATEGORY'), (int) Context::getContext()->cookie->id_lang);
         $children_cats = $parent_cat->recurseLiteCategTree(1);
         $smarty->assign(array('id_category_layered' => $id_category_layered, 'blocklayered_children_cat' => $children_cats, 'controller_layered' => $_GET['controller'], 'search_query' => isset($_GET['search_query']) ? $_GET['search_query'] : null, 'page_layered' => isset($_GET['p']) ? $_GET['p'] : 1));
         return $this->display(__FILE__, 'blocklayered_nofilters.tpl');
         //			return false;
     }
 }
Example #8
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);
	}
Example #9
0
 /**
  * Recursive scan of subcategories
  *
  * @param int    $maxDepth         Maximum depth of the tree (i.e. 2 => 3 levels depth)
  * @param int    $currentDepth     specify the current depth in the tree (don't use it, only for recursive calls!)
  * @param int    $idLang           Specify the id of the language used
  * @param array  $excludedIdsArray Specify a list of IDs to exclude of results
  *
  * @param string $format
  *
  * @return array Subcategories lite tree
  */
 public function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = null, $excludedIdsArray = null, $format = 'default')
 {
     $idLang = is_null($idLang) ? Context::getContext()->language->id : (int) $idLang;
     $children = array();
     $subcats = $this->getSubCategories($idLang, true);
     if (($maxDepth == 0 || $currentDepth < $maxDepth) && $subcats && count($subcats)) {
         foreach ($subcats as &$subcat) {
             if (!$subcat['id_category']) {
                 break;
             } elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray)) {
                 $categ = new Category($subcat['id_category'], $idLang);
                 $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray, $format);
             }
         }
     }
     if (is_array($this->description)) {
         foreach ($this->description as $lang => $description) {
             $this->description[$lang] = Category::getDescriptionClean($description);
         }
     } else {
         $this->description = Category::getDescriptionClean($this->description);
     }
     if ($format === 'sitemap') {
         return array('id' => 'category-page-' . (int) $this->id, 'label' => $this->name, 'url' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'children' => $children);
     }
     return array('id' => (int) $this->id, 'link' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc' => $this->description, 'children' => $children);
 }