Jump to content

[SOLVED] Can i add best-sales block to 404 error page?


Recommended Posts

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 by stephenr (see edit history)
Link to comment
Share on other sites

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:

dUU8Ckp.png

  • Like 1
Link to comment
Share on other sites

  • 8 months later...
  • 1 year later...
  • 1 year later...
  • 6 months later...
  • 1 year later...
  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...