pafranklin Posted December 17, 2013 Posted December 17, 2013 Hi, I currently use the following to display stock levels on my site. <td align="left" class="main">Currently <b><?php //echo tep_get_products_stock($product_info['products_id']); ?></b> in stock (Our warehouse & Manufacturers).</td> However we don't always have absolutely correct stock levels so I would like to change the display to some think like the following... If More than 10 in stock display "Good Stock Levels available" If between 1 and 10 in stock to display "Low Stock Levels" If 0 in stock (out of stock) to display "Currently Out of Stock - Orders received will be placed on backorder" I wonder if someone could assist please? Many thanks. Paul You will never learn if you don't try. And boy am I trying....!
Jack_mcs Posted December 17, 2013 Posted December 17, 2013 Something like the following should work though it has not been tested: <td align="left" class="main"> <?php $qty = tep_get_products_stock($product_info['products_id']); switch ($qty) { case (qty > 10): echo "Good Stock Levels available"; break; case (qty > 0): echo "Low Stock Levels"; break; default: echo "Currently Out of Stock - Orders received will be placed on backorder"; }?> </td> Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
pafranklin Posted December 17, 2013 Author Posted December 17, 2013 Hi and thank you for the reply. I have implemented this and tweaked it slightly but this only shows either out of stock or Low Stock levels. I don't appear to be able to use the equals sign (=) as this crashes the page but ideally 0= Out of stock, 1-10 is Low Stock and above 10 is Good stock. <td align="left" class="stocklevels"> <?php $qty = tep_get_products_stock($product_info['products_id']); switch ($qty) { case (qty > 1): echo "Currently Out of Stock - Orders received will be placed on backorder"; break; case (qty < 10): echo "Low Stock Levels"; break; default: echo "Good Stock Levels available"; }?> </td> Thanks again Jack and hope you can point me in the right direction? Best regards. Paul You will never learn if you don't try. And boy am I trying....!
pafranklin Posted December 17, 2013 Author Posted December 17, 2013 Hi again, I've tried this also but again all I now get is out of stock on everything.......? <td align="left" class="stocklevels"> <?php $qty = tep_get_products_stock($product_info['products_id']); switch ($qty) { case (qty > 10): echo "Good Stock Levels available"; break; case (qty > 5): echo "Low Stock Levels"; break; case (qty > 0): echo "Very Low Stock Levels"; break; default: echo "Currently Out of Stock - Orders received will be placed on backorder"; }?> </td> Any help would be appreciated please.....? Many thanks. Paul You will never learn if you don't try. And boy am I trying....!
Jack_mcs Posted December 17, 2013 Posted December 17, 2013 Change all of the "case (qty" to "case ($qty" Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
pafranklin Posted December 17, 2013 Author Posted December 17, 2013 Thanks again Jack for the help. I think it's getting closer and code so far is <td align="left" class="stocklevels"> <?php $qty = tep_get_products_stock($product_info['products_id']); switch ($qty) { case ($qty > 10): echo "Good Stock Levels available"; break; case ($qty > 5): echo "Low Stock Levels"; break; case ($qty > 0): echo "Very Low Stock Levels"; break; default: echo "Currently Out of Stock - Orders received will be placed on backorder"; }?> </td> However items with a stock level of zero still show as "Good Stock Levels available". The other values seem to return the correct response but I don't know how to return "Currently Out of Stock - Orders received will be placed on backorder" for stock levels of zero? Do you think you could have one more quick look please? Many thanks. Paul You will never learn if you don't try. And boy am I trying....!
Jack_mcs Posted December 17, 2013 Posted December 17, 2013 Try changing switch ($qty) { to echo "qty = '.$qty; switch ($qty) { That will show the actual value being returned. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
pafranklin Posted December 17, 2013 Author Posted December 17, 2013 At last I've figured it out. What I had told PHP to do is compare the value of $qty with the result of ($qty>10). You could use a switch for this (I'm reliably informed) so had to use a regular if/elseif statement instead. Anyway this worked for me so thank you for the input and I hope this helps someone else... <?php $qty = tep_get_products_stock($product_info['products_id']); if ($qty > 10) echo "Good Stock Levels available"; else if ($qty > 5) echo "Low Stock Levels"; else if ($qty > 0) echo "Very Low Stock Levels"; else echo "Currently Out of Stock - Orders received will be placed on backorder" ?> Paul You will never learn if you don't try. And boy am I trying....!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.