From 697cfe40447a41107dd26ca50a336612cb5f7aa1 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 14 Jan 2025 07:50:59 +0000 Subject: [PATCH 1/2] Show archived gateways table --- CHANGELOG-WIP.md | 5 +- src/controllers/GatewaysController.php | 28 ++++++++++++ src/services/Gateways.php | 11 +++++ src/templates/settings/gateways/index.twig | 53 +++++++++++++++++++++- src/translations/en/commerce.php | 2 + 5 files changed, 96 insertions(+), 3 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 37efffc910..83aa03d3cf 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1 +1,4 @@ -# Release Notes for Craft Commerce 4.8 (WIP) \ No newline at end of file +# Release Notes for Craft Commerce 4.8 (WIP) + +### Extensibility +- Added `craft\commerce\services\Gateways\getAllArchivedGateways()`. \ No newline at end of file diff --git a/src/controllers/GatewaysController.php b/src/controllers/GatewaysController.php index 5c6b084fa9..e42dfd5bfb 100644 --- a/src/controllers/GatewaysController.php +++ b/src/controllers/GatewaysController.php @@ -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), ]); } diff --git a/src/services/Gateways.php b/src/services/Gateways.php index e0cdac9cb4..d49dce97c9 100644 --- a/src/services/Gateways.php +++ b/src/services/Gateways.php @@ -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. * diff --git a/src/templates/settings/gateways/index.twig b/src/templates/settings/gateways/index.twig index ccc76a7668..f72929180f 100644 --- a/src/templates/settings/gateways/index.twig +++ b/src/templates/settings/gateways/index.twig @@ -18,8 +18,25 @@ {{ 'New gateway'|t('commerce') }} {% endblock %} -{% block content %} -
+{% block main %} +
+ +
+
+
+ {% if archivedGateways|length %} +

+ {{ 'Show archived gateways'|t('commerce') }} +

+ + + {% endif %} +
{% 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 ''+value.name+''; + } + + return value.name; + } + }, + { + name: 'hasTransactions', + title: Craft.t('commerce', 'Has Transactions?'), + callback: function(value) { + if (value) { + return '
'; + } + } + }, + ], + container: '#gateways-archived-vue-admin-table', + tableData: {{ archivedGateways|json_encode|raw }} + }); + {% endif %} {% endjs %} diff --git a/src/translations/en/commerce.php b/src/translations/en/commerce.php index 3b3d97cba9..c52f4dadf3 100644 --- a/src/translations/en/commerce.php +++ b/src/translations/en/commerce.php @@ -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', From 27877db5d7344c115ec2fca7bb8b5f4e99f7029b Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 14 Jan 2025 07:53:57 +0000 Subject: [PATCH 2/2] Changelog --- CHANGELOG-WIP.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 83aa03d3cf..81a0099ca5 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1,4 +1,7 @@ # Release Notes for Craft Commerce 4.8 (WIP) +### Store Management +- It is now possible to see archived gateways listed in the control panel. ([#3839](https://github.com/craftcms/commerce/issues/3839)) + ### Extensibility - Added `craft\commerce\services\Gateways\getAllArchivedGateways()`. \ No newline at end of file