Skip to content

Commit

Permalink
Merge branch '4.8' into feature/4.8-tax-id-validators
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG-WIP.md
  • Loading branch information
lukeholder committed Jan 22, 2025
2 parents 96f0d56 + b542f43 commit 0673e0b
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# 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
- It is now possible to register custom tax ID validators.
- Added `craft\commerce\services\Gateways\getAllArchivedGateways()`.
- Added `craft\commerce\base\TaxIdValidatorInterface`.
- Added `craft\commerce\taxidvalidators\EuVatIdValidator`.
- Added `craft\commerce\services\Taxes::EVENT_REGISTER_TAX_ID_VALIDATORS`.
- Added `\craft\commerce\services\Taxes::getTaxIdValidators()`.
- Added `\craft\commerce\services\Taxes::getEnabledTaxIdValidators()`.
- Added `\craft\commerce\services\Taxes::getEnabledTaxIdValidators()`.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Improved the performance of recalculating shipping method prices. ([#3841](https://github.com/craftcms/commerce/pull/3841))
- Fixed a bug where Edit Product pages would allow duplication for users that didn’t have permission to duplicate the product. ([#3819](https://github.com/craftcms/commerce/issues/3819))
- Fixed a PHP error that could occur when updating a cart. ([#3842](https://github.com/craftcms/commerce/issues/3842))
- Fixed a PHP error that could occur when adding an invalid address to a cart. ([#3848](https://github.com/craftcms/commerce/issues/3848))

## 4.7.2 - 2024-12-18
Expand Down
1 change: 1 addition & 0 deletions src/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function actionUpdateCart(): ?Response

// When we are about to update the cart, we consider it a real cart at this point, and want to actually create it in the DB.
if ($this->_cart->id === null) {
// Make sure we have a fully saved cart before attempting any mutations.
$this->_cart = $this->_getCart(true);
}

Expand Down
28 changes: 28 additions & 0 deletions src/controllers/GatewaysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
]);
}

Expand Down
11 changes: 11 additions & 0 deletions src/services/Gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
53 changes: 51 additions & 2 deletions src/templates/settings/gateways/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [] %}
Expand Down Expand Up @@ -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
Expand Up @@ -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',
Expand Down Expand Up @@ -893,6 +894,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',
Expand Down

0 comments on commit 0673e0b

Please sign in to comment.