-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add payment gateway order condition rule
- Loading branch information
1 parent
272475a
commit 1ad4c42
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Release Notes for Craft Commerce (WIP) | ||
|
||
## Administration | ||
|
||
- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/elements/conditions/orders/PaymentGatewayConditionRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace craft\commerce\elements\conditions\orders; | ||
|
||
use Craft; | ||
use craft\base\conditions\BaseMultiSelectConditionRule; | ||
use craft\base\conditions\BaseSelectConditionRule; | ||
use craft\base\ElementInterface; | ||
use craft\commerce\elements\db\OrderQuery; | ||
use craft\commerce\elements\Order; | ||
use craft\commerce\Plugin; | ||
use craft\elements\conditions\ElementConditionRuleInterface; | ||
use yii\db\QueryInterface; | ||
|
||
/** | ||
* Payment Gateway condition rule. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.3.0 | ||
*/ | ||
class PaymentGatewayConditionRule extends BaseSelectConditionRule implements ElementConditionRuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return Craft::t('commerce', 'Payment Gateway'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getExclusiveQueryParams(): array | ||
{ | ||
return ['gatewayId']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function options(): array | ||
{ | ||
return Plugin::getInstance()->getGateways()->getAllGateways()->mapWithKeys(function($gateway) { | ||
return [$gateway->id => $gateway->name]; | ||
})->all(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function modifyQuery(QueryInterface $query): void | ||
{ | ||
/** @var OrderQuery $query */ | ||
$query->gatewayId($this->value); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matchElement(ElementInterface $element): bool | ||
{ | ||
/** @var Order $element */ | ||
return $this->matchValue($element->gatewayId); | ||
Check failure on line 64 in src/elements/conditions/orders/PaymentGatewayConditionRule.php GitHub Actions / ci / Code Quality / PHPStan / PHPStan
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters