Jump to content

Display quantity in special category


Thomas Will

Recommended Posts

Hello, I would like to display the available quantity only in certain categories.

I've tried the following (product.tpl / Presta 1.6.1.1) ... 

{if in_array($category.id, array(59)}{$product->quantity}{/if}

unfortunately, without success. Does anyone have an idea for me?

 

Thomas

Link to comment
Share on other sites

Now I've tried the following... 

This only displays the quantity if the article is in category 169, but unfortunately the total quantity is displayed and not the quantity for each attribute.

 

{if ($display_qties  ==  1 && $pproperties.pp_qty_available_display != 2 && !$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && $product->available_for_order && $category->id is in [169])}
                                <!-- number of item in stock -->
                                <p id="pQuantityAvailable"{if $product->quantity <= 0} style="display: none;"{/if}>
                                    <span id="quantityAvailable">{$product->quantity|intval}</span>
                                    <span {if $product->quantity > 1} style="display: none;"{/if} id="quantityAvailableTxt">{l s='Item'} verfügbar</span>
                                    <span {if $product->quantity == 1} style="display: none;"{/if} id="quantityAvailableTxtMultiple">{l s='Items'} verfügbar</span>
                                </p>
{/if}

 

does anyone have an idea for me

Link to comment
Share on other sites

To display the quantity in a special category, you’ll likely need to customize the template file for that specific category. You can do this by editing the relevant .tpl file (usually product-list.tpl or category.tpl depending on your theme) and insert the following line where you want the quantity to appear:

{$product.quantity}

Make sure your product array includes the quantity data. You may also need to enable or adjust the displayProductQuantity in the product listing loop if it’s not already available.

Don’t forget to clear the cache after making changes. Let me know if you need help locating the exact file in your theme.

Link to comment
Share on other sites

Thank you very much.
The quantity is already displayed on the page (product.tpl) – see image/attachment. Unfortunately, the total quantity (above Quantity) of all items ("2 Artikel verfügbar") is displayed, not the quantity of the variant (as in the left column, "1 Artikel").

 

Screenshot2025-03-23111814.png.da9f08ab65f826b82cf7f9ff2d3783c5.png

Link to comment
Share on other sites

Hi @Thomas Will

If you want to display the available count for a selected combination or attribute, it's not that simple. What you see in the detail is not the same template. It can be done via js or a custom hook.

Prestashop 1.6

find file: ./themes/default-bootstrap/js/product.js

find function: updateDisplay()

find query: 

$('#quantityAvailable').text(quantityAvailable);

add your element:

$('#quantityAvailableBeforeQuantitySelected').text(quantityAvailable);

image.png.cc10c7574cced988497122a0aed214e8.png

 

add to TPL: ./themes/default-bootstrap/product.tpl

image.png.593be9c7be633bc24eb373797345ce7b.png

 

Edited by ps8modules (see edit history)
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...