Jump to content

Show message text based on product quantity


rb10

Recommended Posts

Hi, I'd like to know if there's a way/form to display a message/image based on product availability, for example:

0 = NOT AVAILABLE / RED IMAGE

1 = LAST PIECE / ORANGE IMAGE

2-10 = MEDIUM QUANTITY / GREEN IMAGE

11-20 = GOOD AVAILABILITY / ETC.

21-100 = EXCELLENT AVAILABILITY / ETC.

Thank you all

Link to comment
Share on other sites

2 hours ago, rb10 said:

thanks for reply, but download not works

here is a general approach, you will need to customize to  meet your needs

 

Step 1: Edit your product template

Go to your theme’s template file:

For product pages:
/themes/your-theme/templates/catalog/product.tpl

For category/listing pages:
/themes/your-theme/templates/catalog/_partials/miniatures/product.tpl

Insert this code where you want the quantity message to appear:

{* PrestaHeroes Stock Status Message *}
{if $product.quantity == 0}
  <div class="stock-status out-of-stock">Not Available</div>
{elseif $product.quantity == 1}
  <div class="stock-status low-stock">Last piece!</div>
{elseif $product.quantity <= 10}
  <div class="stock-status medium-stock">Medium availability</div>
{elseif $product.quantity <= 20}
  <div class="stock-status good-stock">Good availability</div>
{else}
  <div class="stock-status in-stock">Excellent availability</div>
{/if}

Step 2: Add your CSS

Add the following to your theme’s CSS file:

.stock-status { font-weight: bold; margin: 10px 0; }
.out-of-stock { color: #d32f2f; }
.low-stock { color: #fbc02d; }
.medium-stock { color: #388e3c; }
.good-stock { color: #1976d2; }
.in-stock { color: #388e3c; }
 

Step 3: Make sure $product.quantity is available

On the product page, this variable is usually already available.

On category/listing pages, make sure your controller passes the quantity to the template.

 

Edited by El Patron (see edit history)
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...