# Kapitel 8.4 – eigener Condition Handler

**URL:** <https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066>\
**Category:** Shopware Academy\
**Tags:** shopware-das-handbuc\
**Created:** [13. Juli 2018 um 13:45 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066 "2018-07-13T13:45:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [13. Juli 2018 um 13:45 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/1 "2018-07-13T13:45:31Z")

</div>

Hallo,

versuche grade mittels eigener Condition Artikel zurück zu bekommen, die **nicht aktiv** sind. Leider klappt das nicht, da scheinbar in der Standard-Query schon auf active = 1 abgefragt wird. Wenn ich jetzt mit meiner Condition die Query erweitere um

```
...
$query->where('active = :active');
$query->setParameter(':active', 1);
...

```

erhalte ich die Fehlermeldung \_“Integrity constraint violation: 1052 Column ‘active’ in where clause is ambiguous’”.&nbsp;\_Kann ich in dem Fall irgendwie die Abfrage auf active aus der Standardabfrage neutralisieren, damit meine Condition greift und alle Artikel auswirft, die nicht aktiv sind?

Danke und Gruss,  
Oliver

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [13. Juli 2018 um 14:07 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/2 "2018-07-13T14:07:30Z")

</div>

muss das nicht so lauten? :&nbsp;

```
$query->setParameter('active',1);

```

EDIT: ggf auch so:

```
$query->setParameter('active',true);

```

ps: 0 = nicht aktiv, 1 = aktiv, true = aktiv ?

---

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [13. Juli 2018 um 14:15 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/3 "2018-07-13T14:15:10Z")

</div>

ich will ja in dem Fall alle Artikel ausgeben, die nicht aktiv sind, als active = false bzw. 0.

Das scheint sich dann mit der Standard-Query zu beißen, weil dort scheinbar schon ein active = 1 in der where-clause integriert ist, denke ich. Es müsste also eine Möglichkeit geben, die Condition aus der Standard-Query erst mal zu entfernen. Aber wie?&nbsp;

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [13. Juli 2018 um 14:22 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/4 "2018-07-13T14:22:08Z")

</div>

1. **:active** vs **active**
2. hast du mehrere&nbsp;Tabellen in der Query? ggf brauchst du -\>where(‚richtigetabelle.active = :active‘)

---

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [13. Juli 2018 um 14:29 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/5 "2018-07-13T14:29:24Z")

</div>

hab ich auch schon versucht&nbsp;-\>where(‚s\_articles.active = :active‘)

Wenn ich das ganze z.B. auf&nbsp;

$query-\>where(‚name = :name‘)  
$query-\>setParameter(’:name’, ‚irgendeinartikelname‘)

setze kommt der abgefragte Artikel im Frontend raus. Wie gesagt, nur mit dem active gehts nicht, da wie ich vermute&nbsp; in $query dann sowas entsteht WHERE active = 1 AND active = 0, was sich natürlich gegenseitig ausschließt und dann in einem&nbsp;_„Integrity constraint violation: 1052 Column ‚active‘ in where clause is ambiguous’“ endet_

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [13. Juli 2018 um 14:31 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/6 "2018-07-13T14:31:42Z")

</div>

poste bitte deine komplette query

---

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [13. Juli 2018 um 14:40 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/7 "2018-07-13T14:40:39Z")

</div>

&nbsp;

Anbei das gleiche was funktioniert und z.B. alle Artikel mit Namen Loremipsum ausgibt:

```
namespace MyTestPlugin\Components\SearchBundleDBAL\Condition;

use Shopware\Bundle\SearchBundle\ConditionInterface;
use Shopware\Bundle\SearchBundleDBAL\ConditionHandlerInterface;
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;
use Shopware\Bundle\StoreFrontBundle\Struct;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface;

class MyActiveConditionHandler implements ConditionHandlerInterface
{
    const ACTIVE_INCLUDED = 'my_active_included';

    /**
     * @inheritdoc
     */
    public function supportsCondition(ConditionInterface $condition)
    {
        return ($condition instanceof MyActiveCondition);
    }

    /**
     * @inheritdoc
     */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {

        if (!$query->hasState(self::ACTIVE_INCLUDED)) {
            $query->where('name = :name');
            $query->setParameter(':name', 'loremipsum');
            $query->addState(self::ACTIVE_INCLUDED);
        }
    }
}

```

&nbsp;

Anbei der ConditionHandler, der den SQL-Fehler schmeisst:

```
namespace MyTestPlugin\Components\SearchBundleDBAL\Condition;

use Shopware\Bundle\SearchBundle\ConditionInterface;
use Shopware\Bundle\SearchBundleDBAL\ConditionHandlerInterface;
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;
use Shopware\Bundle\StoreFrontBundle\Struct;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface;

class MyActiveConditionHandler implements ConditionHandlerInterface
{
    const ACTIVE_INCLUDED = 'my_active_included';

    /**
     * @inheritdoc
     */
    public function supportsCondition(ConditionInterface $condition)
    {
        return ($condition instanceof MyActiveCondition);
    }

    /**
     * @inheritdoc
     */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {

        if (!$query->hasState(self::ACTIVE_INCLUDED)) {
            $query->where('active = :active');
            $query->setParameter(':active', 1);
            $query->addState(self::ACTIVE_INCLUDED);
        }
    }
}

```

Also eigener Condition-Handler funktioniert offensichtlich, nur halt nicht auf die benötigte Spalte active ☹

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [13. Juli 2018 um 21:11 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/8 "2018-07-13T21:11:32Z")

</div>

? Das Problem steht doch direkt vor der Nase?

---

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [14. Juli 2018 um 07:18 UTC](https://forum.shopware.com/t/kapitel-8-4-eigener-condition-handler/54066/9 "2018-07-14T07:18:50Z")

</div>

sorry, aber im Moment nicht vor meiner 😉
