stephenr Posted October 18, 2013 Share Posted October 18, 2013 (edited) I want to add my best-sales block to the 404 error page, is that possible to do? I have tried to copy the content from my best sales template (best-sales.tpl) into my 404 template (404.tpl). But when i access the 404 error page, it says that there is no top products. Edited October 24, 2013 by stephenr (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 18, 2013 Share Posted October 18, 2013 in this case you will have to copy contents (from hook) to PageNotFoundController.php and also attach variable to smarty array Link to comment Share on other sites More sharing options...
stephenr Posted October 18, 2013 Author Share Posted October 18, 2013 Thanks vekia. Though what you are saying is gibberish to me. Could you explain it to me as if I was 2 years old ? Link to comment Share on other sites More sharing options...
vekia Posted October 18, 2013 Share Posted October 18, 2013 open this file: controllers/front/PageNotFoundController.php you will see there function public function initContent() - inside this function you can find: $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); right befor this code add: $this->context->smarty->assign(array( 'bestsales' => ProductSale::getBestSales($this->context->language->id,0,10) )); whole initContent funciton should look like now: public function initContent() { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); if (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('png', 'jpg', 'gif'))) { if ((bool)Configuration::get('PS_REWRITING_SETTINGS')) preg_match('#([0-9]+)(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/(.+)\.(png|jpg|gif)$#', $_SERVER['REQUEST_URI'], $matches); if ((!isset($matches[2]) || empty($matches[2])) && !(bool)Configuration::get('PS_REWRITING_SETTINGS')) preg_match('#/([0-9]+)(\-[_a-zA-Z]*)\.(png|jpg|gif)$#', $_SERVER['REQUEST_URI'], $matches); if (is_array($matches) && !empty($matches[2]) && Tools::strtolower(substr($matches[2], -8)) != '_default' && is_numeric($matches[1])) { $matches[2] = substr($matches[2], 1, Tools::strlen($matches[2])).'_default'; if (!isset($matches[4])) $matches[4] = ''; header('Location: '.$this->context->link->getImageLink($matches[4], $matches[1], $matches[2]), true, 302); exit; } header('Content-Type: image/gif'); readfile(_PS_IMG_DIR_.'404.gif'); exit; } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) exit; parent::initContent(); $this->context->smarty->assign(array( 'bestsales' => ProductSale::getBestSales($this->context->language->id,0,10) )); $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); } then in file: 404.tpl located in your theme directory add this code: {include file="./product-list.tpl" products=$bestsales} where? everything depends on you, put it there where you want to display best sales products effect: 1 Link to comment Share on other sites More sharing options...
stephenr Posted October 18, 2013 Author Share Posted October 18, 2013 Thank you so much! I will try this tonight. Link to comment Share on other sites More sharing options...
stephenr Posted October 24, 2013 Author Share Posted October 24, 2013 @vekia So I tried your solution and it works perfectly! Thank you! Link to comment Share on other sites More sharing options...
vekia Posted October 24, 2013 Share Posted October 24, 2013 thank you for confirmation that it works may i know the url to your website? im so curious how it looks and works in "real" store Link to comment Share on other sites More sharing options...
stephenr Posted October 24, 2013 Author Share Posted October 24, 2013 Yeah sure. Gives me a chance to test something else. I was told that someone in the states couldn't access the site. http://www.trendytime.dk/404test Link to comment Share on other sites More sharing options...
vekia Posted October 24, 2013 Share Posted October 24, 2013 wow! outstanding! very nice theme by the way 1 Link to comment Share on other sites More sharing options...
stephenr Posted October 24, 2013 Author Share Posted October 24, 2013 Thx Link to comment Share on other sites More sharing options...
Nikko Posted July 14, 2014 Share Posted July 14, 2014 Thank You !! Link to comment Share on other sites More sharing options...
Gipielle Posted January 28, 2016 Share Posted January 28, 2016 Hello, in prestashop 1.5 it is possibile to do this with hooks ? Link to comment Share on other sites More sharing options...
kamppa Posted July 11, 2017 Share Posted July 11, 2017 Thanks Vekia! This works with 1.6.1.10 but the product titles and descriptions are duplicated on 404 page. How could it be prevented? I also tried this: https://www.prestashop.com/forums/topic/318703-featured-products-in-404-page/?p=1613376 Link to comment Share on other sites More sharing options...
Shad86 Posted January 11, 2018 Share Posted January 11, 2018 I know I shouldn´t just add myself here but I would like to do exactly the same but in 1.7.2.4, any chance for this? Link to comment Share on other sites More sharing options...
wannaspeed Posted April 17, 2019 Share Posted April 17, 2019 (edited) On 1/11/2018 at 3:21 AM, Shad86 said: I know I shouldn´t just add myself here but I would like to do exactly the same but in 1.7.2.4, any chance for this? Did you figure it out? Wanting to do the same for 1.7.5 Edited April 17, 2019 by wannaspeed (see edit history) Link to comment Share on other sites More sharing options...
[email protected] Posted September 28, 2020 Share Posted September 28, 2020 Hello Vekia I have followed your steps as if i was a 2 years old child but it doesn't seem to work on the Prestashop 1.7.6.4. Am i missing something? 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