From da018f90005bec056ad45db1ee271c3f72e57b9f Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Fri, 17 May 2019 19:56:28 +0200 Subject: [PATCH 1/3] Change the default of the active configuration to show the payment methods correctly in the order grid --- Setup/UpgradeData.php | 73 ++++++++++++++++++++++++++++++++++++++++++- etc/config.xml | 36 ++++++++++----------- etc/module.xml | 2 +- 3 files changed, 91 insertions(+), 20 deletions(-) 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 @@ - + From fb9f9d9a39aa0b20a1562ed0d5ac30919bace065 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 3 Jun 2019 19:23:25 +0200 Subject: [PATCH 2/3] Version bump --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 234053e4bde..c4d082963b5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/magento2", "description": "Mollie Payment Module for Magento 2", - "version": "1.5.2", + "version": "1.6.1", "require": { "mollie/mollie-api-php": "^2.1", "magento/framework": ">=100.1.0", diff --git a/etc/module.xml b/etc/module.xml index ca6c6d1b03b..ed98c71c491 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - + From 228537cff1894af78a7dfdb9e1a65e66f795080f Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 3 Jun 2019 20:18:23 +0200 Subject: [PATCH 3/3] Set the default scope id as this is not set in all Magento versions --- Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 14281669660..613c1342c74 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -159,7 +159,7 @@ private function setCorrectWebsiteDefault($path) return; } - $this->resourceConfig->saveConfig($path, '0', 'default'); + $this->resourceConfig->saveConfig($path, '0', 'default', 0); } private function removeBitcoinConfiguration()