Forums / Templates, Stylesheets, Page Layout / Show one left in stock message?

Show one left in stock message?

Started by doooomed on 15 Apr 2012, 5:19 PM · Views: 7,584

Results 21 to 40 of 40
16 Aug 2012, 3:28 PM
#21
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Show one left in stock message?

I also tried to add to the code...

Example:

<?php echo (($flag_show_product_info_quantity == 1 && $products_quantity >3) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>' : '') . "\n"; ?> <?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>'; } else { if ($products_quantity == 4) { echo '<li>' . TEXT_FOUR_LEFT . '</li>'; } else { if ($products_quantity == 5 { echo '<li>' . TEXT_FIVE_LEFT . '</li>'; } else { if ($products_quantity == 6) { echo '<li>' . TEXT_SIX_LEFT . '</li>'; } else { if ($products_quantity == 7) { echo '<li>' . TEXT_SEVEN_LEFT . '</li>'; } else { if ($products_quantity == 8) { echo '<li>' . TEXT_EIGHT_LEFT . '</li>'; } else { if ($products_quantity == 9) { echo '<li>' . TEXT_NINE_LEFT . '</li>'; } else { if ($products_quantity == 10) { echo '<li>' . TEXT_TEN_LEFT . '</li>'; } else { if ($products_quantity == 11) { echo '<li>' . TEXT_ELEVEN_LEFT . '</li>'; } else { if ($products_quantity == 12) { echo '<li>' . TEXT_TWELVE_LEFT . '</li>'; } else { if ($products_quantity == 13) { echo '<li>' . TEXT_THIRTEEN_LEFT . '</li>'; } else { if ($products_quantity == 14) { echo '<li>' . TEXT_FOURTEEN_LEFT . '</li>'; } else { if ($products_quantity == 15) { echo '<li>' . TEXT_FIFTEEN_LEFT . '</li>'; }}} ?>

And...

<?php define('TEXT_ONE_LEFT', 'ONLY ONE COPY LEFT!'); define('TEXT_TWO_LEFT', 'LOW STOCK'); define('TEXT_THREE_LEFT', 'In stock'); define('TEXT_FOUR_LEFT', 'In stock'); define('TEXT_FIVE_LEFT', 'In stock'); define('TEXT_SIX_LEFT', 'In stock'); define('TEXT_SEVEN_LEFT', 'In stock'); define('TEXT_EIGHT_LEFT', 'In stock'); define('TEXT_NINE_LEFT', 'In stock'); define('TEXT_TEN_LEFT', 'In stock'); define('TEXT_ELEVEN_LEFT', 'In stock'); define('TEXT_TWELVE_LEFT', 'In stock'); define('TEXT_THIRTEEN_LEFT', 'In stock'); define('TEXT_FOURTEEN_LEFT', 'In stock'); define('TEXT_FIFTEEN_LEFT', 'In stock'); ?>

Still produces blank page...

17 Aug 2012, 1:02 PM
#22
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

Anyone? Help please!

17 Aug 2012, 2:16 PM
#23
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

I am also getting this error message "syntax error, unexpected $end" from tpl_product_info_display.php on line 319. Line 319 is the last line of code and only has </div> on it

22 Aug 2012, 2:12 PM
#24
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

Wow! No one on this? :huh:

30 Aug 2012, 6:04 AM
#25
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Show one left in stock message?

try changing

if ($products_quantity == 15) {
echo '<li>' . TEXT_FIFTEEN_LEFT . '</li>';
}}}
?>

to

if ($products_quantity == 15) {
echo '<li>' . TEXT_FIFTEEN_LEFT . '</li>';
}}}}}}}}}}}}}}}
?>
31 Aug 2012, 11:27 PM
#26
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

Hi rbarbour! Thank you for the reply. I made the suggested changes and I still get a blank page. I should elaborate on what I mean by blank page. When I say blank page, I still get the header and banner and all that, but I lose the actual product listing... picture, description, price, etc. Any idea? Thanks!!!

31 Aug 2012, 11:28 PM
#27
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

By the way this does work for me if I leave the code the way you originally had it.

1 Sep 2012, 12:18 AM
#28
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Show one left in stock message?

rbarbour:

I did something similar before, I will post that code so you get the idea. My PHP skills aren't that great but it works.

in:
/includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php

find:

<?php echo (($flag_show_product_info_quantity == 1) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>' : '') . "\n"; ?>
> 
> change to:
> ```php
  <?php echo (($flag_show_product_info_quantity == 1 && $products_quantity >3) ? '<li>' . $products_quantity . TEXT_PRODUCT_QUANTITY . '</li>'  : '') . "\n"; ?>
  <?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>';
}}}
?>

then in:
/includes/languages/english/YOUR_TEMPLATE/product_info.php

Add:

define('TEXT_ONE_LEFT', 'Are you feeling lucky, only 1 available!');
define('TEXT_TWO_LEFT', 'Don't miss out, only 2 left.');
define('TEXT_THREE_LEFT', 'Hurry, while supplies last!');

> 
> if the languages file product_info.php doesn't exist, create it.
> 
> Hope this helps!

> **doooomed:**
>
> Hello,
> 
> I am trying to alter this a little and am having some trouble. All I want to do is eliminate the "define('TEXT_THREE_LEFT', 'Hurry, while supplies last!');" part of this.
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 ...
<?php if ($products_quantity == 1) { echo '<li>' . TEXT_ONE_LEFT . '</li>'; } else { if ($products_quantity == 2) { echo '<li>' . TEXT_TWO_LEFT . '</li>'; } else [B]{ if ($products_quantity == 3) { echo '<li>' . TEXT_THREE_LEFT . '</li>'; }}}[/B] ?>

becomes:

<?php if ($products_quantity == 1) { echo '<li>' . TEXT_ONE_LEFT . '</li>'; } else { if ($products_quantity == 2) { echo '<li>' . TEXT_TWO_LEFT . '</li>'; } else [B]{ echo 'In Stock';}}[/B] ?>
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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Sep 2012, 8:49 PM
#29
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

Re: Show one left in stock message?

Works Awesome! Thank you Doc! I just sent you guys a few bucks :jump::jump:

I was wondering how I would go about putting one of those "bullet" dots like the others have into this? Also, would it be possible to make the fonts different colors? Green: In Stock, Yellow: Low Stock, Red: One left

1 Sep 2012, 9:11 PM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Show one left in stock message?

Those "bullet dots" are created by the <li> ... </li> tags wrapped around it.

So you could do this:```
} else { echo '[B]<li>[/B]In Stock[B]</li>[/B]';}}



or for consistency with the other defined phrases, maybe do this:```
} else { echo '[B]<li>[/B]' . TEXT_IN_STOCK . '[B]</li>[/B]';}}

And then that would allow you to add styling to those various phrases all in one place:

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>');

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Sep 2012, 8:45 PM
#31
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

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!

2 Sep 2012, 9:12 PM
#32
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Show one left in stock message?

Let's clean it up a bit:```

<?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>'; } ?>

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Sep 2012, 10:03 PM
#33
doooomed avatar

doooomed

Zen Follower

Join Date:
Jun 2009
Posts:
275
Plugin Contributions:
0

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.

3 Sep 2012, 5:06 AM
#34
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Show one left in stock message?

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".

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jun 2021, 9:30 PM
#35
fuzztrip avatar

fuzztrip

New Zenner

Join Date:
Jul 2020
Location:
USA
Posts:
88
Plugin Contributions:
0

Re: Show one left in stock message?

Hi, I have this working using mostly the following.

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 ...

<?php if ($products_quantity == 1) { echo '<li>' . TEXT_ONE_LEFT . '</li>'; } else { if ($products_quantity == 2) { echo '<li>' . TEXT_TWO_LEFT . '</li>'; } else [B]{ if ($products_quantity == 3) { echo '<li>' . TEXT_THREE_LEFT . '</li>'; }}}[/B] ?>

becomes:

<?php if ($products_quantity == 1) { echo '<li>' . TEXT_ONE_LEFT . '</li>'; } else { if ($products_quantity == 2) { echo '<li>' . TEXT_TWO_LEFT . '</li>'; } else [B]{ echo 'In Stock';}}[/B] ?>
> 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.
13 Jun 2021, 4:05 AM
#36
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Show one left in stock message?

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

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Jun 2021, 2:32 PM
#37
fuzztrip avatar

fuzztrip

New Zenner

Join Date:
Jul 2020
Location:
USA
Posts:
88
Plugin Contributions:
0

Re: Show one left in stock message?

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

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


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!

14 Jun 2021, 5:08 PM
#38
fuzztrip avatar

fuzztrip

New Zenner

Join Date:
Jul 2020
Location:
USA
Posts:
88
Plugin Contributions:
0

Re: Show one left in stock message?

I tried

 <?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

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.

14 Jun 2021, 5:59 PM
#39
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

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
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>';
                    }
            }
    }
?>
14 Jun 2021, 6:20 PM
#40
fuzztrip avatar

fuzztrip

New Zenner

Join Date:
Jul 2020
Location:
USA
Posts:
88
Plugin Contributions:
0

Re: Show one left in stock message?

lindasdd:

Because you used else instead of elseif, you don't have enough closed parenthesis. Try this (I didn't test it):

<?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!