sf7804 Posted January 27, 2003 Posted January 27, 2003 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
burt Posted January 27, 2003 Posted January 27, 2003 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.
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 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>"; } ?>
burt Posted January 27, 2003 Posted January 27, 2003 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
burt Posted January 27, 2003 Posted January 27, 2003 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..
burt Posted January 27, 2003 Posted January 27, 2003 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
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 Ack, well an update, that "worked" just not as I expected! LOL! Oh well... at least I'm "close" :)
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 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;
burt Posted January 27, 2003 Posted January 27, 2003 Use the code I have posted up there ^ - it works fine on a 23/1/2003 snapshot.
burt Posted January 27, 2003 Posted January 27, 2003 You can see here (unless I've fixed it before you view the thread)http://www.rat-store.com/default.php?cPath=26_24 Parse error: parse error in /rat-store.com/includes/modules/product_listing.php on line 16
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 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.
burt Posted January 27, 2003 Posted January 27, 2003 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. :?
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 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) ;)
elari Posted January 27, 2003 Posted January 27, 2003 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 : and then in catalog 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...
sf7804 Posted January 27, 2003 Author Posted January 27, 2003 Very interesting, but I think what I've come up with will work fine for my rather small store ;)
elari Posted January 27, 2003 Posted January 27, 2003 no problem whas just to help as this is a relativly easy to install hack...
CC Posted May 18, 2003 Posted May 18, 2003 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.
elari Posted May 18, 2003 Posted May 18, 2003 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 !!!!
CC Posted May 18, 2003 Posted May 18, 2003 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.
GaryM Posted May 19, 2003 Posted May 19, 2003 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.
Salvo Posted May 24, 2003 Posted May 24, 2003 no problemwhas just to help as this is a relativly easy to install hack... Hi, where is the contribution, I can't find it.. sorryyyy Salvo
Salvo Posted May 24, 2003 Posted May 24, 2003 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
xempel Posted May 27, 2003 Posted May 27, 2003 thx for the info,, but if i whant pictures instead for the collerd text how do i do that?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.