Jump to content

Count of specific attribute per product on prestashop 1.7.8


Recommended Posts


I hope I am explaining this right

I am trying to display the number of combinations for a product on the catalog page.

For example i have a product that uses several attributes color/size/custom

For every product I want to count the number of options available for each product but only using a count of one of the attributes - in this case the custom attribute I have

I have tried the code in /templates/catalog/_partials/miniatures/_partials/product-miniature-2.tpl

{if $product.main_variants  && count($product.main_variants) > 1} combinations available{count($product.main_variants)}{/if}

but it seems as per the link here that it will only returns the color


so it wont work for me - it works as I would like but instead of the color I want my custom attribute count.  So basically if i have more than one custom attribute assigned to my product then I can display in the productcatalog list price from followed by a number of options available to the product


If you can point me in the correct direction that would be cool

theme warehouse/ presta 1.7.8


thank you in advance


Link to comment
Share on other sites


13 hours ago, isdngirl said:

{if $product.main_variants  && count($product.main_variants) > 1}

First of all, I don't understand what is the use of your first condition "$product.main_variants" knowing that after you count on it so if the result is greater than 1, then it exists.


However, have you tried to debug the variable $product.main_variants to know what it contains, if yes, can you send the result?

If I understood correctly you only want to count the custom attributes and not the basic ones?

Link to comment
Share on other sites

Yes maybe I need to explain a bit clearer sorry!

I have a catalog wiht 1000s of products

Each product has 3 attributes - color, size and package size

I want to show on the product list page that  when a product has more than one combination using the size attriibute that the text will be shown next to the price ; price starting from XXX

In addition for that same product on the product list tpl , where there are more than 1 combinations for the size attriibute that the text X(x=count of the number of size combinationsfor the product, not the quanity of articles in the combination)


So for example

Product 1 would have the following attributes color: grey, size =1, package size = 1 - total combinations = 1

Product 2 would have the following attributes :color: grey, yellow, black / size =1 / package size = 1 - so total 4 combinations using color attribute

example 2 works fine with 

{if $product.main_variants  && count($product.main_variants) > 1} combinations available{count($product.main_variants)}{/if}

Product 3  would have the following attributes color: grey / size =1, size =2 / package size = 1 - total 2 combinations using size attribute

I dont know how to make example 3 work because the product.main_variants only uses the attribute of color

Maybe that explains better? Maybe there is a module to do this sort of thing

thank you in advance


Link to comment
Share on other sites

Si vous n'y voyez pas de problème, en français ce sera sûrement mieux.

À moins de trouver dans quelle variable située dans "$product" les variations qui ne sont pas des couleurs sont stockés, je peux vous proposer de surcharger le Controller qui appelle cette fiche de listing produit afin d'ajouter les valeurs souhaitées dans le produits via l'utilisation de méthode ou via une requête SQL, ou encore, d'assigner une toute nouvelle variable contenant les valeurs dont vous avez besoin.

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