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

[4.8] Show archived gateways table #3847

Merged
Changes from 1 commit
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
Next Next commit
Show archived gateways table
nfourtythree committed Jan 14, 2025
commit 697cfe40447a41107dd26ca50a336612cb5f7aa1
5 changes: 4 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Release Notes for Craft Commerce 4.8 (WIP)
# Release Notes for Craft Commerce 4.8 (WIP)

### Extensibility
- Added `craft\commerce\services\Gateways\getAllArchivedGateways()`.
28 changes: 28 additions & 0 deletions src/controllers/GatewaysController.php
Original file line number Diff line number Diff line change
@@ -8,12 +8,16 @@
namespace craft\commerce\controllers;

use Craft;
use craft\base\MissingComponentInterface;
use craft\commerce\base\Gateway;
use craft\commerce\base\GatewayInterface;
use craft\commerce\db\Table;
use craft\commerce\gateways\Dummy;
use craft\commerce\helpers\DebugPanel;
use craft\commerce\Plugin;
use craft\db\Query;
use craft\errors\DeprecationException;
use craft\helpers\Html;
use craft\helpers\Json;
use yii\base\Exception;
use yii\base\InvalidConfigException;
@@ -32,9 +36,33 @@ class GatewaysController extends BaseAdminController
public function actionIndex(): Response
{
$gateways = Plugin::getInstance()->getGateways()->getAllGateways();
$archivedGateways = Plugin::getInstance()->getGateways()->getAllArchivedGateways();

if (!empty($archivedGateways)) {
$gatewayIdsWithTransactions = (new Query())
->select(['gatewayId'])
->from(Table::TRANSACTIONS)
->groupBy(['gatewayId'])
->column();

foreach ($archivedGateways as &$gateway) {
$missing = $gateway instanceof MissingComponentInterface;
$gateway = [
'id' => $gateway->id,
'title' => Craft::t('site', $gateway->name),
'handle' => Html::encode($gateway->handle),
'type' => [
'missing' => $missing,
'name' => $missing ? $gateway->expectedType : $gateway->displayName(),
],
'hasTransactions' => in_array($gateway->id, $gatewayIdsWithTransactions),
];
}
}

return $this->renderTemplate('commerce/settings/gateways/index', [
'gateways' => $gateways,
'archivedGateways' => array_values($archivedGateways),
]);
}

11 changes: 11 additions & 0 deletions src/services/Gateways.php
Original file line number Diff line number Diff line change
@@ -138,6 +138,17 @@ public function getAllGateways(): array
return ArrayHelper::where($this->_getAllGateways(), 'isArchived', false);
}

/**
* @return array
* @throws DeprecationException
* @throws InvalidConfigException
* @sine 4.8.0
*/
public function getAllArchivedGateways(): array
{
return ArrayHelper::where($this->_getAllGateways(), 'isArchived', true);
}

/**
* Archives a gateway by its ID.
*
53 changes: 51 additions & 2 deletions src/templates/settings/gateways/index.twig
Original file line number Diff line number Diff line change
@@ -18,8 +18,25 @@
<a href="{{ url('commerce/settings/gateways/new') }}" class="btn submit add icon">{{ 'New gateway'|t('commerce') }}</a>
{% endblock %}

{% block content %}
<div id="gateways-vue-admin-table"></div>
{% block main %}
<div id="content">

<div class="content-pane">
<div id="gateways-vue-admin-table"></div>
</div>
{% if archivedGateways|length %}
<p>
<a class="fieldtoggle"
data-target="archived-gateways">{{ 'Show archived gateways'|t('commerce') }}</a>
</p>

<div id="archived-gateways" class="hidden" style="margin-top: 22px;">
<div class="content-pane">
<div id="gateways-archived-vue-admin-table"></div>
</div>
</div>
{% endif %}
</div>
{% endblock %}

{% set tableData = [] %}
@@ -73,4 +90,36 @@
reorderFailMessage: Craft.t('commerce', 'Couldn’t reorder gateways.'),
tableData: {{ tableData|json_encode|raw }}
});

{% if archivedGateways|length %}
new Craft.VueAdminTable({
columns: [
{ name: 'id', title: Craft.t('commerce', 'ID') },
{ name: '__slot:title', title: Craft.t('commerce', 'Name') },
{ name: '__slot:handle', title: Craft.t('commerce', 'Handle') },
{
name: 'type',
title: Craft.t('commerce', 'Type'),
callback: function(value) {
if (value.missing) {
return '<span class="error">'+value.name+'</span>';
}

return value.name;
}
},
{
name: 'hasTransactions',
title: Craft.t('commerce', 'Has Transactions?'),
callback: function(value) {
if (value) {
return '<div data-icon="check" title="'+Craft.escapeHtml(Craft.t('commerce', 'Yes'))+'"></div>';
}
}
},
],
container: '#gateways-archived-vue-admin-table',
tableData: {{ archivedGateways|json_encode|raw }}
});
{% endif %}
{% endjs %}
2 changes: 2 additions & 0 deletions src/translations/en/commerce.php
Original file line number Diff line number Diff line change
@@ -464,6 +464,7 @@
'Has Emails?' => 'Has Emails?',
'Has Orders' => 'Has Orders',
'Has Purchasable' => 'Has Purchasable',
'Has Transactions?' => 'Has Transactions?',
'Has Variants?' => 'Has Variants?',
'Height ({unit})' => 'Height ({unit})',
'Height' => 'Height',
@@ -894,6 +895,7 @@
'Short Number' => 'Short Number',
'Show Chart?' => 'Show Chart?',
'Show Order Count?' => 'Show Order Count?',
'Show archived gateways' => 'Show archived gateways',
'Show order count line on chart.' => 'Show order count line on chart.',
'Show rule details' => 'Show rule details',
'Show the Dimensions and Weight fields for products of this type' => 'Show the Dimensions and Weight fields for products of this type',