예제 #1
0
 protected function _prepareHook($params)
 {
     $languages = Language::getLanguages(true, $this->context->shop->id);
     if (!count($languages)) {
         return false;
     }
     $link = new Link();
     if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
         $default_rewrite = array();
         if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) {
             $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']);
             }
         }
         if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) {
             $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']);
             }
         }
         if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) {
             $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
             foreach ($rewrite_infos as $infos) {
                 $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
                 $default_rewrite[$infos['id_lang']] = $arr_link;
             }
         }
         $this->smarty->assign('lang_rewrite_urls', $default_rewrite);
     }
     return true;
 }
예제 #2
0
 /**
  * Returns module content for header
  *
  * @param array $params Parameters
  * @return string Content
  */
 public function hookTop($params)
 {
     global $smarty;
     $languages = Language::getLanguages();
     if (!count($languages)) {
         return;
     }
     $link = new Link();
     if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
         $default_rewrite = array();
         $phpSelf = isset($_SERVER['PHP_SELF']) ? substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) : '';
         if ($phpSelf == 'product.php' and $id_product = (int) Tools::getValue('id_product')) {
             $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']);
             }
         }
         if ($phpSelf == 'category.php' and $id_category = (int) Tools::getValue('id_category')) {
             $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category);
             foreach ($rewrite_infos as $infos) {
                 $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']);
             }
         }
         if ($phpSelf == 'cms.php' and ($id_cms = (int) Tools::getValue('id_cms') or $id_cms_category = (int) Tools::getValue('id_cms_category'))) {
             $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
             foreach ($rewrite_infos as $infos) {
                 $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], NULL, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
                 $default_rewrite[$infos['id_lang']] = $arr_link;
             }
         }
         if (count($default_rewrite)) {
             $smarty->assign('lang_rewrite_urls', $default_rewrite);
         }
     }
     $smarty->assign('languages', $languages);
     return $this->display(__FILE__, 'blocklanguages.tpl');
 }
예제 #3
0
    private function _postProcess()
    {
        Configuration::updateValue('GSITEMAP_ALL_CMS', (int) Tools::getValue('GSITEMAP_ALL_CMS'));
        Configuration::updateValue('GSITEMAP_ALL_PRODUCTS', (int) Tools::getValue('GSITEMAP_ALL_PRODUCTS'));
        $link = new Link();
        $langs = Language::getLanguages();
        $xmlString = <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
</urlset>
XML;
        $xml = new SimpleXMLElement($xmlString);
        if (Configuration::get('PS_REWRITING_SETTINGS') and sizeof($langs) > 1) {
            foreach ($langs as $lang) {
                $this->_addSitemapNode($xml, Tools::getShopDomain(true, true) . __PS_BASE_URI__ . $lang['iso_code'] . '/', '1.00', 'daily', date('Y-m-d'));
            }
        } else {
            $this->_addSitemapNode($xml, Tools::getShopDomain(true, true) . __PS_BASE_URI__, '1.00', 'daily', date('Y-m-d'));
        }
        /* CMS Generator */
        if (Configuration::get('GSITEMAP_ALL_CMS') or !Module::isInstalled('blockcms')) {
            $sql_cms = '
			SELECT DISTINCT ' . (Configuration::get('PS_REWRITING_SETTINGS') ? 'cl.id_cms, cl.link_rewrite, cl.id_lang' : 'cl.id_cms') . ' FROM ' . _DB_PREFIX_ . 'cms_lang cl
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (cl.id_lang = l.id_lang)
			WHERE l.`active` = 1
			ORDER BY cl.id_cms, cl.id_lang ASC';
        } elseif (Module::isInstalled('blockcms')) {
            $sql_cms = '
			SELECT DISTINCT ' . (Configuration::get('PS_REWRITING_SETTINGS') ? 'cl.id_cms, cl.link_rewrite, cl.id_lang' : 'cl.id_cms') . ' FROM ' . _DB_PREFIX_ . 'cms_block_page b
			LEFT JOIN ' . _DB_PREFIX_ . 'cms_lang cl ON (b.id_cms = cl.id_cms)
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (cl.id_lang = l.id_lang)
			WHERE l.`active` = 1
			ORDER BY cl.id_cms, cl.id_lang ASC';
        }
        $cmss = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql_cms);
        foreach ($cmss as $cms) {
            $tmpLink = Configuration::get('PS_REWRITING_SETTINGS') ? $link->getCMSLink((int) $cms['id_cms'], $cms['link_rewrite'], false, (int) $cms['id_lang']) : $link->getCMSLink((int) $cms['id_cms']);
            $this->_addSitemapNode($xml, $tmpLink, '0.8', 'daily');
        }
        /* Categories Generator */
        if (Configuration::get('PS_REWRITING_SETTINGS')) {
            $categories = Db::getInstance()->ExecuteS('
			SELECT c.id_category, c.level_depth, link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, cl.id_lang
			FROM ' . _DB_PREFIX_ . 'category c
			LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON c.id_category = cl.id_category
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON cl.id_lang = l.id_lang
			WHERE l.`active` = 1 AND c.`active` = 1 AND c.id_category != 1
			ORDER BY cl.id_category, cl.id_lang ASC');
        } else {
            $categories = Db::getInstance()->ExecuteS('SELECT c.id_category, c.level_depth, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd
			FROM ' . _DB_PREFIX_ . 'category c 
			ORDER BY c.id_category ASC');
        }
        foreach ($categories as $category) {
            if (($priority = 0.9 - $category['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $tmpLink = Configuration::get('PS_REWRITING_SETTINGS') ? $link->getCategoryLink((int) $category['id_category'], $category['link_rewrite'], (int) $category['id_lang']) : $link->getCategoryLink((int) $category['id_category']);
            $this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($category['date_upd'], 0, 10));
        }
        $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT p.id_product, pl.link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') date_upd, pl.id_lang, cl.`link_rewrite` category, ean13, i.id_image, il.legend legend_image, (
			SELECT MIN(level_depth)
			FROM ' . _DB_PREFIX_ . 'product p2
			LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp2 ON p2.id_product = cp2.id_product
			LEFT JOIN ' . _DB_PREFIX_ . 'category c2 ON cp2.id_category = c2.id_category
			WHERE p2.id_product = p.id_product AND p2.`active` = 1 AND c2.`active` = 1) AS level_depth
		FROM ' . _DB_PREFIX_ . 'product p
		LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (p.id_product = pl.id_product)
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND pl.`id_lang` = cl.`id_lang`)
		LEFT JOIN ' . _DB_PREFIX_ . 'image i ON p.id_product = i.id_product
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND pl.`id_lang` = il.`id_lang`)
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (pl.id_lang = l.id_lang)
		WHERE l.`active` = 1 AND p.`active` = 1
		' . (Configuration::get('GSITEMAP_ALL_PRODUCTS') ? '' : 'HAVING level_depth IS NOT NULL') . '
		ORDER BY pl.id_product, pl.id_lang ASC');
        $tmp = null;
        $res = null;
        foreach ($products as $product) {
            if ($tmp == $product['id_product']) {
                $res[$tmp]['images'][] = array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']);
            } else {
                $tmp = $product['id_product'];
                $res[$tmp] = $product;
                unset($res[$tmp]['id_image'], $res[$tmp]['legend_image']);
                $res[$tmp]['images'][] = array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']);
            }
        }
        foreach ($res as $product) {
            if (($priority = 0.7 - $product['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $tmpLink = $link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $product['category'], $product['ean13'], (int) $product['id_lang']);
            $sitemap = $this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($product['date_upd'], 0, 10));
            $sitemap = $this->_addSitemapNodeImage($sitemap, $product);
        }
        /* Add classic pages (contact, best sales, new products...) */
        $pages = array('authentication' => true, 'best-sales' => false, 'contact-form' => true, 'discount' => false, 'index' => false, 'manufacturer' => false, 'new-products' => false, 'prices-drop' => false, 'supplier' => false, 'store' => false);
        // Don't show suppliers and manufacturers if they are disallowed
        if (!Module::getInstanceByName('blockmanufacturer')->id && !Configuration::get('PS_DISPLAY_SUPPLIERS')) {
            unset($pages['manufacturer']);
        }
        if (!Module::getInstanceByName('blocksupplier')->id && !Configuration::get('PS_DISPLAY_SUPPLIERS')) {
            unset($pages['supplier']);
        }
        // Generate nodes for pages
        if (Configuration::get('PS_REWRITING_SETTINGS')) {
            foreach ($pages as $page => $ssl) {
                foreach ($langs as $lang) {
                    $this->_addSitemapNode($xml, $link->getPageLink($page . '.php', $ssl, $lang['id_lang']), '0.5', 'monthly');
                }
            }
        } else {
            foreach ($pages as $page => $ssl) {
                $this->_addSitemapNode($xml, $link->getPageLink($page . '.php', $ssl), '0.5', 'monthly');
            }
        }
        $xmlString = $xml->asXML();
        $fp = fopen(GSITEMAP_FILE, 'w');
        fwrite($fp, $xmlString);
        fclose($fp);
        $res = file_exists(GSITEMAP_FILE);
        $this->_html .= '<h3 class="' . ($res ? 'conf confirm' : 'alert error') . '" style="margin-bottom: 20px">';
        $this->_html .= $res ? $this->l('Sitemap file generated') : $this->l('Error while creating sitemap file');
        $this->_html .= '</h3>';
    }
예제 #4
0
 public function getLink($menu)
 {
     if ($this->edit_string) {
         return '#';
     }
     $link = new Link();
     $id_lang = Context::getContext()->language->id;
     $value = (int) $menu['item'];
     $result = '';
     switch ($menu['type']) {
         case 'product':
             if (Validate::isLoadedObject($obj_pro = new Product($value, true, $id_lang))) {
                 $result = $link->getProductLink((int) $obj_pro->id, $obj_pro->link_rewrite, null, null, $id_lang);
             }
             break;
         case 'category':
             if (Validate::isLoadedObject($obj_cate = new Category($value, $id_lang))) {
                 $result = $link->getCategoryLink((int) $obj_cate->id, $obj_cate->link_rewrite, $id_lang);
             }
             break;
         case 'cms':
             if (Validate::isLoadedObject($obj_cms = new CMS($value, $id_lang))) {
                 $result = $link->getCMSLink((int) $obj_cms->id, $obj_cms->link_rewrite, $id_lang);
             }
             break;
         case 'url':
             $value = $menu['url'];
             if ($value == 'index' || $value == 'index.php') {
                 $result = $link->getPageLink('index.php', false, $id_lang);
                 break;
             }
             $regex = '((https?|ftp)\\:\\/\\/)?';
             // SCHEME
             $regex .= '([a-z0-9+!*(),;?&=\\$_.-]+(\\:[a-z0-9+!*(),;?&=\\$_.-]+)?@)?';
             // User and Pass
             $regex .= '([a-z0-9-.]*)\\.([a-z]{2,3})';
             // Host or IP
             $regex .= '(\\:[0-9]{2,5})?';
             // Port
             $regex .= '(\\/([a-z0-9+\\$_-]\\.?)+)*\\/?';
             // Path
             $regex .= '(\\?[a-z+&\\$_.-][a-z0-9;:@&%=+\\/\\$_.-]*)?';
             // GET Query
             $regex .= '(#[a-z_.-][a-z0-9+\\$_.-]*)?';
             // Anchor
             if ($value == '#' || preg_match("/^{$regex}\$/", $value)) {
                 $result = $value;
                 break;
             }
             $result = $link->getPageLink($value, false, $id_lang);
             break;
         case 'manufacture':
             if (Validate::isLoadedObject($obj_manu = new Manufacturer($value, $id_lang))) {
                 $result = $link->getManufacturerLink((int) $obj_manu->id, $obj_manu->link_rewrite, $id_lang);
             }
             break;
         case 'supplier':
             if (Validate::isLoadedObject($obj_supp = new Supplier($value, $id_lang))) {
                 $result = $link->getSupplierLink((int) $obj_supp->id, $obj_supp->link_rewrite, $id_lang);
             }
             break;
         default:
             $result = '#';
             break;
     }
     return $result;
 }
예제 #5
0
    /**
     * Hydrate $link_sitemap with categories link
     *
     * @param array  $link_sitemap contain all the links for the Google Sitemap file to be generated
     * @param string $lang         language of link to add
     * @param int    $index        index of the current Google Sitemap file
     * @param int    $i            count of elements added to sitemap main array
     * @param int    $id_category  category object identifier
     *
     * @return bool
     */
    private function _getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_category = 0)
    {
        $link = new Link();
        if (method_exists('ShopUrl', 'resetMainDomainCache')) {
            ShopUrl::resetMainDomainCache();
        }
        $categories_id = Db::getInstance()->ExecuteS('SELECT c.id_category FROM `' . _DB_PREFIX_ . 'category` c
				INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON c.`id_category` = cs.`id_category`
				WHERE c.`active` = 1 AND c.`id_category` != 1 AND c.id_parent > 0 AND c.`id_category` > 0 AND cs.`id_shop` = ' . (int) $this->context->shop->id . ' ORDER BY c.`id_category` ASC');
        foreach ($categories_id as $category_id) {
            $category = new Category((int) $category_id['id_category'], (int) $lang['id_lang']);
            $url = $link->getCategoryLink($category, urlencode($category->link_rewrite), (int) $lang['id_lang']);
            if ($category->id_image) {
                $image_link = $this->context->link->getCatImageLink($category->link_rewrite, (int) $category->id_image, 'category_default');
                $image_link = !in_array(rtrim(Context::getContext()->shop->virtual_uri, '/'), explode('/', $image_link)) ? str_replace(array('https', Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri), array('http', Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri . Context::getContext()->shop->virtual_uri), $image_link) : $image_link;
            }
            $file_headers = Configuration::get('GSITEMAP_CHECK_IMAGE_FILE') ? @get_headers($image_link) : true;
            $image_category = array();
            if (isset($image_link) && ($file_headers[0] != 'HTTP/1.1 404 Not Found' || $file_headers === true)) {
                $image_category = array('title_img' => htmlspecialchars(strip_tags($category->name)), 'link' => $image_link);
            }
            if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'category', 'page' => 'category', 'lastmod' => $category->date_upd, 'link' => $url, 'image' => $image_category), $lang['iso_code'], $index, $i, (int) $category_id['id_category'])) {
                return false;
            }
            unset($image_link);
        }
        return true;
    }
예제 #6
0
    public function getFilterBlock($selectedFilters = array())
    {
        global $cookie;
        static $cache = null;
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $currency = Context::getContext()->currency;
        } else {
            $currency = Currency::getCurrent();
        }
        if (is_array($cache)) {
            return $cache;
        }
        $id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', 1));
        if ($id_parent == 1) {
            return;
        }
        $parent = new Category((int) $id_parent);
        if (version_compare(_PS_VERSION_, '1.5', '>')) {
            $id_shop = (int) Context::getContext()->shop->getId(true);
        } else {
            $id_shop = 0;
        }
        /* Get the filters for the current category */
        $filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'layered_category
			WHERE id_category = ' . (int) $id_parent . '
				AND id_shop = ' . $id_shop . '
			GROUP BY `type`, id_value ORDER BY position ASC');
        // Remove all empty selected filters
        foreach ($selectedFilters as $key => $value) {
            switch ($key) {
                case 'price':
                case 'weight':
                    if ($value[0] === '' && $value[1] === '') {
                        unset($selectedFilters[$key]);
                    }
                    break;
                default:
                    if ($value == '') {
                        unset($selectedFilters[$key]);
                    }
                    break;
            }
        }
        $filterBlocks = array();
        foreach ($filters as $filter) {
            $sqlQuery = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '');
            switch ($filter['type']) {
                // conditions + quantities + weight + price
                case 'price':
                case 'weight':
                case 'condition':
                case 'quantity':
                    if (version_compare(_PS_VERSION_, '1.5', '>')) {
                        $sqlQuery['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, sa.`quantity`, p.`weight` ';
                    } else {
                        $sqlQuery['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight` ';
                    }
                    $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'product p ';
                    $sqlQuery['join'] = '
					INNER JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = p.id_product)
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND
					' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= ' . (int) $parent->nleft . '
					AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
					AND c.active = 1) ';
                    if (version_compare(_PS_VERSION_, '1.5', '>')) {
                        $sqlQuery['join'] .= 'LEFT JOIN ' . _DB_PREFIX_ . 'stock_available sa
							ON (sa.id_product = p.id_product AND sa.id_shop = ' . (int) $this->context->shop->getID(true) . ') ';
                    }
                    $sqlQuery['where'] = 'WHERE p.`active` = 1 ';
                    $sqlQuery['group'] = ' GROUP BY p.id_product ';
                    break;
                case 'manufacturer':
                    $sqlQuery['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer ';
                    $sqlQuery['from'] = '
					FROM `' . _DB_PREFIX_ . 'category_product` cp
					INNER JOIN  `' . _DB_PREFIX_ . 'category` c ON (c.id_category = cp.id_category)
					INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1)
					INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) ';
                    $sqlQuery['where'] = 'WHERE 
					' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= ' . (int) $parent->nleft . '
					AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
					AND c.active = 1 ';
                    $sqlQuery['group'] = ' GROUP BY p.id_manufacturer ';
                    break;
                case 'id_attribute_group':
                    // attribute group
                    $sqlQuery['select'] = '
					SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
					a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,
					liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title';
                    $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'layered_product_attribute lpa
					INNER JOIN ' . _DB_PREFIX_ . 'attribute a
					ON a.id_attribute = lpa.id_attribute
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al
					ON al.id_attribute = a.id_attribute
					AND al.id_lang = ' . (int) $cookie->id_lang . '
					INNER JOIN ' . _DB_PREFIX_ . 'product as p
					ON p.id_product = lpa.id_product
					AND p.active = 1
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_group ag
					ON ag.id_attribute_group = lpa.id_attribute_group
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl
					ON agl.id_attribute_group = lpa.id_attribute_group
					AND agl.id_lang = ' . (int) $cookie->id_lang . '
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value liagl
					ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value lial
					ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = ' . (int) $cookie->id_lang . ') ';
                    $sqlQuery['where'] = 'WHERE a.id_attribute_group = ' . (int) $filter['id_value'] . '
					AND p.id_product IN (
					SELECT id_product
					FROM ' . _DB_PREFIX_ . 'category_product cp
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND 
					' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= ' . (int) $parent->nleft . '
					AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
					AND c.active = 1)) ';
                    $sqlQuery['group'] = '
					GROUP BY lpa.id_attribute
					ORDER BY id_attribute_group, id_attribute ';
                    break;
                case 'id_feature':
                    $sqlQuery['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
					COUNT(DISTINCT p.id_product) nbr,
					lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title ';
                    $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'feature_product fp
					INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = fp.id_product AND p.active = 1)
					LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = ' . (int) $cookie->id_lang . ')
					INNER JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
					LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value lifl
					ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value lifvl
					ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = ' . (int) $cookie->id_lang . ') ';
                    $sqlQuery['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = ' . (int) $filter['id_value'] . '
					AND p.id_product IN (
					SELECT id_product
					FROM ' . _DB_PREFIX_ . 'category_product cp
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND
					' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= ' . (int) $parent->nleft . '
					AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
					AND c.active = 1)) ';
                    $sqlQuery['group'] = 'GROUP BY fv.id_feature_value ';
                    break;
                case 'category':
                    $sqlQuery['select'] = '
					SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # ';
                    $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'category_product cp
					LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) ';
                    $sqlQuery['where'] = '
					WHERE cp.id_category = c.id_category ';
                    $sqlQuery['group'] = ') count_products
					FROM ' . _DB_PREFIX_ . 'category c
					LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
					WHERE c.id_parent = ' . (int) $id_parent . '
					GROUP BY c.id_category ORDER BY level_depth, c.position';
            }
            foreach ($filters as $filterTmp) {
                $methodName = 'get' . ucfirst($filterTmp['type']) . 'FilterSubQuery';
                if (method_exists('BlockLayered', $methodName) && (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) {
                    if ($filter['type'] == $filterTmp['type'] && $filter['id_value'] == $filterTmp['id_value']) {
                        $subQueryFilter = self::$methodName(array(), true);
                    } else {
                        if (!is_null($filterTmp['id_value'])) {
                            $selected_filters_cleaned = $this->cleanFilterByIdValue(@$selectedFilters[$filterTmp['type']], $filterTmp['id_value']);
                        } else {
                            $selected_filters_cleaned = @$selectedFilters[$filterTmp['type']];
                        }
                        $subQueryFilter = self::$methodName($selected_filters_cleaned, $filter['type'] == $filterTmp['type']);
                    }
                    foreach ($subQueryFilter as $key => $value) {
                        $sqlQuery[$key] .= $value;
                    }
                }
            }
            $products = false;
            if (!empty($sqlQuery['from'])) {
                if (version_compare(_PS_VERSION_, '1.5', '>')) {
                    $sqlQuery['from'] .= Context::getContext()->shop->addSqlAssociation('product', 'p');
                }
                $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sqlQuery['select'] . "\n" . $sqlQuery['from'] . "\n" . $sqlQuery['join'] . "\n" . $sqlQuery['where'] . "\n" . $sqlQuery['group']);
            }
            foreach ($filters as $filterTmp) {
                $methodName = 'filterProductsBy' . ucfirst($filterTmp['type']);
                if (method_exists('BlockLayered', $methodName) && (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) {
                    if ($filter['type'] == $filterTmp['type']) {
                        $products = self::$methodName(array(), $products);
                    } else {
                        $products = self::$methodName(@$selectedFilters[$filterTmp['type']], $products);
                    }
                }
            }
            switch ($filter['type']) {
                case 'price':
                    $priceArray = array('type_lite' => 'price', 'type' => 'price', 'id_key' => 0, 'name' => $this->l('Price'), 'slider' => true, 'max' => '0', 'min' => null, 'values' => array('1' => 0), 'unit' => $currency->sign, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (is_null($priceArray['min'])) {
                                $priceArray['min'] = $product['price_min'];
                                $priceArray['values'][0] = $product['price_min'];
                            } else {
                                if ($priceArray['min'] > $product['price_min']) {
                                    $priceArray['min'] = $product['price_min'];
                                    $priceArray['values'][0] = $product['price_min'];
                                }
                            }
                            if ($priceArray['max'] < $product['price_max']) {
                                $priceArray['max'] = $product['price_max'];
                                $priceArray['values'][1] = $product['price_max'];
                            }
                        }
                    }
                    if ($priceArray['max'] != $priceArray['min'] && $priceArray['min'] != null) {
                        if ($filter['filter_type'] == 2) {
                            $priceArray['list_of_values'] = array();
                            $nbr_of_value = $filter['filter_show_limit'];
                            if ($nbr_of_value < 2) {
                                $nbr_of_value = 4;
                            }
                            $delta = ($priceArray['max'] - $priceArray['min']) / $nbr_of_value;
                            $current_step = $priceArray['min'];
                            for ($i = 0; $i < $nbr_of_value; $i++) {
                                $priceArray['list_of_values'][] = array((int) ($priceArray['min'] + $i * $delta), (int) ($priceArray['min'] + ($i + 1) * $delta));
                            }
                        }
                        if (isset($selectedFilters['price']) && isset($selectedFilters['price'][0]) && isset($selectedFilters['price'][1])) {
                            $priceArray['values'][0] = $selectedFilters['price'][0];
                            $priceArray['values'][1] = $selectedFilters['price'][1];
                        }
                        $filterBlocks[] = $priceArray;
                    }
                    break;
                case 'weight':
                    $weightArray = array('type_lite' => 'weight', 'type' => 'weight', 'id_key' => 0, 'name' => $this->l('Weight'), 'slider' => true, 'max' => '0', 'min' => null, 'values' => array('1' => 0), 'unit' => Configuration::get('PS_WEIGHT_UNIT'), 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (is_null($weightArray['min'])) {
                                $weightArray['min'] = $product['weight'];
                                $weightArray['values'][0] = $product['weight'];
                            } else {
                                if ($weightArray['min'] > $product['weight']) {
                                    $weightArray['min'] = $product['weight'];
                                    $weightArray['values'][0] = $product['weight'];
                                }
                            }
                            if ($weightArray['max'] < $product['weight']) {
                                $weightArray['max'] = $product['weight'];
                                $weightArray['values'][1] = $product['weight'];
                            }
                        }
                    }
                    if ($weightArray['max'] != $weightArray['min'] && $weightArray['min'] != null) {
                        if (isset($selectedFilters['weight']) && isset($selectedFilters['weight'][0]) && isset($selectedFilters['weight'][1])) {
                            $weightArray['values'][0] = $selectedFilters['weight'][0];
                            $weightArray['values'][1] = $selectedFilters['weight'][1];
                        }
                        $filterBlocks[] = $weightArray;
                    }
                    break;
                case 'condition':
                    $conditionArray = array('new' => array('name' => $this->l('New'), 'nbr' => 0), 'used' => array('name' => $this->l('Used'), 'nbr' => 0), 'refurbished' => array('name' => $this->l('Refurbished'), 'nbr' => 0));
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (isset($selectedFilters['condition']) && in_array($product['condition'], $selectedFilters['condition'])) {
                                $conditionArray[$product['condition']]['checked'] = true;
                            }
                        }
                    }
                    foreach ($conditionArray as $key => $condition) {
                        if (isset($selectedFilters['condition']) && in_array($key, $selectedFilters['condition'])) {
                            $conditionArray[$key]['checked'] = true;
                        }
                    }
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (isset($conditionArray[$product['condition']])) {
                                $conditionArray[$product['condition']]['nbr']++;
                            }
                        }
                    }
                    $filterBlocks[] = array('type_lite' => 'condition', 'type' => 'condition', 'id_key' => 0, 'name' => $this->l('Condition'), 'values' => $conditionArray, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    break;
                case 'quantity':
                    $quantityArray = array(0 => array('name' => $this->l('Not available'), 'nbr' => 0), 1 => array('name' => $this->l('In stock'), 'nbr' => 0));
                    foreach ($quantityArray as $key => $quantity) {
                        if (isset($selectedFilters['quantity']) && in_array($key, $selectedFilters['quantity'])) {
                            $quantityArray[$key]['checked'] = true;
                        }
                    }
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            $quantityArray[(int) ($product['quantity'] > 0)]['nbr']++;
                        }
                    }
                    $filterBlocks[] = array('type_lite' => 'quantity', 'type' => 'quantity', 'id_key' => 0, 'name' => $this->l('Availability'), 'values' => $quantityArray, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    break;
                case 'manufacturer':
                    if (isset($products) && $products) {
                        $manufaturersArray = array();
                        foreach ($products as $manufacturer) {
                            $manufaturersArray[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']);
                            if (isset($selectedFilters['manufacturer']) && in_array((int) $manufacturer['id_manufacturer'], $selectedFilters['manufacturer'])) {
                                $manufaturersArray[$manufacturer['id_manufacturer']]['checked'] = true;
                            }
                        }
                        $filterBlocks[] = array('type_lite' => 'manufacturer', 'type' => 'manufacturer', 'id_key' => 0, 'name' => $this->l('Manufacturer'), 'values' => $manufaturersArray, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    }
                    break;
                case 'id_attribute_group':
                    $attributesArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $attributes) {
                            if (!isset($attributesArray[$attributes['id_attribute_group']])) {
                                $attributesArray[$attributes['id_attribute_group']] = array('type_lite' => 'id_attribute_group', 'type' => 'id_attribute_group', 'id_key' => (int) $attributes['id_attribute_group'], 'name' => $attributes['attribute_group_name'], 'is_color_group' => (bool) $attributes['is_color_group'], 'values' => array(), 'url_name' => $attributes['name_url_name'], 'meta_title' => $attributes['name_meta_title'], 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                            }
                            $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array('color' => $attributes['color'], 'name' => $attributes['attribute_name'], 'nbr' => (int) $attributes['nbr'], 'url_name' => $attributes['value_url_name'], 'meta_title' => $attributes['value_meta_title']);
                            if (isset($selectedFilters['id_attribute_group'][$attributes['id_attribute']])) {
                                $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']]['checked'] = true;
                            }
                        }
                        $filterBlocks = array_merge($filterBlocks, $attributesArray);
                    }
                    break;
                case 'id_feature':
                    $featureArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $feature) {
                            if (!isset($featureArray[$feature['id_feature']])) {
                                $featureArray[$feature['id_feature']] = array('type_lite' => 'id_feature', 'type' => 'id_feature', 'id_key' => (int) $feature['id_feature'], 'values' => array(), 'name' => $feature['feature_name'], 'url_name' => $feature['name_url_name'], 'meta_title' => $feature['name_meta_title'], 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                            }
                            $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']] = array('nbr' => (int) $feature['nbr'], 'name' => $feature['value'], 'url_name' => $feature['value_url_name'], 'meta_title' => $feature['value_meta_title']);
                            if (isset($selectedFilters['id_feature'][$feature['id_feature_value']])) {
                                $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']]['checked'] = true;
                            }
                        }
                        $filterBlocks = array_merge($filterBlocks, $featureArray);
                    }
                    break;
                case 'category':
                    $tmpArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $category) {
                            $tmpArray[$category['id_category']] = array('name' => $category['name'], 'nbr' => (int) $category['count_products']);
                            if (isset($selectedFilters['category']) && in_array($category['id_category'], $selectedFilters['category'])) {
                                $tmpArray[$category['id_category']]['checked'] = true;
                            }
                        }
                        $filterBlocks[] = array('type_lite' => 'category', 'type' => 'category', 'id_key' => 0, 'name' => $this->l('Categories'), 'values' => $tmpArray, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type']);
                    }
                    break;
            }
        }
        // All non indexable attribute and feature
        $nonIndexable = array();
        // Get all non indexable attribute groups
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT public_name
		FROM `' . _DB_PREFIX_ . 'attribute_group_lang` agl
		LEFT JOIN `' . _DB_PREFIX_ . 'layered_indexable_attribute_group` liag
		ON liag.id_attribute_group = agl.id_attribute_group
		WHERE indexable IS NULL OR indexable = 0
		AND id_lang = ' . (int) $cookie->id_lang) as $attribute) {
            $nonIndexable[] = Tools::link_rewrite($attribute['public_name']);
        }
        // Get all non indexable features
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT name
		FROM `' . _DB_PREFIX_ . 'feature_lang` fl
		LEFT JOIN  `' . _DB_PREFIX_ . 'layered_indexable_feature` lif
		ON lif.id_feature = fl.id_feature
		WHERE indexable IS NULL OR indexable = 0
		AND id_lang = ' . (int) $cookie->id_lang) as $attribute) {
            $nonIndexable[] = Tools::link_rewrite($attribute['name']);
        }
        //generate SEO link
        $paramSelected = '';
        $param_product_url = '';
        $optionCheckedArray = array();
        $paramGroupSelectedArray = array();
        $titleValues = array();
        $link = new Link();
        $linkBase = $link->getCategoryLink($id_parent, Category::getLinkRewrite($id_parent, (int) $cookie->id_lang), (int) $cookie->id_lang);
        $filterBlockList = array();
        //get filters checked by group
        foreach ($filterBlocks as $typeFilter) {
            $filterName = !empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name'];
            $paramGroupSelected = '';
            foreach ($typeFilter['values'] as $key => $value) {
                if (is_array($value) && array_key_exists('checked', $value)) {
                    $valueName = !empty($value['url_name']) ? $value['url_name'] : $value['name'];
                    $paramGroupSelected .= '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                    $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = Tools::link_rewrite($valueName);
                    if (!isset($titleValues[$filterName])) {
                        $titleValues[$filterName] = array();
                    }
                    $titleValues[$filterName][] = $valueName;
                } else {
                    $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = array();
                }
            }
            if (!empty($paramGroupSelected)) {
                $paramSelected .= '/' . str_replace('-', '_', Tools::link_rewrite($filterName)) . $paramGroupSelected;
                $optionCheckedArray[Tools::link_rewrite($filterName)] = $paramGroupSelected;
            }
            // select only attribute and group attribute to display an unique product combination link
            if (!empty($paramGroupSelected) && $typeFilter['type'] == 'id_attribute_group') {
                $param_product_url .= '/' . str_replace('-', '_', Tools::link_rewrite($filterName)) . $paramGroupSelected;
            }
        }
        if ($this->page > 1) {
            $paramSelected .= '/page-' . $this->page;
        }
        $blackList = array('weight', 'price');
        $nofollow = false;
        foreach ($filterBlocks as &$typeFilter) {
            $filterName = !empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name'];
            if (count($typeFilter) > 0 && !in_array($typeFilter['type'], $blackList)) {
                foreach ($typeFilter['values'] as $key => $values) {
                    $nofollow = false;
                    $optionCheckedCloneArray = $optionCheckedArray;
                    //if not filters checked, add parameter
                    $valueName = !empty($values['url_name']) ? $values['url_name'] : $values['name'];
                    if (!in_array(Tools::link_rewrite($valueName), $paramGroupSelectedArray[Tools::link_rewrite($filterName)])) {
                        //update parameter filter checked before
                        if (array_key_exists(Tools::link_rewrite($filterName), $optionCheckedArray)) {
                            $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = $optionCheckedCloneArray[Tools::link_rewrite($filterName)] . '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                            $nofollow = true;
                        } else {
                            $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                        }
                    } else {
                        // Remove selected parameters
                        $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = str_replace('-' . str_replace('-', '_', Tools::link_rewrite($valueName)), '', $optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
                        if (empty($optionCheckedCloneArray[Tools::link_rewrite($filterName)])) {
                            unset($optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
                        }
                    }
                    $parameters = '';
                    foreach ($optionCheckedCloneArray as $keyGroup => $valueGroup) {
                        $parameters .= '/' . str_replace('-', '_', $keyGroup) . $valueGroup;
                    }
                    // Check if there is an non indexable attribute or feature in the url
                    foreach ($nonIndexable as $value) {
                        if (strpos($parameters, '/' . $value) !== false) {
                            $nofollow = true;
                        }
                    }
                    //write link by mode rewriting
                    if (!Configuration::get('PS_REWRITING_SETTINGS')) {
                        $typeFilter['values'][$key]['link'] = $linkBase . '&selected_filters=' . $parameters;
                    } else {
                        $typeFilter['values'][$key]['link'] = $linkBase . $parameters;
                    }
                    $typeFilter['values'][$key]['rel'] = $nofollow ? 'nofollow' : '';
                }
            }
        }
        $nFilters = 0;
        if (isset($selectedFilters['price'])) {
            if ($priceArray['min'] == $selectedFilters['price'][0] && $priceArray['max'] == $selectedFilters['price'][1]) {
                unset($selectedFilters['price']);
            }
        }
        if (isset($selectedFilters['weight'])) {
            if ($weightArray['min'] == $selectedFilters['weight'][0] && $weightArray['max'] == $selectedFilters['weight'][1]) {
                unset($selectedFilters['weight']);
            }
        }
        foreach ($selectedFilters as $filters) {
            $nFilters += count($filters);
        }
        $cache = array('layered_show_qties' => (int) Configuration::get('PS_LAYERED_SHOW_QTIES'), 'id_category_layered' => (int) $id_parent, 'selected_filters' => $selectedFilters, 'n_filters' => (int) $nFilters, 'nbr_filterBlocks' => count($filterBlocks), 'filters' => $filterBlocks, 'title_values' => $titleValues, 'current_friendly_url' => htmlentities($paramSelected), 'param_product_url' => htmlentities($param_product_url), 'nofollow' => !empty($paramSelected) || $nofollow);
        return $cache;
    }
예제 #7
0
    private function _postProcess()
    {
        $link = new Link();
        $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
        $ruBackup = $_SERVER['REQUEST_URI'];
        $snBackup = $_SERVER['SCRIPT_NAME'];
        $getBackup = $_GET;
        $xml = new SimpleXMLElement('<urlset
			xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
			xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
			http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
		</urlset>');
        $sitemap = $xml->addChild('url');
        $sitemap->addChild('loc', 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__);
        $sitemap->addChild('priority', '1.00');
        $sitemap->addChild('lastmod', date("Y-m-d"));
        $sitemap->addChild('changefreq', 'daily');
        $cmss = Db::getInstance()->ExecuteS('
		SELECT DISTINCT b.id_cms, cl.link_rewrite, cl.id_lang
		FROM ' . _DB_PREFIX_ . 'block_cms b
		LEFT JOIN ' . _DB_PREFIX_ . 'cms_lang cl ON (b.id_cms = cl.id_cms)
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (cl.id_lang = l.id_lang)
		WHERE l.`active` = 1
		ORDER BY cl.id_cms, cl.id_lang ASC');
        foreach ($cmss as $cms) {
            $sitemap = $xml->addChild('url');
            $tmpLink = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']);
            $_GET = array('id_cms' => $cms['id_cms']);
            if ($cms['id_lang'] != $defaultLanguage) {
                $_SERVER['REQUEST_URI'] = substr($tmpLink, strpos($tmpLink, __PS_BASE_URI__));
                $_SERVER['SCRIPT_NAME'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
                $link = new Link();
                $tmpLink = $link->getLanguageLink(intval($cms['id_lang']));
                $tmpLink = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . $tmpLink;
            }
            $sitemap->addChild('loc', htmlspecialchars($tmpLink));
            $sitemap->addChild('priority', '0.8');
            $sitemap->addChild('changefreq', 'monthly');
        }
        $categories = Db::getInstance()->ExecuteS('
		SELECT c.id_category, c.level_depth, link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, cl.id_lang
		FROM ' . _DB_PREFIX_ . 'category c
		LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON c.id_category = cl.id_category
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON cl.id_lang = l.id_lang
		WHERE l.`active` = 1 AND c.`active` = 1 AND c.id_category != 1
		ORDER BY cl.id_category, cl.id_lang ASC');
        foreach ($categories as $category) {
            if (($priority = 0.9 - $category['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $sitemap = $xml->addChild('url');
            $tmpLink = $link->getCategoryLink($category['id_category'], $category['link_rewrite']);
            $_GET = array('id_category' => $category['id_category']);
            if ($category['id_lang'] != $defaultLanguage) {
                $_SERVER['REQUEST_URI'] = substr($tmpLink, strpos($tmpLink, __PS_BASE_URI__));
                $_SERVER['SCRIPT_NAME'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
                $link = new Link();
                $tmpLink = $link->getLanguageLink(intval($category['id_lang']));
                $tmpLink = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . $tmpLink;
            }
            $sitemap->addChild('loc', htmlspecialchars($tmpLink));
            $sitemap->addChild('priority', $priority);
            $sitemap->addChild('lastmod', substr($category['date_upd'], 0, 10));
            $sitemap->addChild('changefreq', 'weekly');
        }
        $products = Db::getInstance()->ExecuteS('
		SELECT p.id_product, pl.link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, pl.id_lang, cl.`link_rewrite` AS category, ean13, (
			SELECT MIN(level_depth)
			FROM ' . _DB_PREFIX_ . 'product p2
			LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp2 ON p2.id_product = cp2.id_product
			LEFT JOIN ' . _DB_PREFIX_ . 'category c2 ON cp2.id_category = c2.id_category
			WHERE p2.id_product = p.id_product AND p2.`active` = 1 AND c2.`active` = 1) AS level_depth
		FROM ' . _DB_PREFIX_ . 'product p
		LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND pl.`id_lang` = cl.`id_lang`)
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON pl.id_lang = l.id_lang
		WHERE l.`active` = 1 AND p.`active` = 1
		ORDER BY pl.id_product, pl.id_lang ASC');
        foreach ($products as $product) {
            if (($priority = 0.7 - $product['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $sitemap = $xml->addChild('url');
            $tmpLink = $link->getProductLink($product['id_product'], $product['link_rewrite'], $product['category'], $product['ean13']);
            $_GET = array('id_product' => $product['id_product']);
            if ($product['id_lang'] != $defaultLanguage) {
                $_SERVER['REQUEST_URI'] = substr($tmpLink, strpos($tmpLink, __PS_BASE_URI__));
                $_SERVER['SCRIPT_NAME'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
                $link = new Link();
                $tmpLink = $link->getLanguageLink(intval($product['id_lang']));
                $tmpLink = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . $tmpLink;
            }
            $sitemap->addChild('loc', htmlspecialchars($tmpLink));
            $sitemap->addChild('priority', $priority);
            $sitemap->addChild('lastmod', substr($product['date_upd'], 0, 10));
            $sitemap->addChild('changefreq', 'weekly');
        }
        $images = Db::getInstance()->ExecuteS('
		SELECT *
		FROM ' . _DB_PREFIX_ . 'product p
		LEFT JOIN ' . _DB_PREFIX_ . 'image i ON p.id_product = i.id_product
		LEFT JOIN ' . _DB_PREFIX_ . 'image_lang il ON i.id_image = il.id_image AND il.id_lang = ' . intval($defaultLanguage) . '
		WHERE p.`active` = 1
		ORDER BY p.id_product');
        foreach ($images as $image) {
            $sitemap = $xml->addChild('url');
            $tmpLink = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . $link->getImageLink(Tools::link_rewrite($image['legend']), $image['id_product'] . '-' . $image['id_image']);
            $sitemap->addChild('loc', htmlspecialchars($tmpLink));
            $sitemap->addChild('priority', 0.4);
            $sitemap->addChild('lastmod', substr($image['date_upd'], 0, 10));
            $sitemap->addChild('changefreq', 'monthly');
        }
        $xmlString = $xml->asXML();
        $fp = fopen(GSITEMAP_FILE, 'w');
        fwrite($fp, $xmlString, Tools::strlen($xmlString));
        fclose($fp);
        $res = file_exists(GSITEMAP_FILE);
        $this->_html .= '<h3 class="' . ($res ? 'conf confirm' : 'alert error') . '" style="margin-bottom: 20px">';
        $this->_html .= $res ? $this->l('Sitemap file successfully generated') : $this->l('Error while creating sitemap file');
        $this->_html .= '</h3>';
        $_SERVER['REQUEST_URI'] = $ruBackup;
        $_SERVER['SCRIPT_NAME'] = $snBackup;
        $_GET = $getBackup;
    }
예제 #8
0
    private function _postProcess()
    {
        Configuration::updateValue('GSITEMAP_ALL_CMS', intval(Tools::getValue('GSITEMAP_ALL_CMS')));
        Configuration::updateValue('GSITEMAP_ALL_PRODUCTS', intval(Tools::getValue('GSITEMAP_ALL_PRODUCTS')));
        $link = new Link();
        $xmlString = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
</urlset>
XML;
        $xml = new SimpleXMLElement($xmlString);
        $this->_addSitemapNode($xml, 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__, '1.00', 'daily', date('Y-m-d'));
        if (Configuration::get('GSITEMAP_ALL_CMS')) {
            $sql_cms = '
			SELECT DISTINCT cl.id_cms, cl.link_rewrite, cl.id_lang
			FROM ' . _DB_PREFIX_ . 'cms_lang cl
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (cl.id_lang = l.id_lang)
			WHERE l.`active` = 1
			ORDER BY cl.id_cms, cl.id_lang ASC';
        } else {
            $sql_cms = '
			SELECT DISTINCT b.id_cms, cl.link_rewrite, cl.id_lang
			FROM ' . _DB_PREFIX_ . 'block_cms b
			LEFT JOIN ' . _DB_PREFIX_ . 'cms_lang cl ON (b.id_cms = cl.id_cms)
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON (cl.id_lang = l.id_lang)
			WHERE l.`active` = 1
			ORDER BY cl.id_cms, cl.id_lang ASC';
        }
        $cmss = Db::getInstance()->ExecuteS($sql_cms);
        foreach ($cmss as $cms) {
            $this->_addSitemapNode($xml, $link->getCMSLink(intval($cms['id_cms']), $cms['link_rewrite'], intval($cms['id_lang'])), '0.8', 'daily');
        }
        $categories = Db::getInstance()->ExecuteS('
		SELECT c.id_category, c.level_depth, link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, cl.id_lang
		FROM ' . _DB_PREFIX_ . 'category c
		LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON c.id_category = cl.id_category
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON cl.id_lang = l.id_lang
		WHERE l.`active` = 1 AND c.`active` = 1 AND c.id_category != 1
		ORDER BY cl.id_category, cl.id_lang ASC');
        foreach ($categories as $category) {
            if (($priority = 0.9 - $category['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $tmpLink = $link->getCategoryLink(intval($category['id_category']), $category['link_rewrite'], intval($category['id_lang']));
            $this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($category['date_upd'], 0, 10));
        }
        $products = Db::getInstance()->ExecuteS('
		SELECT p.id_product, pl.link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, pl.id_lang, cl.`link_rewrite` AS category, ean13, (
			SELECT MIN(level_depth)
			FROM ' . _DB_PREFIX_ . 'product p2
			LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp2 ON p2.id_product = cp2.id_product
			LEFT JOIN ' . _DB_PREFIX_ . 'category c2 ON cp2.id_category = c2.id_category
			WHERE p2.id_product = p.id_product AND p2.`active` = 1 AND c2.`active` = 1) AS level_depth
		FROM ' . _DB_PREFIX_ . 'product p
		LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND pl.`id_lang` = cl.`id_lang`)
		LEFT JOIN ' . _DB_PREFIX_ . 'lang l ON pl.id_lang = l.id_lang
		WHERE l.`active` = 1 AND p.`active` = 1
		' . (Configuration::get('GSITEMAP_ALL_PRODUCTS') ? '' : 'HAVING level_depth IS NOT NULL') . '
		ORDER BY pl.id_product, pl.id_lang ASC');
        foreach ($products as $product) {
            if (($priority = 0.7 - $product['level_depth'] / 10) < 0.1) {
                $priority = 0.1;
            }
            $tmpLink = $link->getProductLink(intval($product['id_product']), $product['link_rewrite'], $product['category'], $product['ean13'], intval($product['id_lang']));
            $this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($product['date_upd'], 0, 10));
        }
        /* Add classic pages (contact, best sales, new products...) */
        $pages = array('authentication', 'best-sales', 'category', 'contact-form', 'discount', 'index', 'manufacturer', 'new-products', 'prices-drop', 'search', 'supplier');
        foreach ($pages as $page) {
            $this->_addSitemapNode($xml, htmlspecialchars('http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__ . $page . '.php'), '0.5', 'monthly');
        }
        $xmlString = $xml->asXML();
        $fp = fopen(GSITEMAP_FILE, 'w');
        fwrite($fp, $xmlString);
        fclose($fp);
        $res = file_exists(GSITEMAP_FILE);
        $this->_html .= '<h3 class="' . ($res ? 'conf confirm' : 'alert error') . '" style="margin-bottom: 20px">';
        $this->_html .= $res ? $this->l('Sitemap file successfully generated') : $this->l('Error while creating sitemap file');
        $this->_html .= '</h3>';
    }
예제 #9
0
 /**
  * Builds a category page url for the language and shop.
  *
  * We created our own method due to the existing one in `LinkCore` behaving differently across PS versions.
  *
  * @param Category|CategoryCore $category the category model.
  * @param int|null $id_lang the language ID (falls back on current context if not set).
  * @param int|null $id_shop the shop ID (falls back on current context if not set).
  * @param array $params additional params to add to the url.
  * @return string the category page url.
  */
 public function getCategoryUrl($category, $id_lang = null, $id_shop = null, array $params = array())
 {
     if (is_null($id_lang)) {
         $id_lang = (int) Context::getContext()->language->id;
     }
     if (is_null($id_shop)) {
         $id_shop = (int) Context::getContext()->shop->id;
     }
     if (version_compare(_PS_VERSION_, '1.5.0.0') === -1 || version_compare(_PS_VERSION_, '1.5.5.0') >= 0) {
         /** @var LinkCore $link */
         $link = new Link();
         $url = $link->getCategoryLink($category, null, $id_lang, null, $id_shop);
     } else {
         // For PS versions 1.5.0.0 - 1.5.4.1 we always hard-code the urls to be in non-friendly format and fetch
         // the shops base url ourselves. This is a workaround to all the bugs related to url building in these
         // PS versions.
         $query_params = array('id_category' => (int) $category->id, 'controller' => 'category', 'id_lang' => $id_lang);
         $url = $this->getBaseUrl($id_shop) . 'index.php?' . http_build_query($query_params);
     }
     if ((int) Configuration::get('PS_REWRITING_SETTINGS') === 0) {
         $params['id_lang'] = $id_lang;
     }
     return NostoHttpRequest::replaceQueryParamsInUrl($params, $url);
 }
예제 #10
0
    public function getFilterBlock($selectedFilters = array())
    {
        global $cookie;
        static $cache = null;
        $whereLikeFilter = $this->getSelectedFiltersByQ();
        if (!$whereLikeFilter or $whereLikeFilter == '' or $whereLikeFilter == 0) {
            $whereLikeFilter = $_SESSION['search_q'];
        }
        $whereLikeFilter = str_replace("+", " ", $whereLikeFilter);
        if (is_array($cache)) {
            return $cache;
        }
        $id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', 1));
        if ($id_parent == 1) {
            return;
        }
        if ($id_parent != 4012) {
            $whereLikeFilter = '';
        }
        if ($id_parent == 4017) {
            $usado = true;
        }
        $parent = new Category((int) $id_parent);
        $descrypt_reg = "";
        //echo var_dump($tmp_lett);
        $wLikeArr = explode(" ", ltrim(rtrim($whereLikeFilter)));
        if ($wLikeArr[0] != "") {
            $descrypt_reg = ' pl.description REGEXP "[[:<:]]' . $wLikeArr[0] . '[[:>:]]" ';
            if ($wLikeArr[1] != "") {
                $descrypt_reg .= ' AND pl.description REGEXP "[[:<:]]' . $wLikeArr[1] . '[[:>:]]" ';
            }
            if ($wLikeArr[2] != "") {
                $descrypt_reg .= ' AND pl.description REGEXP "[[:<:]]' . $wLikeArr[2] . '[[:>:]]" ';
            }
            if ($wLikeArr[3] != "") {
                $descrypt_reg .= ' AND pl.description REGEXP "[[:<:]]' . $wLikeArr[3] . '[[:>:]]" ';
            }
        }
        /* Get the filters for the current category */
        $filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM ' . _DB_PREFIX_ . 'layered_category WHERE id_category = ' . (int) $id_parent . '
		GROUP BY `type`, id_value ORDER BY position ASC');
        // Remove all empty selected filters
        foreach ($selectedFilters as $key => $value) {
            switch ($key) {
                case 'price':
                case 'weight':
                    if ($value[0] == '' && $value[1] == '' || $value[0] == 0 && $value[1] == 0) {
                        unset($selectedFilters[$key]);
                    }
                    break;
                default:
                    if ($value == '') {
                        unset($selectedFilters[$key]);
                    }
                    break;
            }
        }
        $filterBlocks = array();
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT level_depth
		FROM `' . _DB_PREFIX_ . 'category` agl
		WHERE id_category = ' . $id_parent) as $catlevl) {
            $level_depth = $catlevl['level_depth'];
        }
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT id_category
		FROM `' . _DB_PREFIX_ . 'category` 
		WHERE id_parent = ' . $id_parent) as $cat2) {
            $catg2do[] = $cat2['id_category'];
        }
        $catg2do_filter = array();
        $catg2do_filter_none = array();
        foreach ($catg2do as $ctg2) {
            foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
                    SELECT id_category
                    FROM `' . _DB_PREFIX_ . 'category` 
                    WHERE id_parent = ' . $ctg2) as $cat22) {
                $catg2do_filter[] = $cat22['id_category'];
                $catg2do_filter_none[] = 0;
            }
            $catg2do_filter[] = $ctg2;
        }
        $catg2do = $catg2do_filter;
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT distinct cc.id_category,cl.name,id_parent
		FROM `' . _DB_PREFIX_ . 'category` cc inner join ' . _DB_PREFIX_ . 'category_lang cl on cc.id_category=cl.id_category 
		WHERE cc.id_parent in (' . implode(",", $catg2do) . ')') as $cat3) {
            $catg3do[] = $cat3['id_category'];
            foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
                    SELECT distinct cc.id_category,cl.name
                    FROM `' . _DB_PREFIX_ . 'category` cc inner join ' . _DB_PREFIX_ . 'category_lang cl on cc.id_category=cl.id_category 
                    WHERE cc.id_category="' . $cat3['id_parent'] . '"') as $cat33) {
                $catg3do_dat['name'][$cat3['id_category']] = $cat33['name'];
                $catg3do_dat['id_category'][$cat3['id_category']] = $cat33['id_category'];
            }
        }
        foreach ($filters as $filter) {
            $sqlQuery = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '');
            switch ($filter['type']) {
                // conditions + quantities + weight + price
                case 'price':
                case 'weight':
                case 'condition':
                case 'quantity':
                    if ($whereLikeFilter != '') {
                        $sqlQuery['select'] = '
					SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight`
					';
                        $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'product p ';
                        $sqlQuery['join'] = '
					INNER JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = p.id_product)
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category ) 
                                        LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product)  
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category
                                        ';
                        $sqlQuery['where'] = 'WHERE p.`active` = 1 and (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
)  ';
                        $sqlQuery['group'] = ' GROUP BY p.id_product ';
                    } else {
                        if ($usado == true) {
                            $sqlQuery['select'] = '
                                            SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight`
                                            ';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'product p ';
                            $sqlQuery['join'] = '
                                            INNER JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = p.id_product)
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category) 

                                            ';
                            $sqlQuery['where'] = 'WHERE p.`active` = 1 and p.condition="used"';
                            $sqlQuery['group'] = ' GROUP BY p.id_product ';
                        } else {
                            $sqlQuery['select'] = '
                                            SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight`
                                            ';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'product p ';
                            $sqlQuery['join'] = '
                                            INNER JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = p.id_product)
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND c.nleft >= ' . (int) $parent->nleft . ' AND c.nright <= ' . (int) $parent->nright . ') 

                                            ';
                            $sqlQuery['where'] = 'WHERE p.`active` = 1 ';
                            $sqlQuery['group'] = ' GROUP BY p.id_product ';
                        }
                    }
                    break;
                case 'manufacturer':
                    if ($whereLikeFilter != '') {
                        $sqlQuery['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer ';
                        $sqlQuery['from'] = '
					FROM `' . _DB_PREFIX_ . 'category_product` cp
					INNER JOIN  `' . _DB_PREFIX_ . 'category` c ON (c.id_category = cp.id_category)
					INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1)
					INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
                                        LEFT JOIN ps_product_lang pl ON (pl.id_product = p.id_product)   
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category    
';
                        $sqlQuery['where'] = '
					WHERE (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
) ';
                        $sqlQuery['group'] = ' GROUP BY p.id_manufacturer order by m.name asc ';
                    } else {
                        if ($usado == true) {
                            $sqlQuery['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer ';
                            $sqlQuery['from'] = '
                                            FROM `' . _DB_PREFIX_ . 'category_product` cp
                                            INNER JOIN  `' . _DB_PREFIX_ . 'category` c ON (c.id_category = cp.id_category)
                                            INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1)
                                            INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) ';
                            $sqlQuery['where'] = '
                                            WHERE  p.condition="used" ';
                            $sqlQuery['group'] = ' GROUP BY p.id_manufacturer  order by m.name asc ';
                        } else {
                            $sqlQuery['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer ';
                            $sqlQuery['from'] = '
                                            FROM `' . _DB_PREFIX_ . 'category_product` cp
                                            INNER JOIN  `' . _DB_PREFIX_ . 'category` c ON (c.id_category = cp.id_category)
                                            INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1)
                                            INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) ';
                            $sqlQuery['where'] = '
                                            WHERE c.nleft >= ' . (int) $parent->nleft . ' AND c.nright <= ' . (int) $parent->nright . ' ';
                            $sqlQuery['group'] = ' GROUP BY p.id_manufacturer  order by m.name asc ';
                        }
                    }
                    break;
                case 'id_attribute_group':
                    // attribute group
                    if ($whereLikeFilter != '') {
                        $sqlQuery['select'] = '
					SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
					a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,
					liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title';
                        $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'layered_product_attribute lpa
					INNER JOIN ' . _DB_PREFIX_ . 'attribute a
					ON a.id_attribute = lpa.id_attribute
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al
					ON al.id_attribute = a.id_attribute
					AND al.id_lang = ' . (int) $cookie->id_lang . '
					INNER JOIN ' . _DB_PREFIX_ . 'product as p
					ON p.id_product = lpa.id_product
					AND p.active = 1
                                        LEFT JOIN ps_product_lang pl ON (pl.id_product = p.id_product)
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_group ag
					ON ag.id_attribute_group = lpa.id_attribute_group
					INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl
					ON agl.id_attribute_group = lpa.id_attribute_group
					AND agl.id_lang = ' . (int) $cookie->id_lang . '
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value liagl
					ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value lial
					ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = ' . (int) $cookie->id_lang . ') ';
                        $sqlQuery['where'] = 'WHERE a.id_attribute_group = ' . (int) $filter['id_value'] . '
					AND (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
)  AND p.id_product IN (
					SELECT id_product
					FROM ' . _DB_PREFIX_ . 'category_product cp
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category)) ';
                        $sqlQuery['group'] = '
					GROUP BY lpa.id_attribute
					ORDER BY id_attribute_group, id_attribute ';
                    } else {
                        if ($usado == true) {
                            $sqlQuery['select'] = '
                                            SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
                                            a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,
                                            liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'layered_product_attribute lpa
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute a
                                            ON a.id_attribute = lpa.id_attribute
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al
                                            ON al.id_attribute = a.id_attribute
                                            AND al.id_lang = ' . (int) $cookie->id_lang . '
                                            INNER JOIN ' . _DB_PREFIX_ . 'product as p
                                            ON p.id_product = lpa.id_product
                                            AND p.active = 1
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_group ag
                                            ON ag.id_attribute_group = lpa.id_attribute_group
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl
                                            ON agl.id_attribute_group = lpa.id_attribute_group
                                            AND agl.id_lang = ' . (int) $cookie->id_lang . '
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value liagl
                                            ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value lial
                                            ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = ' . (int) $cookie->id_lang . ') ';
                            $sqlQuery['where'] = 'WHERE a.id_attribute_group = ' . (int) $filter['id_value'] . ' and p.condition="used" 
                                            AND p.id_product IN (
                                            SELECT id_product
                                            FROM ' . _DB_PREFIX_ . 'category_product cp
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category )) ';
                            $sqlQuery['group'] = '
                                            GROUP BY lpa.id_attribute
                                            ORDER BY id_attribute_group, id_attribute ';
                        } else {
                            $sqlQuery['select'] = '
                                            SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
                                            a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,
                                            liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'layered_product_attribute lpa
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute a
                                            ON a.id_attribute = lpa.id_attribute
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al
                                            ON al.id_attribute = a.id_attribute
                                            AND al.id_lang = ' . (int) $cookie->id_lang . '
                                            INNER JOIN ' . _DB_PREFIX_ . 'product as p
                                            ON p.id_product = lpa.id_product
                                            AND p.active = 1
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_group ag
                                            ON ag.id_attribute_group = lpa.id_attribute_group
                                            INNER JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl
                                            ON agl.id_attribute_group = lpa.id_attribute_group
                                            AND agl.id_lang = ' . (int) $cookie->id_lang . '
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value liagl
                                            ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value lial
                                            ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = ' . (int) $cookie->id_lang . ') ';
                            $sqlQuery['where'] = 'WHERE a.id_attribute_group = ' . (int) $filter['id_value'] . '
                                            AND p.id_product IN (
                                            SELECT id_product
                                            FROM ' . _DB_PREFIX_ . 'category_product cp
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND c.nleft >= ' . (int) $parent->nleft . ' AND c.nright <= ' . (int) $parent->nright . ')) ';
                            $sqlQuery['group'] = '
                                            GROUP BY lpa.id_attribute
                                            ORDER BY id_attribute_group, id_attribute ';
                        }
                    }
                    break;
                case 'id_feature':
                    if ($whereLikeFilter != '') {
                        $sqlQuery['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
					COUNT(DISTINCT p.id_product) nbr,
					lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title ';
                        $sqlQuery['from'] = '
					FROM ' . _DB_PREFIX_ . 'feature_product fp
					INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = fp.id_product AND p.active = 1)
                                        LEFT JOIN ps_product_lang pl ON (pl.id_product = p.id_product) 
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category
					LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = ' . (int) $cookie->id_lang . ')
					INNER JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
					LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value lifl
					ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = ' . (int) $cookie->id_lang . ')
					LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value lifvl
					ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = ' . (int) $cookie->id_lang . ') ';
                        $sqlQuery['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = ' . (int) $filter['id_value'] . '
					AND (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
)  AND p.id_product IN (
					SELECT id_product
					FROM ' . _DB_PREFIX_ . 'category_product cp
					INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category)) ';
                        $sqlQuery['group'] = 'GROUP BY fv.id_feature_value order by CAST(fvl.value as UNSIGNED) asc,fvl.value asc';
                    } else {
                        if ($usado == true) {
                            $sqlQuery['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
                                            COUNT(DISTINCT p.id_product) nbr,
                                            lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title ';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'feature_product fp
                                            INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = fp.id_product AND p.active = 1)
                                            LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = ' . (int) $cookie->id_lang . ')
                                            INNER JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
                                            LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value lifl
                                            ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value lifvl
                                            ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = ' . (int) $cookie->id_lang . ') ';
                            $sqlQuery['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = ' . (int) $filter['id_value'] . ' and p.condition="used" 
                                            AND p.id_product IN (
                                            SELECT id_product
                                            FROM ' . _DB_PREFIX_ . 'category_product cp
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category )) ';
                            $sqlQuery['group'] = 'GROUP BY fv.id_feature_value order by CAST(fvl.value as UNSIGNED) asc,fvl.value asc';
                        } else {
                            $sqlQuery['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
                                            COUNT(DISTINCT p.id_product) nbr,
                                            lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title ';
                            $sqlQuery['from'] = '
                                            FROM ' . _DB_PREFIX_ . 'feature_product fp
                                            INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = fp.id_product AND p.active = 1)
                                            LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = ' . (int) $cookie->id_lang . ')
                                            INNER JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
                                            LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value lifl
                                            ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = ' . (int) $cookie->id_lang . ')
                                            LEFT JOIN ' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value lifvl
                                            ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = ' . (int) $cookie->id_lang . ') ';
                            $sqlQuery['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = ' . (int) $filter['id_value'] . '
                                            AND p.id_product IN (
                                            SELECT id_product
                                            FROM ' . _DB_PREFIX_ . 'category_product cp
                                            INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND c.nleft >= ' . (int) $parent->nleft . ' AND c.nright <= ' . (int) $parent->nright . ')) ';
                            $sqlQuery['group'] = 'GROUP BY fv.id_feature_value order by CAST(fvl.value as UNSIGNED) asc,fvl.value asc';
                        }
                    }
                    break;
                case 'category':
                    //$level_depth
                    if ($whereLikeFilter != '') {
                        $sqlQuery['select'] = ' SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # ';
                        $sqlQuery['from'] = 'FROM ' . _DB_PREFIX_ . 'category_product cp
					LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) 
                                        LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product)
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category
';
                        $sqlQuery['where'] = ' WHERE cp.id_category = c.id_category and (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
)  ';
                        $sqlQuery['group'] = ') count_products
					FROM ' . _DB_PREFIX_ . 'category c
					LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
					WHERE (SELECT count(DISTINCT p.id_product) cont FROM ' . _DB_PREFIX_ . 'category_product cp 
                                            LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) 
                                            LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product) 
                                            WHERE cp.id_category = c.id_category and (
(
' . $descrypt_reg . '
) 
OR 
(p.id_product ="' . $whereLikeFilter . '" OR p.reference = "' . $whereLikeFilter . '") 
OR
(cl.name REGEXP "[[:<:]]' . $whereLikeFilter . '[[:>:]]")
)   )>=1
					GROUP BY cl.name ORDER BY count_products desc,level_depth, c.position';
                    } else {
                        if ($usado == true) {
                            $sqlQuery['select'] = ' SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # ';
                            $sqlQuery['from'] = 'FROM ' . _DB_PREFIX_ . 'category_product cp
					LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) 
                                        LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product)
                                        LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON p.`id_category_default` = cl.id_category
';
                            $sqlQuery['where'] = ' WHERE cp.id_category = c.id_category and (p.condition="used")   ';
                            $sqlQuery['group'] = ') count_products
					FROM ' . _DB_PREFIX_ . 'category c
					LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
					WHERE (SELECT count(DISTINCT p.id_product) cont FROM ' . _DB_PREFIX_ . 'category_product cp 
                                            LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) 
                                            LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product) 
                                            WHERE cp.id_category = c.id_category and p.condition="used"    )>=1
					GROUP BY cl.name ORDER BY level_depth, c.position';
                        } else {
                            if ($level_depth < 3 and count($catg3do) > 0) {
                                $sqlQuery['select'] = '
                                                SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # ';
                                $sqlQuery['from'] = '
                                                FROM ' . _DB_PREFIX_ . 'category_product cp
                                                LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) ';
                                $sqlQuery['where'] = '
                                                WHERE cp.id_category = c.id_category ';
                                $sqlQuery['group'] = ') count_products
                                                FROM ' . _DB_PREFIX_ . 'category c
                                                LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
                                                WHERE   (c.id_category in (' . implode(",", $catg3do) . ') or c.id_parent=' . $id_parent . ' )
                                                GROUP BY c.id_category HAVING count_products>0 ORDER BY c.id_parent,cl.name,c.id_category,level_depth, c.position';
                            } else {
                                $sqlQuery['select'] = '
                                                SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # ';
                                $sqlQuery['from'] = '
                                                FROM ' . _DB_PREFIX_ . 'category_product cp
                                                LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = cp.id_product AND p.active = 1) ';
                                $sqlQuery['where'] = '
                                                WHERE cp.id_category = c.id_category ';
                                $sqlQuery['group'] = ') count_products
                                                FROM ' . _DB_PREFIX_ . 'category c
                                                LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = ' . (int) $cookie->id_lang . ')
                                                WHERE c.id_parent = ' . (int) $id_parent . ' 
                                                GROUP BY c.id_category ORDER BY level_depth, c.position';
                            }
                        }
                    }
            }
            foreach ($filters as $filterTmp) {
                $methodName = 'get' . ucfirst($filterTmp['type']) . 'FilterSubQuery';
                if (method_exists('BlockLayered', $methodName) && (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) {
                    if ($filter['type'] == $filterTmp['type'] && $filter['id_value'] == $filterTmp['id_value']) {
                        $subQueryFilter = self::$methodName(array(), true);
                    } else {
                        if (!is_null($filterTmp['id_value'])) {
                            $selected_filters_cleaned = $this->cleanFilterByIdValue(@$selectedFilters[$filterTmp['type']], $filterTmp['id_value']);
                        } else {
                            $selected_filters_cleaned = @$selectedFilters[$filterTmp['type']];
                        }
                        $subQueryFilter = self::$methodName($selected_filters_cleaned, $filter['type'] == $filterTmp['type']);
                    }
                    if ($filter['type'] != "category") {
                        foreach ($subQueryFilter as $key => $value) {
                            $sqlQuery[$key] .= $value;
                        }
                    }
                }
            }
            $products = false;
            if (!empty($sqlQuery['from'])) {
                $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sqlQuery['select'] . "\n" . $sqlQuery['from'] . "\n" . $sqlQuery['join'] . "\n" . $sqlQuery['where'] . "\n" . $sqlQuery['group']);
            }
            foreach ($filters as $filterTmp) {
                $methodName = 'filterProductsBy' . ucfirst($filterTmp['type']);
                if (method_exists('BlockLayered', $methodName) && (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) {
                    if ($filter['type'] == $filterTmp['type']) {
                        $products = self::$methodName(array(), $products);
                    } else {
                        $products = self::$methodName(@$selectedFilters[$filterTmp['type']], $products);
                    }
                }
            }
            switch ($filter['type']) {
                case 'price':
                    $priceArray = array('type_lite' => 'price', 'type' => 'price', 'id_key' => 0, 'name' => $this->l('Price'), 'slider' => true, 'max' => '0', 'min' => null, 'values' => array('1' => 0), 'unit' => Currency::getCurrent()->sign);
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (is_null($priceArray['min'])) {
                                $priceArray['min'] = $product['price_min'];
                                $priceArray['values'][0] = $product['price_min'];
                            } else {
                                if ($priceArray['min'] > $product['price_min']) {
                                    $priceArray['min'] = $product['price_min'];
                                    $priceArray['values'][0] = $product['price_min'];
                                }
                            }
                            if ($priceArray['max'] < $product['price_max']) {
                                $priceArray['max'] = $product['price_max'];
                                $priceArray['values'][1] = $product['price_max'];
                            }
                        }
                    }
                    if ($priceArray['max'] != $priceArray['min'] && $priceArray['min'] != null) {
                        if (isset($selectedFilters['price']) && isset($selectedFilters['price'][0]) && isset($selectedFilters['price'][1])) {
                            $priceArray['values'][0] = $selectedFilters['price'][0];
                            $priceArray['values'][1] = $selectedFilters['price'][1];
                        }
                        $filterBlocks[] = $priceArray;
                    }
                    break;
                case 'weight':
                    $weightArray = array('type_lite' => 'weight', 'type' => 'weight', 'id_key' => 0, 'name' => $this->l('Weight'), 'slider' => true, 'max' => '0', 'min' => null, 'values' => array('1' => 0), 'unit' => Configuration::get('PS_WEIGHT_UNIT'));
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (is_null($weightArray['min'])) {
                                $weightArray['min'] = $product['weight'];
                                $weightArray['values'][0] = $product['weight'];
                            } else {
                                if ($weightArray['min'] > $product['weight']) {
                                    $weightArray['min'] = $product['weight'];
                                    $weightArray['values'][0] = $product['weight'];
                                }
                            }
                            if ($weightArray['max'] < $product['weight']) {
                                $weightArray['max'] = $product['weight'];
                                $weightArray['values'][1] = $product['weight'];
                            }
                        }
                    }
                    if ($weightArray['max'] != $weightArray['min'] && $weightArray['min'] != null) {
                        if (isset($selectedFilters['weight']) && isset($selectedFilters['weight'][0]) && isset($selectedFilters['weight'][1])) {
                            $weightArray['values'][0] = $selectedFilters['weight'][0];
                            $weightArray['values'][1] = $selectedFilters['weight'][1];
                        }
                        $filterBlocks[] = $weightArray;
                    }
                    break;
                case 'condition':
                    $conditionArray = array('new' => array('name' => $this->l('New'), 'nbr' => 0), 'used' => array('name' => $this->l('Used'), 'nbr' => 0), 'refurbished' => array('name' => $this->l('Refurbished'), 'nbr' => 0));
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (isset($selectedFilters['condition']) && in_array($product['condition'], $selectedFilters['condition'])) {
                                $conditionArray[$product['condition']]['checked'] = true;
                            }
                        }
                    }
                    foreach ($conditionArray as $key => $condition) {
                        if (isset($selectedFilters['condition']) && in_array($key, $selectedFilters['condition'])) {
                            $conditionArray[$key]['checked'] = true;
                        }
                    }
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            if (isset($conditionArray[$product['condition']])) {
                                $conditionArray[$product['condition']]['nbr']++;
                            }
                        }
                    }
                    $filterBlocks[] = array('type_lite' => 'condition', 'type' => 'condition', 'id_key' => 0, 'name' => $this->l('Condition'), 'values' => $conditionArray);
                    break;
                case 'quantity':
                    $quantityArray = array(0 => array('name' => $this->l('Not available'), 'nbr' => 0), 1 => array('name' => $this->l('In stock'), 'nbr' => 0));
                    foreach ($quantityArray as $key => $quantity) {
                        if (isset($selectedFilters['quantity']) && in_array($key, $selectedFilters['quantity'])) {
                            $quantityArray[$key]['checked'] = true;
                        }
                    }
                    if (isset($products) && $products) {
                        foreach ($products as $product) {
                            $quantityArray[(int) ($product['quantity'] > 0)]['nbr']++;
                        }
                    }
                    $filterBlocks[] = array('type_lite' => 'quantity', 'type' => 'quantity', 'id_key' => 0, 'name' => $this->l('Availability'), 'values' => $quantityArray);
                    break;
                case 'manufacturer':
                    if (isset($products) && $products) {
                        $manufaturersArray = array();
                        foreach ($products as $manufacturer) {
                            $manufaturersArray[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']);
                            if (isset($selectedFilters['manufacturer']) && in_array((int) $manufacturer['id_manufacturer'], $selectedFilters['manufacturer'])) {
                                $manufaturersArray[$manufacturer['id_manufacturer']]['checked'] = true;
                            }
                        }
                        $filterBlocks[] = array('type_lite' => 'manufacturer', 'type' => 'manufacturer', 'id_key' => 0, 'name' => $this->l('Manufacturer'), 'values' => $manufaturersArray);
                    }
                    break;
                case 'id_attribute_group':
                    $attributesArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $attributes) {
                            if (!isset($attributesArray[$attributes['id_attribute_group']])) {
                                $attributesArray[$attributes['id_attribute_group']] = array('type_lite' => 'id_attribute_group', 'type' => 'id_attribute_group', 'id_key' => (int) $attributes['id_attribute_group'], 'name' => $attributes['attribute_group_name'], 'is_color_group' => (bool) $attributes['is_color_group'], 'values' => array(), 'url_name' => $attributes['name_url_name'], 'meta_title' => $attributes['name_meta_title']);
                            }
                            $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array('color' => $attributes['color'], 'name' => $attributes['attribute_name'], 'nbr' => (int) $attributes['nbr'], 'url_name' => $attributes['value_url_name'], 'meta_title' => $attributes['value_meta_title']);
                            if (isset($selectedFilters['id_attribute_group'][$attributes['id_attribute']])) {
                                $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']]['checked'] = true;
                            }
                        }
                        $filterBlocks = array_merge($filterBlocks, $attributesArray);
                    }
                    break;
                case 'id_feature':
                    $featureArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $feature) {
                            if (!isset($featureArray[$feature['id_feature']])) {
                                $featureArray[$feature['id_feature']] = array('type_lite' => 'id_feature', 'type' => 'id_feature', 'id_key' => (int) $feature['id_feature'], 'values' => array(), 'name' => $feature['feature_name'], 'url_name' => $feature['name_url_name'], 'meta_title' => $feature['name_meta_title']);
                            }
                            $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']] = array('nbr' => (int) $feature['nbr'], 'name' => $feature['value'], 'url_name' => $feature['value_url_name'], 'meta_title' => $feature['value_meta_title']);
                            if (isset($selectedFilters['id_feature'][$feature['id_feature_value']])) {
                                $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']]['checked'] = true;
                            }
                        }
                        $filterBlocks = array_merge($filterBlocks, $featureArray);
                    }
                    break;
                case 'category':
                    $tmpArray = array();
                    if (isset($products) && $products) {
                        foreach ($products as $category) {
                            //mbj
                            $tmpArray[$category['id_category']] = array('name' => $category['name'], 'nbr' => (int) $category['count_products']);
                            if (isset($selectedFilters['category']) && in_array($category['id_category'], $selectedFilters['category'])) {
                                $tmpArray[$category['id_category']]['checked'] = true;
                            }
                        }
                        $filterBlocks[] = array('type_lite' => 'category', 'type' => 'category', 'id_key' => 0, 'name' => $this->l('Categories'), 'values' => $tmpArray);
                    }
                    break;
            }
        }
        // All non indexable attribute and feature
        $nonIndexable = array();
        // Get all non indexable attribute groups
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT public_name
		FROM `' . _DB_PREFIX_ . 'attribute_group_lang` agl
		LEFT JOIN `' . _DB_PREFIX_ . 'layered_indexable_attribute_group` liag
		ON liag.id_attribute_group = agl.id_attribute_group
		WHERE indexable IS NULL OR indexable = 0
		AND id_lang = ' . (int) $cookie->id_lang) as $attribute) {
            $nonIndexable[] = Tools::link_rewrite($attribute['public_name']);
        }
        // Get all non indexable features
        foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT name
		FROM `' . _DB_PREFIX_ . 'feature_lang` fl
		LEFT JOIN  `' . _DB_PREFIX_ . 'layered_indexable_feature` lif
		ON lif.id_feature = fl.id_feature
		WHERE indexable IS NULL OR indexable = 0
		AND id_lang = ' . (int) $cookie->id_lang) as $attribute) {
            $nonIndexable[] = Tools::link_rewrite($attribute['name']);
        }
        //generate SEO link
        $paramSelected = '';
        $optionCheckedArray = array();
        $paramGroupSelectedArray = array();
        $titleValues = array();
        $link = new Link();
        $linkBase = $link->getCategoryLink($id_parent, Category::getLinkRewrite($id_parent, (int) $cookie->id_lang), (int) $cookie->id_lang);
        $filterBlockList = array();
        //get filters checked by group
        foreach ($filterBlocks as $typeFilter) {
            $filterName = !empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name'];
            $paramGroupSelected = '';
            foreach ($typeFilter['values'] as $key => $value) {
                if (is_array($value) && array_key_exists('checked', $value)) {
                    $valueName = !empty($value['url_name']) ? $value['url_name'] : $value['name'];
                    $paramGroupSelected .= '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                    $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = Tools::link_rewrite($valueName);
                    if (!isset($titleValues[$filterName])) {
                        $titleValues[$filterName] = array();
                    }
                    $titleValues[$filterName][] = $valueName;
                } else {
                    $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = array();
                }
            }
            if (!empty($paramGroupSelected)) {
                $paramSelected .= '/' . str_replace('-', '_', Tools::link_rewrite($filterName)) . $paramGroupSelected;
                $optionCheckedArray[Tools::link_rewrite($filterName)] = $paramGroupSelected;
            }
        }
        $blackList = array('weight', 'price');
        $nofollow = false;
        foreach ($filterBlocks as &$typeFilter) {
            $filterName = !empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name'];
            if (count($typeFilter) > 0 && !in_array($typeFilter['type'], $blackList)) {
                foreach ($typeFilter['values'] as $key => $values) {
                    $nofollow = false;
                    $optionCheckedCloneArray = $optionCheckedArray;
                    //if not filters checked, add parameter
                    $valueName = !empty($values['url_name']) ? $values['url_name'] : $values['name'];
                    if (!in_array(Tools::link_rewrite($valueName), $paramGroupSelectedArray[Tools::link_rewrite($filterName)])) {
                        //update parameter filter checked before
                        if (array_key_exists(Tools::link_rewrite($filterName), $optionCheckedArray)) {
                            $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = $optionCheckedCloneArray[Tools::link_rewrite($filterName)] . '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                            $nofollow = true;
                        } else {
                            $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = '-' . str_replace('-', '_', Tools::link_rewrite($valueName));
                        }
                    } else {
                        // Remove selected parameters
                        $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = str_replace('-' . str_replace('-', '_', Tools::link_rewrite($valueName)), '', $optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
                        if (empty($optionCheckedCloneArray[Tools::link_rewrite($filterName)])) {
                            unset($optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
                        }
                    }
                    $parameters = '';
                    foreach ($optionCheckedCloneArray as $keyGroup => $valueGroup) {
                        $parameters .= '/' . str_replace('-', '_', $keyGroup) . $valueGroup;
                    }
                    // Check if there is an non indexable attribute or feature in the url
                    foreach ($nonIndexable as $value) {
                        if (strpos($parameters, '/' . $value) !== false) {
                            $nofollow = true;
                        }
                    }
                    //write link by mode rewriting
                    if (!Configuration::get('PS_REWRITING_SETTINGS')) {
                        $typeFilter['values'][$key]['link'] = $linkBase . '&selected_filters=' . $parameters;
                    } else {
                        $typeFilter['values'][$key]['link'] = $linkBase . $parameters;
                    }
                    $typeFilter['values'][$key]['rel'] = $nofollow ? 'nofollow' : '';
                }
            }
        }
        $nFilters = 0;
        if (isset($selectedFilters['price'])) {
            if ($priceArray['min'] == $selectedFilters['price'][0] && $priceArray['max'] == $selectedFilters['price'][1]) {
                unset($selectedFilters['price']);
            }
        }
        if (isset($selectedFilters['weight'])) {
            if ($weightArray['min'] == $selectedFilters['weight'][0] && $weightArray['max'] == $selectedFilters['weight'][1]) {
                unset($selectedFilters['weight']);
            }
        }
        foreach ($selectedFilters as $filters) {
            $nFilters += count($filters);
        }
        $cache = array('layered_show_qties' => (int) Configuration::get('PS_LAYERED_SHOW_QTIES'), 'id_category_layered' => (int) $id_parent, 'level_depth' => $level_depth, 'catg3do' => $catg3do_dat, 'selected_filters' => $selectedFilters, 'n_filters' => (int) $nFilters, 'nbr_filterBlocks' => count($filterBlocks), 'filters' => $filterBlocks, 'title_values' => $titleValues, 'current_friendly_url' => htmlentities($paramSelected), 'nofollow' => !empty($paramSelected) || $nofollow);
        return $cache;
    }
예제 #11
0
 /**
  * Mise à jour de l'objet cms pour remplacer les variables d'url des lien
  * @param string : contenu ou il faut remplacer les liens
  * @return string : contenu avec les liens remplacés
  */
 public static function updateCmsLinksDisplay($content = null)
 {
     //Inclusion de la classe des widgets
     include_once dirname(__FILE__) . '/classes/Widget.php';
     if ($content === null) {
         return;
     }
     //Dans prestashop 1.6 les caractères { et } sont encodés
     if (_PS_VERSION_ > '1.6') {
         $content = urldecode($content);
     }
     $link_model = new Link();
     //Mise à jour des liens vers les pages cms
     preg_match_all('#{{cms url=([0-9])}}#', $content, $cms_links);
     if (isset($cms_links[1]) && sizeof($cms_links[1])) {
         foreach ($cms_links[1] as $link) {
             $link_url = $link_model->getCMSLink($link);
             $content = preg_replace('#{{cms url=' . $link . '}}#', $link_url, $content);
         }
     }
     //Mise à jour des liens vers les pages categories
     preg_match_all('#{{category url=([0-9])}}#', $content, $category_links);
     if (isset($category_links[1]) && sizeof($category_links[1])) {
         foreach ($category_links[1] as $category_link) {
             $category_link_url = $link_model->getCategoryLink($category_link);
             $content = preg_replace('#{{category url=' . $category_link . '}}#', $category_link_url, $content);
         }
     }
     //Mise à jour des liens vers les pages produits
     preg_match_all('#{{product url=([0-9])}}#', $content, $product_links);
     if (isset($product_links[1]) && sizeof($product_links[1])) {
         foreach ($product_links[1] as $product_link) {
             $product_link_url = $link_model->getProductLink($product_link);
             $content = preg_replace('#{{product url=' . $product_link . '}}#', $product_link_url, $content);
         }
     }
     //Mise à jour des liens d'ajout au panier
     preg_match_all('#{{cart url=([0-9])}}#', $content, $product_links);
     if (isset($product_links[1]) && sizeof($product_links[1])) {
         foreach ($product_links[1] as $product_link) {
             $product_cart_url = sprintf('index.php?controller=cart&add=1&qty=1&id_product=%s&token=%s', $product_link, Tools::getToken());
             $content = preg_replace('#{{cart url=' . $product_link . '}}#', $product_cart_url, $content);
         }
     }
     //Gestion des widgets
     preg_match_all('#{{widget name="(.*)"(.*)}}#U', $content, $widgets);
     if (isset($widgets[1]) && sizeof($widgets[1])) {
         $i = 0;
         foreach ($widgets[1] as $widget) {
             $widget = trim($widget);
             if (is_file(dirname(__FILE__) . '/classes/' . $widget . '.php')) {
                 include_once dirname(__FILE__) . '/classes/' . $widget . '.php';
                 $widgetParams = $widgets[2][$i];
                 try {
                     $widgetObject = new $widget($widgetParams);
                     $widgetContent = $widgetObject->display();
                     $content = str_replace('{{widget name="' . $widget . '"' . $widgetParams . '}}', $widgetContent, $content);
                 } catch (PrestaShopExceptionCore $e) {
                     echo $e->getMessage();
                 }
             }
             $i++;
         }
     }
     return $content;
 }
예제 #12
0
 public function hookAjaxCall()
 {
     $all_categories = Category::getCategories($this->context->language->id, true, true, 'AND `c`.`hide_on_left` = \'0\'');
     $categories = blockcategories::createMenuCategories($all_categories, $_GET['id_category'], $_GET['level']);
     $link = new Link();
     foreach (array_keys($categories) as $index) {
         $categories[$index]['link'] = $link->getCategoryLink($categories[$index]['id_category']);
     }
     $this->context->smarty->assign('categories', $categories);
     $this->context->smarty->assign('level', $_GET['level']);
     return $this->display(__FILE__, 'blockcategories-ajax.tpl');
 }
예제 #13
0
 function frontGetModuleContents($module, $cacheKey = '')
 {
     if (!$this->isCached('pagelink.' . $module['layout'] . '.tpl', Tools::encrypt($cacheKey))) {
         $contents = array();
         $langId = $this->context->language->id;
         $shopId = $this->context->shop->id;
         $items = Db::getInstance()->executeS("Select r.*, rl.name, rl.link  \n\t\t\t\tFrom " . _DB_PREFIX_ . "pagelink_item AS r \n\t\t\t\tInner Join " . _DB_PREFIX_ . "pagelink_item_lang AS rl On r.id = rl.menuitem_id \n\t\t\t\tWhere r.parent_id = 0 AND r.module_id = " . $module['id'] . " AND r.status = 1 AND rl.id_lang = " . $langId . " Order By r.ordering");
         if ($items) {
             foreach ($items as &$item) {
                 $icon = $this->getImageSrc($item['icon'], true);
                 $item['icon_type'] = $icon->type;
                 $item['full_path'] = $icon->img;
                 if ($item['link_type'] == 'PAG-authentication') {
                     if ($this->context->customer->logged) {
                         $item['link'] = $this->context->link->getPageLink('index', true, NULL, "mylogout");
                         $item['name'] = $this->l('Sign out');
                         $item['custom_class'] = 'nav-logout';
                     } else {
                         $item['link'] = $this->frontGenerationUrl($item['link_type'], $item['link']);
                     }
                 } elseif ($item['link_type'] == 'PRODUCT-0') {
                     $item['link'] = $this->frontGenerationUrl('PRD-' . $item['product_id'], $item['link']);
                 } elseif ($item['link_type'] == 'CURRENCY-BOX') {
                     $item['currencies'] = array('name' => $this->context->currency->name, 'iso_code' => $this->context->currency->iso_code, 'sign' => $this->context->currency->sign);
                 } elseif ($item['link_type'] == 'LANGUAGE-BOX') {
                     $languages = Language::getLanguages(true, $this->context->shop->id);
                     if (count($languages) > 0) {
                         $link = new Link();
                         if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
                             $default_rewrite = array();
                             if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) {
                                 $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product);
                                 foreach ($rewrite_infos as $infos) {
                                     $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']);
                                 }
                             }
                             if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) {
                                 $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category);
                                 foreach ($rewrite_infos as $infos) {
                                     $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']);
                                 }
                             }
                             if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) {
                                 $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
                                 foreach ($rewrite_infos as $infos) {
                                     $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
                                     $default_rewrite[$infos['id_lang']] = $arr_link;
                                 }
                             }
                             $this->smarty->assign(array('lang_rewrite_urls' => $default_rewrite, 'lang_name' => $this->context->language->name, 'lang_iso_code' => $this->context->language->iso_code));
                         }
                     }
                 } else {
                     $item['link'] = $this->frontGenerationUrl($item['link_type'], $item['link']);
                 }
                 $item['submenus'] = $this->frontGetSubMenus($module['id'], $item['id']);
             }
         }
         $this->context->smarty->assign(array('module_layout' => $module['layout'], 'display_name' => $module['display_name'], 'custom_class' => $module['custom_class'], 'name' => $module['name'], 'menuContents' => $items));
     }
     return $this->display(__FILE__, 'pagelink.' . $module['layout'] . '.tpl', Tools::encrypt($cacheKey));
 }
예제 #14
0
 public function hookActionObjectUpdateAfter($params)
 {
     if (isset($params['object']) && !empty($params['object'])) {
         $object = $params['object'];
         $type = get_class($object);
         if (!in_array($type, array('Product', 'Manufacturer', 'Supplier', 'Category', 'CMS', 'CMSCategory'))) {
             // Ok not our job
             return;
         }
         $shops = $this->getShopsIds();
         $link = new Link();
         $redirect_list = array();
         // Incremental way, it's a bugfix, for supplier for example
         $shop_urls = array();
         $shop_urls[] = 'https:';
         $shop_urls[] = 'http:';
         foreach ($shops as $id_shop) {
             $shop = new ShopUrl($id_shop);
             $shop_urls[] = str_replace(array('http://', 'https://'), '', $shop->getURL(true));
             $shop_urls[] = str_replace(array('http://', 'https://'), '', $shop->getURL(false));
         }
         $shop_urls = array_unique($shop_urls);
         foreach ($shops as $id_shop) {
             // foreach langs, foreach shops ...
             $langs = Language::getLanguages(false, $id_shop, true);
             foreach ($langs as $id_lang) {
                 switch ($type) {
                     case 'Manufacturer':
                         $old_link = $link->getManufacturerLink($object, null, null, null, $id_lang, $id_shop);
                         break;
                     case 'Supplier':
                         $old_link = $link->getSupplierLink($object, null, null, null, $id_lang, $id_shop);
                         break;
                     case 'CMS':
                         $old_link = $link->getCMSLink($object, null, null, $id_lang, $id_shop);
                         break;
                     case 'Product':
                         $old_link = $link->getProductLink($object, null, null, null, $id_lang, $id_shop);
                         break;
                     case 'Category':
                         $old_link = $link->getCategoryLink($object, null, $id_lang, null, $id_shop);
                         break;
                     case 'CMSCategory':
                         $old_link = $link->getCMSCategoryLink($object, null, $id_lang, $id_shop);
                         break;
                     default:
                         // UFO
                         break;
                 }
                 // Escape shops urls, it's a multishop relative approach
                 $old = str_replace($shop_urls, '', $old_link);
                 $old = '/' . ltrim($old, '/');
                 // Avoid duplicates, simplify complex mapings
                 $md5 = md5($old);
                 if (!isset($redirect_list[$md5])) {
                     $redirect_list[$md5]['old'] = $old;
                     $redirect_list[$md5]['shops'][] = $id_shop;
                 } elseif (!in_array($id_shop, $redirect_list[$md5]['shops'])) {
                     $redirect_list[$md5]['shops'][] = $id_shop;
                 }
             }
         }
         if (!empty($redirect_list)) {
             foreach ($redirect_list as $redirect) {
                 foreach ($redirect['shops'] as $id_shop) {
                     $this->checkConflict($redirect['old'], $id_shop);
                 }
             }
         }
     }
 }
 public function postCategory($id, $title = '')
 {
     $mResult = false;
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         $link = Context::getContext()->link;
     } else {
         $link = new Link();
     }
     $category = new Category((int) $id, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
     if ($category && Validate::isLoadedObject($category) && $category->active) {
         // Image
         $image_link = $link->getCatImageLink($category->link_rewrite, (int) $id);
         /* Before version 1.4 */
         if (strpos($image_link, 'http://') === FALSE && strpos($image_link, 'https://') === FALSE) {
             $image_link = 'http://' . $_SERVER['HTTP_HOST'] . $image_link;
         }
         // URL
         $cat_url = $link->getCategoryLink($category);
         $mResult = $this->createFBPost($title, $category->name, $cat_url, strip_tags($category->description), $image_link);
     }
     return $mResult;
 }
예제 #16
0
 private function _getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_category = 0)
 {
     $link = new Link();
     $categories_id = Db::getInstance()->ExecuteS('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` WHERE `active` = 1 AND `id_category` != 1 AND `id_category` > ' . (int) $id_category . '  ORDER BY `id_category` ASC');
     foreach ($categories_id as $category_id) {
         $category = new Category((int) $category_id['id_category'], (int) $lang['id_lang']);
         if (_PS_VERSION_ >= 1.5) {
             $url = $link->getCategoryLink($category, null, null, null, (int) $lang['id_lang']);
         } else {
             $url = $link->getCategoryLink($category, $category->link_rewrite, (int) $lang['id_lang']);
         }
         if ($category->id_image) {
             $image_link = $this->context->link->getCatImageLink($category->link_rewrite, (int) $category->id_image, 'category_default');
         }
         $file_headers = @get_headers($image_link);
         if (isset($image_link) && $file_headers[0] != 'HTTP/1.1 404 Not Found') {
             if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'category', 'page' => 'category', 'link' => $image_link, 'image' => array('title_img' => Tools::safeOutput($category->name))), $lang['iso_code'], $index, $i, (int) $category_id['id_category'])) {
                 return false;
             }
         }
         if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'category', 'page' => 'category', 'link' => $url, 'image' => false), $lang['iso_code'], $index, $i, (int) $category_id['id_category'])) {
             return false;
         }
         unset($image_link);
     }
     return true;
 }