public function init()
 {
     global $smarty;
     parent::init();
     if (Module::isInstalled('agilesellerratings')) {
         include_once _PS_ROOT_DIR_ . "/modules/agilesellerratings/agilesellerratings.php";
         $smarty->assign(array('cate_seller_ratting' => AgileSellerRatings::getAverageRating4Category($this->category->id)));
     }
 }
 public function init()
 {
     if ($category_rewrite = Tools::getValue('category_rewrite')) {
         $sql = 'SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category_lang`
             WHERE `link_rewrite` = \'' . pSQL(str_replace('.html', '', $category_rewrite)) . '\' AND `id_lang` = ' . Context::getContext()->language->id;
         if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
             $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID();
         }
         $id_category = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
         if ($id_category > 0) {
             $_GET['id_category'] = $id_category;
         }
     }
     parent::init();
 }
    public function init()
    {
        if (Tools::getValue('category_rewrite')) {
            // SQL safe?
            $category_rewrite = Tools::getValue('category_rewrite');
            $sql = 'SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category_lang`
					WHERE `link_rewrite` = \'' . $category_rewrite . '\' AND `id_lang` = ' . Context::getContext()->language->id;
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= ' AND `id_shop` = ' . (int) Shop::getContextShopID();
            }
            $categorys_list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            $categorys_count = count($categorys_list);
            if ($categorys_count == 1) {
                // Found ONLY one so dont need to look for parent
                $id_category = (int) $categorys_list[0]['id_category'];
                $_GET['noredirect'] = TRUE;
            } else {
                if ($categorys_count > 1) {
                    // Found more than one so look for parent
                    // SQL safe?
                    $parent_rewrite = Tools::getValue('categories_rewrite');
                    $shop_id = (int) Shop::getContextShopID();
                    $sql = 'SELECT c.`id_category`
						FROM `ps_category` c
						LEFT JOIN `ps_category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.id_shop = ' . $shop_id . ' )
							INNER JOIN ps_category_shop category_shop ON (category_shop.id_category = c.id_category AND category_shop.id_shop = ' . $shop_id . ')
						LEFT JOIN `ps_category_lang` clp ON (c.`id_parent` = clp.`id_category`)
						WHERE cl.`link_rewrite` = \'' . $category_rewrite . '\'
							AND clp.`link_rewrite` = \'' . $parent_rewrite . '\'
							AND cl.`id_lang` = ' . Context::getContext()->language->id;
                    $id_category = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
                    $_GET['noredirect'] = TRUE;
                } else {
                    // none found
                    $id_category = 0;
                }
            }
            if ($id_category > 0) {
                $_GET['id_category'] = $id_category;
            } else {
                //TODO: Do we need to send 404?
                header('HTTP/1.1 404 Not Found');
                header('Status: 404 Not Found');
            }
        }
        parent::init();
    }
    public function init()
    {
        if (Tools::getValue('category_rewrite')) {
            $category_rewrite = Tools::getValue('category_rewrite');
            $id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
				SELECT `id_category`
				FROM `' . _DB_PREFIX_ . 'category_lang`
				WHERE `link_rewrite` = \'' . $category_rewrite . '\'');
            if ($id_category > 0) {
                $_GET['id_category'] = $id_category;
                //$_GET['noredirect'] = 1;
            } else {
                Tools::display404Error();
                die;
            }
        }
        parent::init();
    }
    /**
     * Method init() : Initialize category controller with category_rewrite params
     *
     * @module now_seo_links
     *
     * @see CategoryControllerCore::init()
     */
    public function init()
    {
        // Get rewrite
        $sRewrite = Tools::getValue('category_rewrite', false);
        if ($sRewrite) {
            $iIdCategory = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
				SELECT `id_category`
				FROM `' . _DB_PREFIX_ . 'category_lang`
				WHERE `link_rewrite` = \'' . $sRewrite . '\'
				AND `id_lang` = ' . Context::getContext()->language->id);
            if ($iIdCategory) {
                $_GET['id_category'] = $iIdCategory;
            }
        }
        parent::init();
        // On vérifie si l'URL actuelle est correcte ou pas
        $goodUrl = Context::getContext()->link->getCategoryLink($this->category);
        if (!preg_match('#' . $_SERVER['REDIRECT_URL'] . '#', $goodUrl)) {
            header('Status: 301 Moved Permanently', false, 301);
            header('Location: ' . $goodUrl);
            exit;
        }
    }