Skip to content

Commit

Permalink
Fix not in query for customer condition rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Oct 10, 2023
1 parent b3f27a9 commit 4d3b836
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/elements/conditions/orders/CustomerConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use craft\elements\conditions\ElementConditionRuleInterface;
use craft\elements\db\ElementQueryInterface;
use craft\elements\User;
use craft\helpers\ArrayHelper;
use craft\helpers\Cp;
use craft\helpers\Db;
use yii\base\InvalidConfigException;
use yii\db\Expression;

/**
* Customer Condition Rule
Expand Down Expand Up @@ -85,10 +86,11 @@ public function modifyQuery(ElementQueryInterface $query): void
/** @var OrderQuery $query */
$paramValue = $this->paramValue();
if ($this->operator === self::OPERATOR_NOT_IN) {
ArrayHelper::prependOrAppend($paramValue, 'not', true);
// Account for the fact the querying using a combination of `not` and `in` doesn't match `null` in the column
$query->andWhere(Db::parseParam(new Expression('coalesce([[commerce_orders.customerId]], -1)'), $paramValue));
} else {
$query->customerId($paramValue);
}

$query->customerId($paramValue);
}

/**
Expand Down

0 comments on commit 4d3b836

Please sign in to comment.