hakeryk2 Posted April 21, 2016 Share Posted April 21, 2016 (edited) Hello community, How to create a link in .tpl file which will show all featured products? I have tried to do something like this {$link->getCategoryLink(2)} Because I found in database that this is the ID of main category is 2 but it showing 404 page when I try to click it. Same is when I will 1 instead of 2. In front office when I hover the link that I've created I am getting proper seo ie http://mywebsite.pl/2-polecane (polecane in polish is featured). Any ideas? This is so trivial and I am a little bit angry that I am not able to figure that out. Edited April 21, 2016 by hakeryk2 (see edit history) Link to comment Share on other sites More sharing options...
Daresh Posted April 21, 2016 Share Posted April 21, 2016 You want to display all products from the home category? For some reason this is not so easy to do. The easiest workaround is to have some another category (like "All") Link to comment Share on other sites More sharing options...
hakeryk2 Posted April 21, 2016 Author Share Posted April 21, 2016 Yup, that is what I want - display all of them. Ok, so this is impossible and I am not asking why. So now I will create new category, I will go to PhpMyAdmin and select all products with category "2" and add to them new category id which I will put in .tpl file. In future I will have just another checkmark to check :/ Thanks for Your advice. Dzięki 1 Link to comment Share on other sites More sharing options...
endriu107 Posted April 21, 2016 Share Posted April 21, 2016 I think this should solve problem: In CategoryController.php override function canonicalRedirection by this code: <?php class CategoryController extends CategoryControllerCore { public function canonicalRedirection($canonicalURL = '') { if (Tools::getValue('live_edit')) return ; if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop() || $this->category->id == Configuration::get('PS_ROOT_CATEGORY')) { $this->redirect_after = '404'; $this->redirect(); } if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category)) FrontController::canonicalRedirection($this->context->link->getCategoryLink($this->category)); } } We supposed to write in other language forums 1 Link to comment Share on other sites More sharing options...
endriu107 Posted April 21, 2016 Share Posted April 21, 2016 (edited) Now I check my solution and its work but product are not display, so this is complete override code: <?php class CategoryController extends CategoryControllerCore { public function canonicalRedirection($canonicalURL = '') { if (Tools::getValue('live_edit')) return ; if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop() || $this->category->id == Configuration::get('PS_ROOT_CATEGORY')) { $this->redirect_after = '404'; $this->redirect(); } if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category)) FrontController::canonicalRedirection($this->context->link->getCategoryLink($this->category)); } public function assignProductList() { $hook_executed = false; Hook::exec('actionProductListOverride', array( 'nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hook_executed, )); // The hook was not executed, standard working if (!$hookExecuted || is_null($this->nbProducts)) { $this->context->smarty->assign('categoryNameComplement', ''); $this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true); $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts" $this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); } // Hook executed, use the override else { // Pagination must be call after "getProducts" $this->pagination($this->nbProducts); } $this->addColorsToProductList($this->cat_products); Hook::exec('actionProductListModifier', array( 'nb_products' => &$this->nbProducts, 'cat_products' => &$this->cat_products, )); foreach ($this->cat_products as &$product) { if (isset($product['id_product_attribute']) && $product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) { $product['minimal_quantity'] = $product['product_attribute_minimal_quantity']; } } $this->context->smarty->assign('nb_products', $this->nbProducts); } } Edited April 21, 2016 by endriu107 (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now