How to get number how much products are in vendor?

I want to display like this :

I get all vendors, but I don’t count how much product are in current vendor.

I am trying like this:

{% assign vendorProducts = collection.products.size | where: ‘vendor’, vendor %}

{{ vendor }} {% assign productCount = vendorProducts.size %} ({{ productCount }})

Maybe any soliution?

Hey @kestas97

To count the number of products for each vendor in your Shopify collection, you can modify your Liquid code as follows:

{% for vendor in collection.products | map: 'vendor' | uniq %}
  {% assign vendorProducts = collection.products | where: 'vendor', vendor %}
  
    {{ vendor }}
    {% assign productCount = vendorProducts.size %}
    ({{ productCount }})
  

{% endfor %}

In the updated code, the {% for %} loop iterates over each unique vendor in the collection’s products. For each vendor, it assigns the products associated with that vendor to the vendorProducts variable using the where filter.

Then, the productCount variable is assigned the size of the vendorProducts array, which represents the number of products for that particular vendor. This count is displayed within the element.

By making these changes, you should be able to count the number of products for each vendor correctly.

If I managed to help you then, don’t forget to Like it and Mark it as Solution!

Best Regards,
Moeed