Page 4 of 4 FirstFirst ... 234
Results 31 to 40 of 40
  1. #31
    Join Date
    Jun 2009
    Posts
    275
    Plugin Contributions
    0

    Default 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. #32
    Join Date
    Jan 2004
    Posts
    66,350
    Blog Entries
    7
    Plugin Contributions
    271

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

    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.

  3. #33
    Join Date
    Jun 2009
    Posts
    275
    Plugin Contributions
    0

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

  4. #34
    Join Date
    Jan 2004
    Posts
    66,350
    Blog Entries
    7
    Plugin Contributions
    271

    Default Re: Show one left in stock message?

    Quote Originally Posted by doooomed View Post
    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.

  5. #35
    Join Date
    Jul 2020
    Location
    USA
    Posts
    68
    Plugin Contributions
    0

    Default Re: Show one left in stock message?

    Hi, I have this working using mostly the following.

    Quote Originally Posted by DrByte View Post
    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.

  6. #36
    Join Date
    Jan 2004
    Posts
    66,350
    Blog Entries
    7
    Plugin Contributions
    271

    Default Re: Show one left in stock message?

    Quote Originally Posted by Fuzztrip View Post
    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.

  7. #37
    Join Date
    Jul 2020
    Location
    USA
    Posts
    68
    Plugin Contributions
    0

    Default Re: Show one left in stock message?

    Quote Originally Posted by DrByte View Post
    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"
    Click image for larger version. 

Name:	1.jpg 
Views:	6 
Size:	34.9 KB 
ID:	19620

    to "Low Stock"

    Click image for larger version. 

Name:	2.PNG 
Views:	5 
Size:	174.8 KB 
ID:	19621

    But when sold out it reads "In Stock"

    Click image for larger version. 

Name:	3.jpg 
Views:	5 
Size:	28.4 KB 
ID:	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!

  8. #38
    Join Date
    Jul 2020
    Location
    USA
    Posts
    68
    Plugin Contributions
    0

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

  9. #39
    Join Date
    Jun 2007
    Posts
    470
    Plugin Contributions
    1

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

  10. #40
    Join Date
    Jul 2020
    Location
    USA
    Posts
    68
    Plugin Contributions
    0

    Default Re: Show one left in stock message?

    Quote Originally Posted by lindasdd View Post
    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!

 

 
Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. v151 how to show one product if its different colors's size are out of stock?
    By kidultlearner in forum General Questions
    Replies: 6
    Last Post: 13 Aug 2016, 01:46 PM
  2. Stock by Attribute - Out of Stock Error Message
    By genxian in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 27 May 2011, 06:37 PM
  3. Want items to show out of stock after 5 items left
    By rickiesdiscount in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 21 Oct 2008, 02:54 AM
  4. Stock by attributes show stock levels placement error
    By fradesigns in forum General Questions
    Replies: 0
    Last Post: 17 Oct 2007, 01:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR