How to programmaticaly serve a 404 in template.php
My personal advice is to return the "No results found" message from Views instead of issue a 404. Why? Because if you ever wind up adding products or changing the name of a product, what used to be a 404 is not anymore. I feel like from an SEO perspective you would have an uphill battle. Anyway.

One way to do this would be from a custom module. Do not do it in template.php.

/**
 * Implements hook_views_pre_render().
 */
 function mymodule_views_pre_render(&amp;$view) {
   if ($view-&gt;name == 'myview' &amp;&amp; some_other_conditions) {
     if (empty($view-&gt;result)) {
       drupal_add_http_header('Status', '404 Not Found');
       drupal_not_found();
       drupal_exit();
     }
  }
}


Bonus, Drupal 8:

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\views\ViewExecutable;

/**
 * Implements hook_views_pre_render().
 */
 function mymodule_views_pre_render(ViewExecutable $view) {
   if ($view-&gt;id() == 'myview' &amp;&amp; some_other_conditions) {
     if (empty($view-&gt;result)) {
       throw new NotFoundHttpException();
     }
  }
}


Is the view generating the page at products/%? Why do you need to know the $node-&gt;nid?