Results 1 to 10 of 40

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Posts
    66,380
    Blog Entries
    7
    Plugin Contributions
    274

    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.

  2. #2
    Join Date
    Jul 2020
    Location
    USA
    Posts
    88
    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:	31 
Size:	34.9 KB 
ID:	19620

    to "Low Stock"

    Click image for larger version. 

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

    But when sold out it reads "In Stock"

    Click image for larger version. 

Name:	3.jpg 
Views:	32 
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!

  3. #3
    Join Date
    Jul 2020
    Location
    USA
    Posts
    88
    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.

  4. #4
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

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

  5. #5
    Join Date
    Jul 2020
    Location
    USA
    Posts
    88
    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!

 

 

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