Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

"In Stock"/"Out of Stock"


sosidge

Recommended Posts

Hi,

 

I want to update my site so that it displays whether an item is "In Stock" or "Out of Stock" as you look at it in product_info.php (and perhaps also on the product list as you browse the categories). Saving the customer the hassle of adding it to the cart, only to get an "Out of Stock" message.

 

I don't want to display quantities (the option in the osCommerce admin tool) - there should be some secrets in a relationship!

 

Any suggestions for a good, simple contribution, or code change?

 

Also, how can I stop osCommerce changing the product status to "red" (i.e. removed from the catalogue) when the stock runs out? I want it to stay "green" (i.e. in the catalogue) at all times.

 

Thanks.

- osCommerce is fun! -
Link to comment
Share on other sites

Try this:

 

 <?php ? if ((STOCK_CHECK == 'true')&&(tep_get_products_stock($product_info['products_id']) < 1)) {
?>
? ? ?<tr>
? ? ? <td><span class="markProductOutOfStock"><b><?php echo 'Out of Stock'; ?></b></span></td>
? ? ?</tr>
<?php
} else {
?>
? ? ?<tr>
? ? ? <td><span class="markProductOutOfStock"><b><?php echo 'In Stock'; ?></b></span></td>
? ? ?</tr>
<?php
}
?>?

 

 

Matti

Link to comment
Share on other sites

Under includes/languages/english/product_info.php I have added this to the front of the existing text and shows up when you set an estimated in stock date.

 

define('TEXT_DATE_AVAILABLE', '<font color="#ff0000"><font size="2">OUT OF STOCK<BR></font>

 

HTH

Link to comment
Share on other sites

Matti: What file does your code go into and where?

 

I usually have my quanitity stock in admin set at a real high number (just in case!) and have set in admin under Configuration, check stock level = False, subtract stock = False, mark product out of stock = blank.

 

Thanks!

Link to comment
Share on other sites

Matti:? What file does your code go into and where?

 

I usually have my quanitity stock in admin set at a real high number (just in case!) and have set in admin under Configuration, check stock level = False, subtract stock = False, mark product out of stock = blank.

 

Thanks!

The code I posted would go in product_info.php - for product_listing use the $listing variable (from index.php) rather than $product_info - it would also need to be formatted differently (loop)

 

The above could be used elsewhere also - just make sure you have the correct $variable['products_id'] - eg. in specials.php you would use $specials from the $specials_query :)

 

You can place the code anywhere on the page - eg. immediately after:

 

 ? ? ?<tr>
? ? ? ?<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
? ? ? ? ?<tr>
? ? ? ? ? ?<td class="pageHeading" valign="top"><?php echo $products_name; ?></td>
? ? ? ? ? ?<td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
? ? ? ? ?</tr>
? ? ? ?</table></td>
? ? ?</tr>

 

Matti

Link to comment
Share on other sites

  • 2 weeks later...
Also, how can I stop osCommerce changing the product status to "red" (i.e. removed from the catalogue) when the stock runs out? I want it to stay "green" (i.e. in the catalogue) at all times.

Any thoughts on this? Thanks

- osCommerce is fun! -
Link to comment
Share on other sites

  • 1 month later...

With much delay, many thanks to Matti for the solution above, I've finally got that code added - excellent!

 

I also found a solution to the products not appearing in the catalogue once they are out of stock - can someone reassure me that i won't have a bigger problem in the future from this.

 

I've made this change in checkout_process.php, around line 152...

 

if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
         tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'"); //set_products_status was 0
       }

 

This seems to stop the product being switch to "out of stock" status in the admin panel (when the red light comes on), and so it stays in the catalogue.

 

Is this a good solution? No hidden problems that I'll suffer in the future?

 

Thanks.

- osCommerce is fun! -
Link to comment
Share on other sites

Ok, another update.

 

I've just adapted Matti's code so that it can be used in the product listing to give an "In Stock"/"Out of Stock" message, replacing the Quantity column.

 

Wrapped it up into a contribution (hope you don't mind).

 

Find it here.

- osCommerce is fun! -
Link to comment
Share on other sites

Try this:

 

 <?php ? if ((STOCK_CHECK == 'true')&&(tep_get_products_stock($product_info['products_id']) < 1)) {
?>
? ? ?<tr>
? ? ? <td><span class="markProductOutOfStock"><b><?php echo 'Out of Stock'; ?></b></span></td>
? ? ?</tr>
<?php
} else {
?>
? ? ?<tr>
? ? ? <td><span class="markProductOutOfStock"><b><?php echo 'In Stock'; ?></b></span></td>
? ? ?</tr>
<?php
}
?>?

 

 

Matti

Why use tep_get_products_stock? You're simply adding an unnecessary query to the page.

 

The count is already called on that page. A better solution would be something like:

 

<?php   if ((STOCK_CHECK == 'true')&&($product_info['products_quantity'] < 1)) {
?>

Link to comment
Share on other sites

  • 10 months later...

If the item has stock and has a in stock date, how would I show the date?

 

case 'PRODUCT_LIST_QUANTITY':
$lc_align = 'center';
if ((STOCK_CHECK == 'true')&&($listing[$x]['products_quantity'] < 1)) {
$lc_text = '<span class="markProductOutOfStock"><b>Out of Stock</b></span>';
} else {
if ($listing[$x]['products_date_available'] > date('Y-m-d H:i:s')) {
$lc_text = '<span class="markProductOutofStock"><b>In Stocx ' . tep_date_long($listing[$x]['products_date_available']) . '</b></span>';
} else {
$lc_text = '<span class="markProductOutofStock"><b>In Stock</b></span>';
}}
break;

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...