diff --git a/CHANGELOG.md b/CHANGELOG.md index 21e7c8f5b1..ea467fbb79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added the `commerce/gateways/webhook-url` command. - Fixed a bug where the delete button would be shown for users that do not have permission to delete on the Product edit page. ([#3285](https://github.com/craftcms/commerce/issues/3285)) - Fixed a bug where deleted shipping categories were still available for selection. ([#3272](https://github.com/craftcms/commerce/issues/3272)) +- Fixed a bug where the customer condition rule wasn’t loading correctly. ([#3291](https://github.com/craftcms/commerce/issues/3291)) - Fixed an error that could occur when rendering a PDF. ([#2633](https://github.com/craftcms/commerce/issues/2633)) - Fixed a bug where duplicate inactive users could be created when using the `commerce/upgrade` command. ([#3286](https://github.com/craftcms/commerce/issues/3286)) diff --git a/src/elements/conditions/orders/CustomerConditionRule.php b/src/elements/conditions/orders/CustomerConditionRule.php index 02aa7d9ac4..00248bfc69 100644 --- a/src/elements/conditions/orders/CustomerConditionRule.php +++ b/src/elements/conditions/orders/CustomerConditionRule.php @@ -15,13 +15,17 @@ use craft\elements\conditions\ElementConditionRuleInterface; use craft\elements\db\ElementQueryInterface; use craft\elements\User; +use craft\helpers\Cp; +use craft\helpers\Db; use yii\base\InvalidConfigException; +use yii\db\Expression; /** * Customer Condition Rule * * @author Pixel & Tonic, Inc. * @since 4.2.0 + * @TODO change the class that the `CustomerConditionRule` extends */ class CustomerConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface { @@ -35,6 +39,7 @@ public function getLabel(): string /** * @return array + * @deprecated in 4.3.1. */ protected function options(): array { @@ -47,6 +52,24 @@ protected function options(): array ->all(); } + /** + * @inheritDoc + */ + protected function inputHtml(): string + { + $users = User::find()->status(null)->limit(null)->id($this->values)->all(); + + return Cp::elementSelectHtml([ + 'name' => 'values', + 'elements' => $users, + 'elementType' => User::class, + 'sources' => null, + 'criteria' => null, + 'condition' => null, + 'single' => false, + ]); + } + /** * @inheritdoc */ @@ -63,10 +86,11 @@ public function modifyQuery(ElementQueryInterface $query): void /** @var OrderQuery $query */ $paramValue = $this->paramValue(); if ($this->operator === self::OPERATOR_NOT_IN) { - $paramValue = ['or', $paramValue, null]; + // 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); } /**