Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Show Inactive item instead of Page Not Found?


hydro

Recommended Posts

For products that are Inactive, instead of showing a Page Not Found (i.e. link from search engine), I would like it to show the product information if it is in the catalog but instead of showing Price and Add to Cart, I would like to show the page as Out of Stock / Deactivated.

 

Something along this message:

 

OUT OF STOCK.

Deactivated. This item is currently out of stock and it may or may not be restocked.

 

Since I don't keep track of stock level and I don't want it to automatically show out of stock if stock level is >=0. I want it to show OUT OF STOCK / Deactivated if it is in Inactive state.

 

Pros:

1. This way you don't loose your page rank if the item is deactivated but reactivate later on.

2. You can maybe cross-sell or recommend customer to go with new products

3. Can still view out of stock product information

 

Anyone knows how to do this? Probably just a few change in SQL queries and code in the product_info.php

Link to comment
Share on other sites

yes, here is my section of code .

The products_availability_id is some custom code to indicate the stock status, in my case 0 means re-orderable, 4 definitely sold out.

You might need to tweak it a little, but I think it should get you going

 

<?php
if ($product_check['total'] < 1) {
?> <h1><?php echo TEXT_HEADER_ITEM_NOT_FOUND; ?> </h1>
<?php

   // the requested product could not be found. But we do not give up.
   // Check if it was disabled and get the category id of that product
   $product_check_query = tep_db_query("select distinct pc.categories_id, cd.categories_name, cd.categories_description
									 from " . TABLE_PRODUCTS . " p,
										  " . TABLE_PRODUCTS_DESCRIPTION . " pd,
										  " . TABLE_PRODUCTS_TO_CATEGORIES . " pc,
										  " . TABLE_CATEGORIES_DESCRIPTION . " cd
									 where p.products_status != '1' and
										   p.products_id = '" . (int)$_GET['products_id'] . "' and
										   pd.products_id = p.products_id and
										   pd.products_id = pc.products_id and
										   pd.language_id = '" . (int)$languages_id . "' and
                                              pc.categories_id = cd.categories_id and
										   cd.language_id = '" . (int)$languages_id . "'");


   if ($product_check = tep_db_fetch_array($product_check_query)) { // product exists but disabled
    $msg = '<div style="margin: 20px; font-size: 12px;"><h1>';
       if ($the_man_info['manufacturers_name'] != 'Other') {
         $msg .= $the_man_info['manufacturers_name'] . ' ' ;
       }
       $msg .= $the_product_name . '</h1><div id="piGal" style="padding: 5px;background-color:lightgrey;">';
       if (tep_not_null($the_product_info['products_image'])) {
           $msg .= '<a id="one_img" style="float:left; margin: 10px; " href="' . tep_href_link(DIR_WS_IMAGES . $the_product_info['products_image'])
       . '" target="_blank" rel="fancybox" title="'.$the_product_name.'" >'
       . tep_image(DIR_WS_IMAGES . $the_product_info['products_image'], $the_product_name, 100,100) . '</a>';
       }

       if ($the_product_info['products_description'] != '') {
         $msg .= '<i>'.$the_product_info['products_description'] .'</i>';
       } else { $msg .= ' ';}
       $msg .= '<br style="clear: both;"></div>';
       if ($the_product_info['products_availability_id'] == 0) {
         $msg .= TEXT_NOT_IN_STOCK ;
       } else {
         $msg .= TEXT_IS_SOLD_OUT ;
       }
       $msg .= '</div>';
       echo $msg; ?>
<script type="text/javascript">
$("#piGal a[rel^='fancybox']").fancybox({
 cyclic: true
});
</script>      
  <h1><?php echo TEXT_OTHER_ITEMS_IN . $product_check['categories_name']; ?></h1>
  <div><?php
       if ($the_man_info['manufacturers_name'] != 'Other') {
           echo '<a href="' . tep_href_link(FILENAME_DEFAULT . '?cPath='.$product_check['categories_id'] . '&manufacturers_id=' . $the_product_info['manufacturers_id'])
       . '" title=" other items" >' . TEXT_JUST_SHOW_THE_ONES_FROM . $the_man_info['manufacturers_name'] . '</a>';
       }
       ?></div>
  <div class="cat_desc"><?php echo $product_check['categories_description']; ?></div>
<?php    
  // then we do a query of the other products in the same category
  // and we display them below using the product_listing module
  $listing_sql = "select distinct p.products_model,
						 pd.products_name,
						 p.products_image,
						 p.products_quantity,
						 p.products_id,
						 p.manufacturers_id,
						 m.manufacturers_name,
						 p.products_price,
						 p.products_tax_class_id,
						 IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
						 IF(s.status, s.specials_new_products_price, p.products_price) as final_price
				  from " . TABLE_PRODUCTS_DESCRIPTION . " pd,
					   " . TABLE_CATEGORIES . " c, (
					   " . TABLE_PRODUCTS . " p left join
					   " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id,
					   " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ) left join
					   " . TABLE_SPECIALS . " s on p.products_id = s.products_id
				  where p.products_status = '1' and
					    p.products_id = p2c.products_id and
					    pd.products_id = p2c.products_id and
					    p2c.categories_id = c.categories_id and
					    c.categories_id = " . $product_check['categories_id'] . " and
					    pd.language_id = '" . (int)$languages_id . "'";


// create column list
   $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
					 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
					 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
					 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
					 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
					 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
					 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
					 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);

   asort($define_list);

   $column_list = array();
   reset($define_list);
   while (list($key, $value) = each($define_list)) {
  if ($value > 0) $column_list[] = $key;
   }

   $select_column_list = '';

   for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
  switch ($column_list[$i]) {
    case 'PRODUCT_LIST_MODEL':
	  $select_column_list .= 'p.products_model, ';
	  break;
    case 'PRODUCT_LIST_NAME':
	  $select_column_list .= 'pd.products_name, ';
	  break;
    case 'PRODUCT_LIST_MANUFACTURER':
	  $select_column_list .= 'm.manufacturers_name, ';
	  break;
    case 'PRODUCT_LIST_QUANTITY':
	  $select_column_list .= 'p.products_quantity, ';
	  break;
    case 'PRODUCT_LIST_IMAGE':
	  $select_column_list .= 'p.products_image, ';
	  break;
    case 'PRODUCT_LIST_WEIGHT':
	  $select_column_list .= 'p.products_weight, ';
	  break;
  }
   }

   if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
  for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
    if ($column_list[$i] == 'PRODUCT_LIST_MODEL') {
	  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
	  $listing_sql .= " order by p.products_model";
	  break;
    }
  }
   } else {
  $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
  $sort_order = substr($HTTP_GET_VARS['sort'], 1);
  $listing_sql .= ' order by ';
  switch ($column_list[$sort_col-1]) {
    case 'PRODUCT_LIST_MODEL':
	  $listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '');
	  break;
    case 'PRODUCT_LIST_NAME':
	  $listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : '') . ", p.products_model";
	  break;
    case 'PRODUCT_LIST_MANUFACTURER':
	  $listing_sql .= "m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", p.products_model";
	  break;
    case 'PRODUCT_LIST_QUANTITY':
	  $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", p.products_model";
	  break;
    case 'PRODUCT_LIST_IMAGE':
	  $listing_sql .= "p.products_model";
	  break;
    case 'PRODUCT_LIST_WEIGHT':
	  $listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", p.products_model";
	  break;
    case 'PRODUCT_LIST_PRICE':
	  $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", p.products_model";
	  break;
  }
   }

?><div><?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING_COL); ?></div>
<?php    
   } else {
?>
   <div><?php echo TEXT_PRODUCT_NOT_FOUND; ?></div>
<?php      
   }
// END NOT FOUND BUT    
} else {

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

thinking about it, I think I started from another contribution, not sure which one though

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...