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 1 to 20 of 40
15 Apr 2012, 5:19 PM
#1
doooomed avatar

doooomed

Zen Follower

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

Show one left in stock message?

Is there a way to have a message automatically come up on the product page saying "only 1 left in stock" when the stock level reaches 1, instead of showing how many is in stock otherwise? I hope this makes sense lol. Any help is greatly appreciated!!!

16 Apr 2012, 11:08 AM
#2
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

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

16 Apr 2012, 11:42 AM
#3
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Show one left in stock message?

Nice one rbarbour :clap:! It may be a good idea to put the defines in a separate file

Will certainly keep this piece of code on file for future reference - thanks.

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Apr 2012, 11:55 AM
#4
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

thanks for the update that this works for you!

16 Apr 2012, 11:59 AM
#5
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

frank18:

It may be a good idea to put the defines either in a separate file.

I thought it was!

rbarbour:

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

Add:
PHP Code:

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

16 Apr 2012, 1:49 PM
#6
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Show one left in stock message?

Something like this:

includes/languages/english/extra_definitions/YOUR_TEMPLATE/one_left_defines.php

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

16 Apr 2012, 2:03 PM
#7
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

Gotcha - :cool:

23 Apr 2012, 8:51 PM
#8
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Thanks to everyone who replied! I have been trying different things to get this to work but am having no luck. The following seems to be the problem... (I think)

rbarbour:

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!

I follow everything up to /includes/languages/english but after that I don't have a your_template folder. I tried adding one and then creating a product_info.php file but still no luck. Anyone know what I'm doing wrong? I am using the Mostly Grey template and zencart version 1.3.9h

Thanks!
23 Apr 2012, 9:25 PM
#9
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

your_template = the Mostly Grey template name ( i think it is mostlygrey )

go to admin > tools > template selection

What does it say under Template Directory?

23 Apr 2012, 9:43 PM
#10
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Thanks for the reply. You are correct, it is mostlygrey, but as I said I go to /includes/languages/english and there is no mostlygrey folder or any other template folder. I created one and the product_info.php but had no luck getting it to work.

23 Apr 2012, 9:55 PM
#11
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

/includes/languages/english/mostlygrey/product_info.php

and the contents of product_info.php

are as follows:

<?php 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!'); ?>
23 Apr 2012, 10:01 PM
#12
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Correct, but still nothing...

23 Apr 2012, 10:06 PM
#13
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

If using above code, are you viewing a product with a quantity of 3 or less?

if not using above code, can you paste the code from your product_info file?

23 Apr 2012, 10:20 PM
#14
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Yes, I am using the above code and viewing products with less than 3

23 Apr 2012, 10:38 PM
#15
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

frank18 made a suggestion in post #6, you could try that.

I also use 1.3.9h with a highly customized template, so I do not know how to further troubleshoot with actually seeing.

Maybe someone else my have an idea

Something like this:

includes/languages/english/extra_definitions/YOUR_TEMPLATE/one_left_defines.php

23 Apr 2012, 10:42 PM
#16
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

I was going to try that but what do I put in the includes/languages/english/extra_definitions/YOUR_TEMPLATE/one_left_defines.php ?

This?

<?php 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!'); ?>
24 Apr 2012, 1:37 AM
#17
rbarbour avatar

rbarbour

Totally Zenned

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

Re: Show one left in stock message?

yepper - let me know if that worked

26 Apr 2012, 3:22 PM
#18
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Unfortunately no go on that one either, and it caused me to get a blank page when ever I tried to add something to the cart...strange! :blink:

29 Apr 2012, 3:12 PM
#19
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

Yup, still cannot get this to work for me...Anyone have any idea?

16 Aug 2012, 2:42 PM
#20
doooomed avatar

doooomed

Zen Follower

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

Re: Show one left in stock message?

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. I tried various things like deleting define('TEXT_THREE_LEFT', 'Hurry, while supplies last!'); and
"if ($products_quantity == 3) {
echo '<li>' . TEXT_THREE_LEFT . '</li>';
} else { (from tpl_product_info_display.php)

but every change I make produces a blank page. Any ideas? Thank you!