Skip to content

Commit

Permalink
Merge pull request #153 from mollie/1.6.1
Browse files Browse the repository at this point in the history
1.6.1
  • Loading branch information
Marvin-Magmodules authored Jun 4, 2019
2 parents d527864 + 806318f commit 095bfce
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
75 changes: 73 additions & 2 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +30,16 @@ class UpgradeData implements UpgradeDataInterface
*/
private $salesSetupFactory;

/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var Config
*/
private $resourceConfig;

/**
* @var WriterInterface
*/
Expand All @@ -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;
}
Expand All @@ -73,6 +91,10 @@ public function upgrade(
$this->removeBitcoinConfiguration();
}

if (version_compare($context->getVersion(), '1.6.1', '<')) {
$this->upgradeActiveState();
}

$setup->endSetup();
}

Expand All @@ -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', 0);
}

private function removeBitcoinConfiguration()
{
$paths = [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 17 additions & 17 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<cancel_failed_orders>0</cancel_failed_orders>
</mollie_general>
<mollie_methods_bancontact>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Bancontact</model>
<title>Bancontact</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -26,7 +26,7 @@
<instructions/>
</mollie_methods_bancontact>
<mollie_methods_banktransfer>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Banktransfer</model>
<title>Banktransfer</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -37,7 +37,7 @@
<instructions/>
</mollie_methods_banktransfer>
<mollie_methods_belfius>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Belfius</model>
<title>Belfius</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -46,7 +46,7 @@
<instructions/>
</mollie_methods_belfius>
<mollie_methods_creditcard>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Creditcard</model>
<title>Credit Cards</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -55,7 +55,7 @@
<instructions/>
</mollie_methods_creditcard>
<mollie_methods_ideal>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Ideal</model>
<title>iDeal</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -65,7 +65,7 @@
<instructions/>
</mollie_methods_ideal>
<mollie_methods_kbc>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Kbc</model>
<title>KBC/CBC</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -75,7 +75,7 @@
<instructions/>
</mollie_methods_kbc>
<mollie_methods_paypal>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Paypal</model>
<title>Paypal</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -84,7 +84,7 @@
<instructions/>
</mollie_methods_paypal>
<mollie_methods_paysafecard>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Paysafecard</model>
<title>Paysafecard</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -93,7 +93,7 @@
<instructions/>
</mollie_methods_paysafecard>
<mollie_methods_sofort>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Sofort</model>
<title>Sofort</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -102,7 +102,7 @@
<instructions/>
</mollie_methods_sofort>
<mollie_methods_inghomepay>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Inghomepay</model>
<title>ING Homepay</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -111,7 +111,7 @@
<instructions/>
</mollie_methods_inghomepay>
<mollie_methods_giropay>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Giropay</model>
<title>Giropay</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -120,7 +120,7 @@
<instructions/>
</mollie_methods_giropay>
<mollie_methods_eps>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Eps</model>
<title>EPS</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -129,7 +129,7 @@
<instructions/>
</mollie_methods_eps>
<mollie_methods_klarnapaylater>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Klarnapaylater</model>
<title>Klarna Pay Later</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -139,7 +139,7 @@
<instructions/>
</mollie_methods_klarnapaylater>
<mollie_methods_klarnasliceit>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Klarnasliceit</model>
<title>Klarna Slice It</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -149,7 +149,7 @@
<instructions/>
</mollie_methods_klarnasliceit>
<mollie_methods_paymentlink>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Paymentlink</model>
<title>Mollie: Payment Link</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -160,7 +160,7 @@
<instructions/>
</mollie_methods_paymentlink>
<mollie_methods_giftcard>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Giftcard</model>
<title>Giftcard</title>
<payment_description>{ordernumber}</payment_description>
Expand All @@ -170,7 +170,7 @@
<instructions/>
</mollie_methods_giftcard>
<mollie_methods_przelewy24>
<active>0</active>
<active>1</active>
<model>Mollie\Payment\Model\Methods\Przelewy24</model>
<title>Przelewy24</title>
<payment_description>{ordernumber}</payment_description>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mollie_Payment" setup_version="1.6.0" />
<module name="Mollie_Payment" setup_version="1.6.1" />
</config>

0 comments on commit 095bfce

Please sign in to comment.