Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Displaying "out of stock" in Product Listings?


sf7804

Recommended Posts

Posted

Just curious, can someone point me to the right code to add an "out of stock" warning to the product listings? I have added the code here to the product_info.php, but I can't get it to work with product_listing.php

 

I've searched.. I've played with the code.. I've messed the code up, so now I ask for help :D

Posted

You need to supply the code with a products_id, so you would need to call the function within the listing iteration on a per product basis.

 

Make sense ? ;)

 

Basically feed the product ID one at a time while the query is executing.

Posted

Well, sort of. My ability to program in php is somewhat limited... am I right in assuming that whicever code needs to be added goes into here in product_listing.php? (assuming I wish to list the stock status just after the product name)

 

          case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_name'] . '</a> ';

           }

           break;

 

I didn't use a function in the product_info.php, I just used (well edited) the code listed in the link I gave earlier.

 

Here's a feeble attempt, I haven't tested it, have no clue if it is syntacticly correct, but I could just call it from the other statement, maybe stick it after the closing anchor tag, right? Maybe? So frustrating ;) Oh how I wish I knew what I was doing.. LOL!

 

<?php 

function getStockStatus($products_id) {

$prod_quantity = tep_get_products_stock($products_id); 

print '<span class="stockWarning">';

switch ($prod_quantity) { 

 case 0: 

	 print "Out of stock"; 

	 break; 

 case 1:

 case 2:

 case 3:

	 print "limited quantity"; 

	 break; 

 default: 

	 print "In Stock"; 

 };

 print "</span>";

}

?>

Posted

Try this:

 

case 'PRODUCT_LIST_QUANTITY':

           $lc_align = 'right';

           switch($listing_values['products_quantity']) {

               case 0:

               $value = "Out of stock";

               break;

               case 1:

               case 2:

               case 3:

               $value = "limited quantity";

               break;

               default:

               $value = "In Stock";

           }

           $lc_text = ' ' . $value  . ' ';

           break;

 

Untested, I just wrote it now. Might work, looks logical enough...

 

hth

Posted

ps, sorry about mentioning functions, there is a get quantity function floating about somewhere that I wrote...thought you may have been using that one..

Posted

I've quickly tested and that does appear to work, you could use the same sort of thing to turn the "buy now" button off as well (if stock == 0).

 

hth

Posted

Nope, I didn't find the "get quantity" function. My little function works, the problem is that it doesn't put the end value where I'd expect, it's all listed at the top :( You can see here (unless I've fixed it before you view the thread) http://www.rat-store.com/default.php?cPath=26_24

 

Where exactly do I need to place the function to be called? Right now it's as follows.. (look for getStockStatus, this is in product_listing.php, obviously)

          case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a><br>' . getStockStatus($listing_values['products_id']);

           } else {

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_name'] . '</a><br>' . getStockStatus($listing_values['products_id']);

           }

           break;

Posted

WOOHOO! I did it.. I had to make it a return since it's only part of $lc_text, not the whole thing.

 

Here it is that works, just as I'd started off, with some alterations based on the "better" code that was posted ;)

 

function getStockStatus($products_id) {

$prod_quantity = tep_get_products_stock($products_id); 

switch ($prod_quantity) { 

 case 0: 

	 $value = "Out of stock"; 

	 break; 

 case 1:

 case 2:

 case 3:

	 $value = "limited quantity"; 

	 break; 

 default: 

	 $value = "In Stock"; 

 };

 return('<span class="stockWarning">' . $value  . '</span> ');

}

 

I think I may move the value into the "quantity" column, and change the heading, that way I can display the more useful information and not just numbers.

Posted

Works rather nicely doesn't it, I've just implemented almost the same thing on my test shop, and am testing it out fully now...

 

I've also put in a switch to remove the "buy now" button on product_info.php and product_listing.php

 

Just gotta find the other places where it's possible to buy from now. :?

Posted

I don't use the buy now feature, but I suppose I could adapt what I've done to make a switch as you have.

 

I'm actually sort of amazed that was as "easy" to do as it was, all things considered (the fact that I don't know php, and only have limited C++ and perl experience) ;)

Posted

try to install my qty_display_allowed hack

it let you define standard

Out Of Stock

In stock x pces

Coming Soon

On Request

 

you set easilly in admin panel like this :

set_display_qty_admin_.jpg

 

and then in catalog

display_qty_text_catalog.jpg

 

this is avalaible in all page and i have also updated printable_catalog to display stock

 

look at my demo shop

some other features are avalaible

define a breakout that will alow display qty only if < = > to the breakout

define more stock statuses as you want...

Posted

no problem

whas just to help as this is a relativly easy to install hack...

  • 3 months later...
Posted

Hey Elari, or anyone for that matter...

 

I thought it was very easy to hack, I have altered the code and layouts etc to my hearts content, but for the life of me I can not get it to work on frickin products_info page!!!!

 

I have been working on this for literally hours now!! :onfire:

It just will not display anything, I receive no errors now, but I also see no display text...

 

pfffff... I cant figure it out at the mo... :sneaky:

It worked everywhere else just fine, but not on product_info

 

Elari - I have PM'd you for some hellp if you could please.

ta.

 

CC.

Posted

i just answerd you in pm

send me ftp access and let me know if you use the old way for display qty or the lastest one witch use a function like this one

         case 'PRODUCT_LIST_QUANTITY':

           $lc_align = 'right';

           //elari quantity display allowed

           if (PRODUCT_LIST_PRODUCTS_STATUS == 1 ) {

             $lc_text=tep_get_products_stock_status_display ( $listing['products_quantity'] , $listing['products_quantity_display_allowed'] );

           } else {

           // we display qty the usual way managed by OSc... nothing is changed :)

           // If you need you can again make test on breakout qty....

           $lc_text = ' ' . $listing['products_quantity'] . ' ';

           }

           //elari end display qty

           break;

 

send me ftp acces in private !!!!

Posted

Thanks for this buddy, but I did manage to fix this in the end.

 

I went about it slightly differently, but got my end result.

 

I have altered things a little from your original contribution, adding images and to other pages etc.

 

But I have upgraded to your most recent mod now too, and it works pretty well.

 

thanks for the tips, and for a great mod. :wink:

CC.

Posted

This post isn't really for those already participating in this thread as much as it's for someone who finds this thread via a search or whatnot. Additionally, sometimes when I find these threads that have been going on for a while, it's difficult for me to put together exactly what the answer is/was. There are usually code examples and then revisions, suggestions etc, and maybe even different options. So to lay it all out for a newbie-non-php-coder like me, here's what I got out of this thread.

 

I took the examples here and did something similar. In my case, I just simply wanted out of stock and changed:

case 'PRODUCT_LIST_QUANTITY':

           $lc_align = 'center';

           $lc_text = ' ' . $listing_values['products_quantity'] . ' ';

           break;  

 

To:

case 'PRODUCT_LIST_QUANTITY': 

           $lc_align = 'center'; 

           switch($listing_values['products_quantity']) { 

               case 0: 

               $value = "<font color=red><i>Out of stock</i></font>"; 

               break; 

               default: 

               $value = $listing_values['products_quantity'];

           } 

           $lc_text = ' ' . $value  . ' '; 

           break;

 

Additionally, if a product was out of stock, I thought it would be nice to have the price either greyed out and/or struck out. So in the same file, I went to line 122 and changed:

case 'PRODUCT_LIST_PRICE':

           $lc_align = 'right';

           if ($listing_values['specials_new_products_price']) {  

 

To:

case 'PRODUCT_LIST_PRICE':

           $lc_align = 'right';

           if (($listing_values['products_quantity']) <=0) {

           $lc_text = ' <s><font color=gray>' . $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</s></font> ';

           } elseif

           ($listing_values['specials_new_products_price']) {  

 

Hope that helps somebody :)

Have you ever gotten any help from these forums? Be part of the community and help out by answering a question or 2.

Pass on what you know about OSC to someone who needs help.

Posted
no problem

whas just to help as this is a relativly easy to install hack...

 

Hi, where is the contribution, I can't find it.. sorryyyy

 

Salvo

Posted
WOOHOO! I did it.. I had to make it a return since it's only part of $lc_text, not the whole thing.

 

Here it is that works, just as I'd started off, with some alterations based on the "better" code that was posted ;)

 

function getStockStatus($products_id) {

$prod_quantity = tep_get_products_stock($products_id); 

switch ($prod_quantity) { 

 case 0: 

	 $value = "Out of stock"; 

	 break; 

 case 1:

 case 2:

 case 3:

	 $value = "limited quantity"; 

	 break; 

 default: 

	 $value = "In Stock"; 

 };

 return('<span class="stockWarning">' . $value  . '</span> ');

}

 

I think I may move the value into the "quantity" column, and change the heading, that way I can display the more useful information and not just numbers.

 

Can anyone tell me where this code go?

 

I am using the MS1

 

Thanks

Archived

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

×
×
  • Create New...