Lemonstand product & category throw 404 if not found

January 2, 2014    lemonstand

Lemonstand weirdly does not come with a way to configure it's dynamic pages such as categories and products to throw automatically throw a 404 if the product was not found.

I solved this with the following simple snippet. Initially just added to the post_action.php for both the category/ and product/ pages.

if(!isset($product)){
  $params = array();

  $page = Cms_Page::findByUrl('/404', $params);
  header('HTTP/1.0 404 Not Found');
  Cms_Controller::get_instance()->open($page,$params);
  exit;
}

if(!isset($category)){
  $params = array();

  $page = Cms_Page::findByUrl('/404', $params);
  header('HTTP/1.0 404 Not Found');
  Cms_Controller::get_instance()->open($page,$params);
  exit;
}

An improvement to this could be to wrap the 404 throwing into a function provided by a custom module and then just keep the logic behind throwing the 404 in the relevant areas of the site. In this case I just couldn't be bothered...bite me.


blog comments powered by Disqus