Thread tagged as: Question, Shop

Count products inside brand

Sounds really simple. Don't know how to do it.

Is there a way to count the amount of products a brand has?

Lexi McGee

Lexi McGee 3 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not a built in way, but yes it can be done.

What's the context? Do you need to do just one or many? This would affect the method.

Well. All brands. Got thousands of products distributed in about 20 brands. What's the fastest way? Is it going to be slow because the brands are serialized into the productDynamicFields column?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, they're also indexed. It's slow because you'll need to get all the products to count them, even though they're not being used. The process would be

  1. Get all brands
  2. For each brand...
  3. Get all products by brand
  4. Count the products

Obviously it would be much quicker with a dedicated function, but that doesn't exist right now.