diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index eaba982a22..00bca7abf7 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -4,6 +4,8 @@ ### Administration +- Gateway condition rules now allow multiple gateways to be selected. ([#4112](https://github.com/craftcms/commerce/issues/4112)) + ### Development ### Extensibility diff --git a/src/elements/conditions/orders/PaymentGatewayConditionRule.php b/src/elements/conditions/orders/PaymentGatewayConditionRule.php index b859fb8d0c..d26d4aa54f 100644 --- a/src/elements/conditions/orders/PaymentGatewayConditionRule.php +++ b/src/elements/conditions/orders/PaymentGatewayConditionRule.php @@ -3,7 +3,7 @@ namespace craft\commerce\elements\conditions\orders; use Craft; -use craft\base\conditions\BaseSelectConditionRule; +use craft\base\conditions\BaseMultiSelectConditionRule; use craft\base\ElementInterface; use craft\commerce\elements\db\OrderQuery; use craft\commerce\elements\Order; @@ -17,7 +17,7 @@ * @author Pixel & Tonic, Inc. * @since 5.3.0 */ -class PaymentGatewayConditionRule extends BaseSelectConditionRule implements ElementConditionRuleInterface +class PaymentGatewayConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface { /** * @inheritdoc @@ -48,9 +48,20 @@ protected function options(): array */ public function modifyQuery(QueryInterface $query): void { - $gateway = Plugin::getInstance()->getGateways()->getAllGateways()->firstWhere('uid', $this->value); - /** @var OrderQuery $query */ - $query->gatewayId($gateway->id); + $gatewayIds = []; + $gateways = Plugin::getInstance()->getGateways()->getAllGateways(); + + foreach ($this->getValues() as $uid) { + $gateway = $gateways->firstWhere('uid', $uid); + if ($gateway) { + $gatewayIds[] = $gateway->id; + } + } + + if (!empty($gatewayIds)) { + /** @var OrderQuery $query */ + $query->gatewayId($this->paramValue(fn($uid) => $gateways->firstWhere('uid', $uid)?->id)); + } } /**