diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php
index ceb591fd1b6..bcc7c10a07a 100644
--- a/Setup/UpgradeData.php
+++ b/Setup/UpgradeData.php
@@ -6,6 +6,8 @@
namespace Mollie\Payment\Setup;
+use Magento\Config\Model\ResourceModel\Config;
+use Magento\Framework\App\ResourceConnection;
use Magento\Sales\Setup\SalesSetupFactory;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
@@ -26,15 +28,31 @@ class UpgradeData implements UpgradeDataInterface
*/
private $salesSetupFactory;
+ /**
+ * @var ResourceConnection
+ */
+ private $resourceConnection;
+
+ /**
+ * @var Config
+ */
+ private $resourceConfig;
+
/**
* UpgradeData constructor.
*
* @param SalesSetupFactory $salesSetupFactory
+ * @param ResourceConnection $resourceConnection
+ * @param Config $resourceConfig
*/
public function __construct(
- SalesSetupFactory $salesSetupFactory
+ SalesSetupFactory $salesSetupFactory,
+ ResourceConnection $resourceConnection,
+ Config $resourceConfig
) {
$this->salesSetupFactory = $salesSetupFactory;
+ $this->resourceConnection = $resourceConnection;
+ $this->resourceConfig = $resourceConfig;
}
/**
@@ -51,6 +69,10 @@ public function upgrade(
$this->createMollieShipmentId($setup);
}
+ if (version_compare($context->getVersion(), '1.5.3', '<')) {
+ $this->upgradeActiveState();
+ }
+
$setup->endSetup();
}
@@ -68,4 +90,53 @@ public function createMollieShipmentId($setup)
$options = ['type' => 'varchar', 'visible' => false, 'required' => false];
$salesSetup->addAttribute('shipment', 'mollie_shipment_id', $options);
}
+
+ /**
+ * See https://github.com/magento/magento2/issues/22231
+ * This is part of a fix that sets the default of the active config to 1 instead of 0. That's why we extract the
+ * current value from the database. If that is not 1 we set the value in the database to 0. This is to prevent
+ * that we turn on payment methods that are not active.
+ */
+ private function upgradeActiveState()
+ {
+ $paths = [
+ 'payment/mollie_methods_bancontact/active',
+ 'payment/mollie_methods_banktransfer/active',
+ 'payment/mollie_methods_belfius/active',
+ 'payment/mollie_methods_bitcoin/active',
+ 'payment/mollie_methods_creditcard/active',
+ 'payment/mollie_methods_ideal/active',
+ 'payment/mollie_methods_kbc/active',
+ 'payment/mollie_methods_paypal/active',
+ 'payment/mollie_methods_paysafecard/active',
+ 'payment/mollie_methods_sofort/active',
+ 'payment/mollie_methods_inghomepay/active',
+ 'payment/mollie_methods_giropay/active',
+ 'payment/mollie_methods_eps/active',
+ 'payment/mollie_methods_klarnapaylater/active',
+ 'payment/mollie_methods_klarnasliceit/active',
+ 'payment/mollie_methods_paymentlink/active',
+ 'payment/mollie_methods_giftcard/active',
+ 'payment/mollie_methods_przelewy24/active',
+ ];
+
+ foreach ($paths as $path) {
+ $this->setCorrectWebsiteDefault($path);
+ }
+ }
+
+ private function setCorrectWebsiteDefault($path)
+ {
+ $connection = $connection = $this->resourceConnection->getConnection();
+ $tableName = $this->resourceConnection->getTableName('core_config_data');
+
+ $query = 'select value from ' . $tableName . ' where scope = "default" and path = :path';
+ $result = $connection->fetchOne($query, ['path' => $path]);
+
+ if ($result !== false) {
+ return;
+ }
+
+ $this->resourceConfig->saveConfig($path, '0', 'default');
+ }
}
diff --git a/etc/config.xml b/etc/config.xml
index 68fd3380305..564ccfd5f23 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -16,7 +16,7 @@
1
- 0
+ 1
Mollie\Payment\Model\Methods\Bancontact
Bancontact
{ordernumber}
@@ -25,7 +25,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Banktransfer
Banktransfer
{ordernumber}
@@ -36,7 +36,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Belfius
Belfius
{ordernumber}
@@ -45,7 +45,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Bitcoin
Bitcoin
{ordernumber}
@@ -54,7 +54,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Creditcard
Credit Cards
{ordernumber}
@@ -63,7 +63,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Ideal
iDeal
{ordernumber}
@@ -73,7 +73,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Kbc
KBC/CBC
{ordernumber}
@@ -83,7 +83,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paypal
Paypal
{ordernumber}
@@ -92,7 +92,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paysafecard
Paysafecard
{ordernumber}
@@ -101,7 +101,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Sofort
Sofort
{ordernumber}
@@ -110,7 +110,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Inghomepay
ING Homepay
{ordernumber}
@@ -119,7 +119,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Giropay
Giropay
{ordernumber}
@@ -128,7 +128,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Eps
EPS
{ordernumber}
@@ -137,7 +137,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Klarnapaylater
Klarna Pay Later
{ordernumber}
@@ -147,7 +147,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Klarnasliceit
Klarna Slice It
{ordernumber}
@@ -157,7 +157,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paymentlink
Mollie: Payment Link
{ordernumber}
@@ -168,7 +168,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Giftcard
Giftcard
{ordernumber}
@@ -178,7 +178,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Przelewy24
Przelewy24
{ordernumber}
diff --git a/etc/module.xml b/etc/module.xml
index cfb6c3123ec..7b775d6fc33 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -1,4 +1,4 @@
-
+