Re: Show one left in stock message?
Okay, I almost got this. I am using the following... ( I tried using } else { echo '<li>' . TEXT_IN_STOCK . '</li>';}} as you suggested but couldn't get it to work correctly)
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>In Stock</li>';}}
?>
and
define('TEXT_ONE_LEFT', '<span style="color:red">ONLY ONE COPY LEFT!</span>');
define('TEXT_TWO_LEFT', '<span style="color:yellow">LOW STOCK</span>');
define('TEXT_IN_STOCK', '<span style="color: green">In stock</span>');
I use product: General and product: Music. I have
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>In Stock</li>';}}
?>
in both /includes/templates/mostlygrey/templates/tpl_product_info_display.php and /includes/templates/mostlygrey/templates/tpl_product_music_info_display.php
On the general pages everything is working great except the words "In Stock" did not change to green for some reason (One left and low stock both have changed to yellow and red)
On the music pages I get TEXT_ONE_LEFT, TEXT_TWO_LEFT instead of "One left" or "Low stock". The words "In Stock" do show up though if I list more than two in stock. None have changed color.
Sorry if this is simple stuff, I'm not too knowledgeable with code and such.
Your help is mucho appreciated!
Re: Show one left in stock message?
Let's clean it up a bit:
Code:
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} elseif ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else {
echo '<li>' . TEXT_IN_STOCK . '</li>';
}
?>
and those defines need to be in a language file
Re: Show one left in stock message?
I have now used the "cleaned up" code you gave me, Thank you!
I have the defines in product_info.php which is working for "General" products except I still can't get "In stock" to change to green. I am still having trouble with the Music products. I tried making product_music_info.php and adding the defines to that but I am still getting the same TEXT_ONE_LEFT, TEXT_TWO_LEFT, etc.
Re: Show one left in stock message?
Quote:
Originally Posted by
doooomed
I have the defines in product_info.php which is working for "General" products except I still can't get "In stock" to change to green. I am still having trouble with the Music products. I tried making product_music_info.php and adding the defines to that but I am still getting the same TEXT_ONE_LEFT, TEXT_TWO_LEFT, etc.
All those symptoms tell me you're editing the wrong files (or not uploading them), even the one where you put the "cleaned up code".
Re: Show one left in stock message?
Hi, I have this working using mostly the following.
Quote:
Originally Posted by
DrByte
Your code example posted above suggests that you're doing nothing special for 3 or greater, so following that pattern, you would just do this:
The following ...
Code:
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else {
if ($products_quantity == 3) {
echo '<li>' . TEXT_THREE_LEFT . '</li>';
}}}
?>
becomes:
Code:
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo 'In Stock';}}
?>
The nesting of { and } braces is really odd in there. More complicated than it needs to be, but I fear that if I posted tidier code then you might miss the correct cleanup, so I only edited the very tiny bit shown.
So what I'm trying to do is make it show the message "Out of Stock" when the quantity reaches 0. I haven't had much luck. Any advice? Thanks.
Re: Show one left in stock message?
Quote:
Originally Posted by
Fuzztrip
So what I'm trying to do is make it show the message "Out of Stock" when the quantity reaches 0.
There's a built-in feature to show Out Of Stock (or "Sold Out") when qty is 0:
Admin->Configuration->Stock->Show Sold Out Image in place of Add to Cart
3 Attachment(s)
Re: Show one left in stock message?
Quote:
Originally Posted by
DrByte
There's a built-in feature to show Out Of Stock (or "Sold Out") when qty is 0:
Admin->Configuration->Stock->Show Sold Out Image in place of Add to Cart
I apologize, I should have elaborated more. Using the code found in this thread I now have a section in the product page that changes from "In Stock"
Attachment 19620
to "Low Stock"
Attachment 19621
But when sold out it reads "In Stock"
Attachment 19622
In includes/templates/mytemplate/templates/tpl_product_music_info_display I have
PHP Code:
<?php
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>' . TEXT_IN_STOCK . '</li>';}}
?>
In includes/languages/english/mytemplate/product_info.php I have
PHP Code:
<?php
define('TEXT_ONE_LEFT', '<b>Last One!</b>');
define('TEXT_TWO_LEFT', 'Low Stock');
define('TEXT_IN_STOCK', 'In stock');
?>
I would like to have it read "Out of stock" when the quantity reaches zero but am at a loss as how to make that happen.
Thanks!
Re: Show one left in stock message?
I tried
PHP Code:
<?php
if ($products_quantity == 0) {
echo '<li>' . TEXT_SOLD_OUT . '</li>';
} else {
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>' . TEXT_IN_STOCK . '</li>';}}
?>
PHP Code:
<?php
define('TEXT_SOLD_OUT', 'Out of Stock');
define('TEXT_ONE_LEFT', 'Last One!');
define('TEXT_TWO_LEFT', 'Low Stock');
define('TEXT_IN_STOCK', 'In stock');
?>
But it produced a blank page.
Re: Show one left in stock message?
Because you used else instead of elseif, you don't have enough closed parenthesis. Try this (I didn't test it):
PHP Code:
<?php
if ($products_quantity == 0) {
echo '<li>' . TEXT_SOLD_OUT . '</li>';
} else {
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>' . TEXT_IN_STOCK . '</li>';
}
}
}
?>
Re: Show one left in stock message?
Quote:
Originally Posted by
lindasdd
Because you used else instead of elseif, you don't have enough closed parenthesis. Try this (I didn't test it):
PHP Code:
<?php
if ($products_quantity == 0) {
echo '<li>' . TEXT_SOLD_OUT . '</li>';
} else {
if ($products_quantity == 1) {
echo '<li>' . TEXT_ONE_LEFT . '</li>';
} else {
if ($products_quantity == 2) {
echo '<li>' . TEXT_TWO_LEFT . '</li>';
} else { echo '<li>' . TEXT_IN_STOCK . '</li>';
}
}
}
?>
Perfect. Thank you!