diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php
index 9dd7bc10b10..14281669660 100644
--- a/Setup/UpgradeData.php
+++ b/Setup/UpgradeData.php
@@ -6,13 +6,15 @@
namespace Mollie\Payment\Setup;
+use Magento\Sales\Setup\SalesSetupFactory;
+use Magento\Config\Model\ResourceModel\Config;
+use Magento\Store\Model\StoreManagerInterface;
+use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
-use Magento\Sales\Setup\SalesSetupFactory;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
-use Magento\Store\Model\StoreManagerInterface;
/**
* Class UpgradeData
@@ -28,6 +30,16 @@ class UpgradeData implements UpgradeDataInterface
*/
private $salesSetupFactory;
+ /**
+ * @var ResourceConnection
+ */
+ private $resourceConnection;
+
+ /**
+ * @var Config
+ */
+ private $resourceConfig;
+
/**
* @var WriterInterface
*/
@@ -42,15 +54,21 @@ class UpgradeData implements UpgradeDataInterface
* UpgradeData constructor.
*
* @param SalesSetupFactory $salesSetupFactory
+ * @param ResourceConnection $resourceConnection
+ * @param Config $resourceConfig
* @param WriterInterface $configWriter
* @param StoreManagerInterface $storeManager
*/
public function __construct(
SalesSetupFactory $salesSetupFactory,
+ ResourceConnection $resourceConnection,
+ Config $resourceConfig,
WriterInterface $configWriter,
StoreManagerInterface $storeManager
) {
$this->salesSetupFactory = $salesSetupFactory;
+ $this->resourceConnection = $resourceConnection;
+ $this->resourceConfig = $resourceConfig;
$this->configWriter = $configWriter;
$this->storeManager = $storeManager;
}
@@ -73,6 +91,10 @@ public function upgrade(
$this->removeBitcoinConfiguration();
}
+ if (version_compare($context->getVersion(), '1.6.1', '<')) {
+ $this->upgradeActiveState();
+ }
+
$setup->endSetup();
}
@@ -91,6 +113,55 @@ public function createMollieShipmentId($setup)
$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');
+ }
+
private function removeBitcoinConfiguration()
{
$paths = [
diff --git a/etc/config.xml b/etc/config.xml
index 4755e9b5096..9cb492f6700 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -17,7 +17,7 @@
0
- 0
+ 1
Mollie\Payment\Model\Methods\Bancontact
Bancontact
{ordernumber}
@@ -26,7 +26,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Banktransfer
Banktransfer
{ordernumber}
@@ -37,7 +37,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Belfius
Belfius
{ordernumber}
@@ -46,7 +46,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Creditcard
Credit Cards
{ordernumber}
@@ -55,7 +55,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Ideal
iDeal
{ordernumber}
@@ -65,7 +65,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Kbc
KBC/CBC
{ordernumber}
@@ -75,7 +75,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paypal
Paypal
{ordernumber}
@@ -84,7 +84,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paysafecard
Paysafecard
{ordernumber}
@@ -93,7 +93,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Sofort
Sofort
{ordernumber}
@@ -102,7 +102,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Inghomepay
ING Homepay
{ordernumber}
@@ -111,7 +111,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Giropay
Giropay
{ordernumber}
@@ -120,7 +120,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Eps
EPS
{ordernumber}
@@ -129,7 +129,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Klarnapaylater
Klarna Pay Later
{ordernumber}
@@ -139,7 +139,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Klarnasliceit
Klarna Slice It
{ordernumber}
@@ -149,7 +149,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Paymentlink
Mollie: Payment Link
{ordernumber}
@@ -160,7 +160,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Giftcard
Giftcard
{ordernumber}
@@ -170,7 +170,7 @@
- 0
+ 1
Mollie\Payment\Model\Methods\Przelewy24
Przelewy24
{ordernumber}