Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Reports #3628

Draft
wants to merge 8 commits into
base: 5.x
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions CHANGELOG-5.2-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Release Notes for Craft Commerce 5.2 (WIP)

### Store Management

### Administration

### Extensibility

### System

5 changes: 5 additions & 0 deletions CHANGELOG-WIP.md
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))
13 changes: 8 additions & 5 deletions src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,11 +1384,14 @@ private function _registerJavascript(array $variables): void
Craft::$app->getView()->registerJs('window.orderEdit.defaultShippingCategoryId = ' . Json::encode($defaultShippingCategoryId) . ';', View::POS_BEGIN);

$currentUser = Craft::$app->getUser()->getIdentity();
$permissions = [
'commerce-manageOrders' => $currentUser->can('commerce-manageOrders'),
'commerce-editOrders' => $currentUser->can('commerce-editOrders'),
'commerce-deleteOrders' => $currentUser->can('commerce-deleteOrders'),
];

$permissions = ArrayHelper::map([
'editUsers',
'commerce-manageOrders',
'commerce-editOrders',
'commerce-deleteOrders',
], fn($permission) => $permission, fn($permission) => Craft::$app->getUser()->getIdentity()->can($permission));

Craft::$app->getView()->registerJs('window.orderEdit.currentUserPermissions = ' . Json::encode($permissions) . ';', View::POS_BEGIN);
Craft::$app->getView()->registerJs('window.orderEdit.currentUserId = ' . Json::encode($currentUser->id) . ';', View::POS_BEGIN);

Expand Down
1 change: 1 addition & 0 deletions src/elements/conditions/orders/OrderCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function selectableConditionRules(): array
ItemTotalConditionRule::class,
OrderStatusConditionRule::class,
OrderSiteConditionRule::class,
PaymentGatewayConditionRule::class,
ReferenceConditionRule::class,
ShippingMethodConditionRule::class,
TotalDiscountConditionRule::class,
Expand Down
67 changes: 67 additions & 0 deletions src/elements/conditions/orders/PaymentGatewayConditionRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace craft\commerce\elements\conditions\orders;

use Craft;
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->uid => $gateway->name];
})->all();
}

/**
* @inheritdoc
*/
public function modifyQuery(QueryInterface $query): void
{
$gateway = Plugin::getInstance()->getGateways()->getAllGateways()->firstWhere('uid', $this->value);
/** @var OrderQuery $query */
$query->gatewayId($gateway->id);
}

/**
* @inheritdoc
*/
public function matchElement(ElementInterface $element): bool
{
/** @var Order $element */
$gatewayUid = $element->getGateway()?->uid;
return $this->matchValue($gatewayUid);
}
}
1 change: 1 addition & 0 deletions src/translations/en/commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@
'Payment Amount' => 'Payment Amount',
'Payment Currencies' => 'Payment Currencies',
'Payment Method' => 'Payment Method',
'Payment Gateway' => 'Payment Gateway',
'Payment error: {message}' => 'Payment error: {message}',
'Payment method issue' => 'Payment method issue',
'Payment source created.' => 'Payment source created.',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
{{ getDisplayName(false) }}
</div>
<div class="w-full light">{{ customer.email }}</div>
<div class="w-full" v-if="display && customer.cpEditUrl">
<div
class="w-full"
v-if="
display &&
customer.cpEditUrl &&
currentUserPermissions.editUsers
"
>
<a :href="customer.cpEditUrl" v-if="customer.cpEditUrl">{{
$options.filters.t('View customer', 'commerce')
}}</a>
Expand All @@ -46,6 +53,8 @@
</template>

<script>
import {mapGetters} from 'vuex';

export default {
props: {
customer: {
Expand Down Expand Up @@ -114,6 +123,8 @@
},

computed: {
...mapGetters(['currentUserPermissions']),

initialChar() {
const displayName = this.getDisplayName();
if (!displayName) {
Expand Down
Loading