Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions src/elements/conditions/orders/PaymentGatewayConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +17,7 @@
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.3.0
*/
class PaymentGatewayConditionRule extends BaseSelectConditionRule implements ElementConditionRuleInterface
class PaymentGatewayConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface
{
/**
* @inheritdoc
Expand Down Expand Up @@ -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));
}
}

/**
Expand Down
Loading