# Criteria funktioniert mit im Falle von "ähnliche Artikel" nicht

**URL:** <https://forum.shopware.com/t/criteria-funktioniert-mit-im-falle-von-aehnliche-artikel-nicht/89747>\
**Category:** Programmierung\
**Created:** [13. August 2021 um 11:45 UTC](https://forum.shopware.com/t/criteria-funktioniert-mit-im-falle-von-aehnliche-artikel-nicht/89747 "2021-08-13T11:45:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RomanReimche](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@RomanReimche](https://forum.shopware.com/u/RomanReimche)\
**Post date:** [13. August 2021 um 11:45 UTC](https://forum.shopware.com/t/criteria-funktioniert-mit-im-falle-von-aehnliche-artikel-nicht/89747/1 "2021-08-13T11:45:42Z")

</div>

Hallo,

ich habe ein Plugin geschrieben, das Criteria/Condition dafür verwendet, nur die Artikel in Listings anzuzeigen, die Lieferzeit kleiner eines bestimmten Wertes haben. Das funktioniert im Allgemeinen gut, aber hat anscheinend keinen Effekt auf den Block „Ähnliche Artikel“, wo standardmäßig die Ähnlichkeit laut Shopware Doku nach Kategorie bestimmt wird. So sieht MeinConditionHandler-\>generateCondition() aus:

```auto
public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {

        $minLieferzeit = 120;

        if (!$query->hasState(self::STATE_INCLUDED)) {

            $query->innerJoin(
                 'product',
                 's_articles_details',
                 'details',
                 'details.articleID = product.id'
            );

            $query->andWhere("details.shippingtime < $minLieferzeit"); 

            $query->addState(self::STATE_INCLUDED);
        }
    }

```

So sieht die $query-\>getSQL() aus, wenn ich es an dieser Stelle mit die($query-\>getSQL()) ausgebe:

```auto
SELECT FROM s_articles product INNER JOIN s_articles_details variant ON variant.id = product.main_detail_id AND variant.active = 1 AND product.active = 1 INNER JOIN s_articles_categories_ro productCategory ON productCategory.articleID = product.id AND productCategory.categoryID IN (:productCategory) LEFT JOIN s_articles_avoid_customergroups avoidCustomerGroup ON avoidCustomerGroup.articleID = product.id AND avoidCustomerGroup.customerGroupId IN (:customerGroupIds11111111111111111111) INNER JOIN s_articles_details details ON details.articleID = product.id INNER JOIN s_articles_attributes productAttribute ON productAttribute.articledetailsID = variant.id WHERE (avoidCustomerGroup.articleID IS NULL) AND (details.shippingtime < 120)

```

(111111111111111 – hier habe ich die tatsächliche Zahlen geändert)

Wie könnte ich das Problem lösen?

---

<div class="post-metadata">

**Author:** ![RomanReimche](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@RomanReimche](https://forum.shopware.com/u/RomanReimche)\
**Post date:** [13. August 2021 um 12:15 UTC](https://forum.shopware.com/t/criteria-funktioniert-mit-im-falle-von-aehnliche-artikel-nicht/89747/2 "2021-08-13T12:15:26Z")

</div>

Ein bisschen erweiterte Infos. Der Block ist bei uns keine Ajax-Block, sondern verwendet /frontend/includes/product\_slider\_items.tpl. Was aber wieder keinen Tipp gibt, warum Criteria keinen Effekt hat…

---

<div class="post-metadata">

**Author:** ![RomanReimche](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@RomanReimche](https://forum.shopware.com/u/RomanReimche)\
**Post date:** [13. August 2021 um 12:21 UTC](https://forum.shopware.com/t/criteria-funktioniert-mit-im-falle-von-aehnliche-artikel-nicht/89747/3 "2021-08-13T12:21:10Z")

</div>

Wahrscheinlich habe ich doch eine Idee. Die [Doku von SearchBundle](https://developers.shopware.com/developers-guide/shopware-5-search-bundle/) git uns die Liste von den Kontexten, wo Criteria Effekt hat:

- Search
- Listing
- AjaxSearch
- AjaxListing
- AjaxCount
- ProductNavigation

Ich vermute, der Controller Shopware\_Controllers\_Frontend\_Detail hat einfach nichts damit zu tun und deshalb wird Criteria nicht angewandt. Ist die Denkweise richtig? Oder doch hat er etwas mit ProductNavigation zu tun?
