Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Display Out of Stock products..??


Guest

Recommended Posts

HI there,

 

I'd like to know if there's a way to display "out of stock" products?

 

I have a script that updates my parts from my supplier.. when the part is N/A it automatically sets it to "Out of Stock"... however.. now ppl can't see that product listed on my site... is there a way where i can still make it available to view? (including being listed in the Menu).. also with a "out of stock" button or text displayed on the page? and making sure ppl can't order it until it's available again?

 

what I would then setup is a cron job to DELETE the product all together if it's been n/a for extented period of time..

 

thxs a million :)

 

-JG

Link to comment
Share on other sites

You didn't say which version you are using so I will answer for 2.2ms2

 

Go to your Admin area and select the following from the menu:

 

Configuration/Stock

 

 

Set "Check stock level" to TRUE

Set "Allow checkout" to FALSE

 

This allows the customer to see products that are out of stock and displays an "out of stock" message in red on both the product info page and the shopping cart.

 

If someone tries to check out with an out of stock item in their cart, they are returned to the cart page and this message is displayed in red:

 

"Products marked with *** dont exist in desired quantity in our stock.

Please alter the quantity of products marked with (***), Thank you"

 

You can also set the (****) to whatever you want it to be....I'd leave it as it is.

 

Good luck with your site

 

Grocery Guy

gogogrocery.com

"Aliiiiive, it's alive, it's ALIIIIIIIIIIIIIVE!!!"

Link to comment
Share on other sites

Hi Paul,

 

sorry.. I am using 2.2ms2 :)

 

I can't believe I missed that section in the Admin menu! DOH!

 

Anyways, I changed the settings to what you suggested and it's still not working. Out of stock Items still don't show up anywhere in the listings...

 

any other ideas?

 

I have set to NULL both "Date Available" and "Products Quantity" and in the Stock section I have "Subtract stock" set to False..

 

thxs

-JG

Link to comment
Share on other sites

ok.. I can see my product now... however.. is there a way I can replace the "ADD TO CART" button with a "OUT OF STOCK" button for these products? (on the actual product display..)

 

thxs again

-JG

Link to comment
Share on other sites

I added your contibutions on my shop.. at first it works fine.. but now I got a parse error on line 231. Here's my code it's a bit messy. :D I'm using os2.2ms2 btw. :) Help pls. :)

 

<?php
/*
 $Id: product_info.php,v 1.97 2003/07/01 14:34:54 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);

 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 $product_check = tep_db_fetch_array($product_check_query);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link rel="stylesheet" type="text/css" href="../fg.css">
<script language="javascript"><!--
function popupWindow(url) {
 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,res
izable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,le
ft=150')
}
//--></script>
<style type="text/css">
<!--
.style1 {font-size: 9px}
-->
</style>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="90%" cellspacing="3" cellpadding="3">
 <tr>
   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
   </table></td>
<!-- body_text //-->
   <td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?><table border="0" width="95%" cellspacing="0" cellpadding="0">
<?php
 if ($product_check['total'] < 1) {
?>
     <tr>
       <td><?php new infoBox(array(array('text' => TEXT_PRODUCT_NOT_FOUND))); ?></td>
     </tr>
     <tr>
       <td> </td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
<?php
 } else {
   $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
   $product_info = tep_db_fetch_array($product_info_query);

   tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

   if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
     $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   } else {
     $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
   }

   if (tep_not_null($product_info['products_model'])) {
     $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
   } else {
     $products_name = $product_info['products_name'];
   }
?>

     <tr>
       <td class="main"><?php
   if (tep_not_null($product_info['products_image'])) {
?>
         <?php
   }
?>
         <?php
   $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
   $products_attributes = tep_db_fetch_array($products_attributes_query);
   if ($products_attributes['total'] > 0) {
?>
         <table width="100%"  border="0">
           <tr>
             <td><table border="0" cellspacing="0" cellpadding="2">
               <tr>
                 <td align="center" class="smallText">
                   <script language="javascript"><!--
document.write('<?php echo '<a href="javascript:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $product_info['products_id']) . '\\\')">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>');
//--></script>
                   <noscript>
                   <?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], $product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>
                   </noscript>
<br>
<?php
If ($product_info['products_quantity']==0){
   echo '<br><font color="#C70832"><strong>*** Out of Stock ***</stong></font><br><br>';
}
?>

                 </td>
               </tr>
             </table></td>
             <td><table width="100%"  border="0">
               <tr>
                 <td><?php echo stripslashes($product_info['products_description']); ?></td>
               </tr>
               <tr>
                 <td><table width="100%" border="0" cellpadding="0" cellspacing="3">
                     <?php
     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
     while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
       $products_options_array = array();
       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
       while ($products_options = tep_db_fetch_array($products_options_query)) {
         $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
         if ($products_options['options_values_price'] != '0') {
           $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
         }
       }

       if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
         $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
       } else {
         $selected_attribute = false;
       }
?>
                     <tr>
                       <td width="60" class="productvalue"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
                       <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
                     </tr>
                     <?php
     }
?>
                   </table>
                 </td>
               </tr>
             </table>
             <table width="100%" border="0">
               <tr>
                 <td><?php If ($product_info['products_quantity']<>0){
   echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); 
}else{
   echo tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . 'button_out_of_stock_cart.gif', IMAGE_BUTTON_OUT_OF_STOCK); 
   
} 
?>
</td>
               </tr>
               <tr>
                 <td><?php echo '<a href="flash.php?menu=0">' . tep_image_button('button_continue_shopping.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; ?></td>
               </tr>
             </table></td>
           </tr>
         </table>
         <?php
   }
?>
       </td>
     </tr>
        <tr>
       <td>
         <?php require(DIR_WS_MODULES . FILENAME_ADDITIONAL_IMAGES); ?>   
       </td>
     </tr>
<?php
   $reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
   $reviews = tep_db_fetch_array($reviews_query);
   if ($reviews['count'] > 0) {
?>
<?php
   }

   if (tep_not_null($product_info['products_url'])) {
?>
<?php
   }

   if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
?>
<?php
   } else {
?>
<?php
   }
?>

   </table>
   </form></td>
<!-- body_text_eof //-->
   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
   </table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Link to comment
Share on other sites

line 71.. the required slashes for the QUOTES ("") are missing..

 

replace:

echo '<br><font color="#C70832"><strong>*** Out of Stock ***</stong></font><br><br>';

 

with:

echo "<br><font color=\"#C70832\"><strong>*** Out of Stock ***</stong></font><br><br>";

 

(notice the slashes in front of the quotes)

 

that should do it..

 

-JG

Link to comment
Share on other sites

erm.. I already get rid of it.. but still wasn't working. But I got it all work now.. I delete some codes of my product_info page.. but not your code. :D Love your code !!

 

I have this other problem, I installed QTPro and love that cons too. But the thing is I can still buy the out of stock product of certain attributes. For example, I have 2 size of shirts, the large size is "0" quantity but the medium is "5". I can still able to buy that shirt large size. But if both L or M is "0", the item shows as an out of stock. Is it possible if I set the large to an "Out of stock" item? Or maybe I should ask the QTPro support.. :D but anyway, thanks for your help and your constribution :)

Link to comment
Share on other sites

I'm glad you figured it out and that you enjoy my contrib ! :)

 

You might want to check with the QTPro ppl first on this issue since I've never used that contrib (yet) and I haven't started using the attribute feature of oscommerce.. Perhaps when I get a chance I'll take a look at it and post an update..

I'm sure it can be done.. just a matter of coding it in ;)

 

-JG

Link to comment
Share on other sites

Thanks for the great contrib. I have most of it working but having a problem with the product_listing.php. I never return a true value for the following line;

if ($listing['products_quantity']<>0){

 

Thus everything shows an out of stock button, in stock and out of stock.

 

Any ideas?

 

Thanks,

Mark

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 2 weeks later...

The reason - If ($listing['products_quantity']<>0){ always give you OUT OF STOCK in product listing is because it try to take its value from the product quantity value in the listing page, so if you set your Display Product Quantity to 0 (=don't display) this value will always be 0, and will the OUT OF STOCK button will always appear.

Meaning - you must enable the Display Product Quantity in your admin for this contribution to show the correct button.

 

This is a disadvantage for someone like me who want to hide the Stock qty, so I tried to make product_listing.php take the value from (If ($product_info['products_quantity']<>0){) instead of the $listing, but it doesn't work...unfortunately my knowledge in PHP is less than limited and I would appreciate if someone can fix the contribution to show the correct buttons even when the Display Product Quantity is disabled. :)

Link to comment
Share on other sites

I am using MS1 with column listing and do not use the buy it now button

and the only Mods I made were as follows:

Open your includes/languages/english.php file and add:

 

define('IMAGE_BUTTON_OUT_OF_STOCK', 'Out of Stock');

 

 

and:

 

Open your product_info.php file and find:

 

echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);

 

Comment Out or REPLACE it with:

 

If ($product_info['products_quantity']<>0){

    echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);

}else{

    echo tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . 'button_out_of_stock_cart.gif', IMAGE_BUTTON_OUT_OF_STOCK);

   

}

 

I changed nothing else except to have products set to on (green) with a quantity of "0".

Worked like a dream!

Link to comment
Share on other sites

There is one more issue:

 

The "Add to Cart" buttons are still available for out of stock items in the New Products window (What's new? -> more) and this should be changed too if possible.

 

Anybody know how?

 

Thanks in advance! :)

Link to comment
Share on other sites

I *think* that this is the part that should be revised in /catalog/product_new.php:

 

 

<tr>
? ? ? ? ? ?<td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
? ? ? ? ? ?<td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
? ? ? ? ? ?<td align="right" valign="middle" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>'; ?></td>
? ? ? ? ?</tr>

 

Can anyone please explain how to revise it so that the "Out of Stock" button will be displayed instead of the "Add to Cart" button when the item is out of stock?

Link to comment
Share on other sites

  • 3 months later...

dr_lucas, and everybody else,

If you havent found the solution fot this I got it.

 

Fist of all, Display Product Quantity in admin must be enabled, then product_new.php must read from the quantity table in Mysql, you do this by adding

p.products_quantity

in the line where product_new.php catch the info from mysql.

In my template file product_new.tpl.php it look like this:

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";

 

The you go to the buy now button:

<?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_IN_CART) . '</a>'; ?>

and replace it or comment it out with:

<?php
	 If ($products_new['products_quantity']<>0){
           echo       '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>';
           }else{    
           echo tep_image_button('button_out_of_stock.gif', IMAGE_BUTTON_OUT_OF_STOCK) . ' ';
     }
?>

 

 

It worked for me :D

 

// Fredrik J

 

*** my sport ate your sport for breakfast ***

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...