# Anzahl der Artikel in einer Kategorie

**URL:** <https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899>\
**Category:** Programmierung\
**Created:** [21. Februar 2020 um 09:52 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899 "2020-02-21T09:52:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![padaja](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@padaja](https://forum.shopware.com/u/padaja)\
**Post date:** [21. Februar 2020 um 09:52 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899/1 "2020-02-21T09:52:15Z")

</div>

Hallo,

wie finde ich die Anzahl der Artikel (aktive) in einer Kategorie heraus?  
Das muss ja irgendwas in der Richtung sein:&nbsp;

```
{$sCategories.childrenCount}
```

---

<div class="post-metadata">

**Author:** ![Antonio](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/antonio/32/14624_2.png) [@Antonio](https://forum.shopware.com/u/Antonio)\
**Post date:** [1. Juni 2022 um 08:02 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899/2 "2022-06-01T08:02:21Z")

</div>

push it \>\>\>\>\>\>\>\> interessiert mich auch sehr

---

<div class="post-metadata">

**Author:** ![hello](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hello](https://forum.shopware.com/u/hello)\
**Post date:** [6. Juli 2022 um 11:57 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899/3 "2022-07-06T11:57:08Z")

</div>

Wir haben dafür ein Smarty Plugin in THEME/\_private/smarty erstellt:

```auto
<?php
function smarty_modifier_getCategoryArticleCount($value, $format = array()) {
		
	$id = (int)$value;
	if ($id != 0) {
		
		$parameters = [
			'categoryId' => $id,
			'customerGroupId' => Shopware()->Shop()->getCustomerGroup()->getId()
		];
		
		$articleCount = Shopware()->Models()->getConnection()->fetchColumn("
			SELECT COUNT(DISTINCT s0_.id)
			FROM s_articles s0_ 
			INNER JOIN s_articles_categories_ro s2_ ON s0_.id = s2_.articleID 
			INNER JOIN s_categories s1_ ON s1_.id = s2_.categoryID AND (s1_.active = 1 AND s1_.id = :categoryId) 
			LEFT JOIN s_articles_avoid_customergroups s4_ ON s0_.id = s4_.articleID AND (s4_.customergroupID = :customerGroupId) 
			WHERE s0_.active = 1
			GROUP BY s4_.customergroupID, s1_.id 
			HAVING COUNT(s4_.customergroupID) = 0
		", $parameters);
		
	} else {
		$articleCount = NULL;
	}
	return $articleCount;

}

```

---

<div class="post-metadata">

**Author:** ![phil](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/phil/32/13661_2.png) [@phil](https://forum.shopware.com/u/phil)\
**Post date:** [12. Juli 2022 um 22:16 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899/4 "2022-07-12T22:16:32Z")

</div>

Nice. Denke es wäre noch gut zu ergänzen, wie man den Smarty-Modifier dann in einer tpl anspricht.

LG Phil

---

<div class="post-metadata">

**Author:** ![hello](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hello](https://forum.shopware.com/u/hello)\
**Post date:** [21. Juli 2022 um 09:28 UTC](https://forum.shopware.com/t/anzahl-der-artikel-in-einer-kategorie/64899/5 "2022-07-21T09:28:59Z")

</div>

Nutzung durch Übergabe der Kategorie ID (im Beispiel $catId):

```auto
$catId|getCategoryArticleCount

```
