Skip to content

Commit 0537bbb

Browse files
Merge pull request #1135 from buckaroo-it/BP-4114-Make-sure-payment-method-names-are-correct-by-default-Bancontact-Billink
Bp 4114 make sure payment method names are correct by default bancontact billink
2 parents ce33997 + c603de8 commit 0537bbb

38 files changed

+130
-4
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Buckaroo\Magento2\Model\Config\Backend;
4+
5+
use Magento\Framework\App\Config\Value;
6+
use Magento\Framework\App\ResourceConnection;
7+
8+
class EmptyToDelete extends Value
9+
{
10+
/**
11+
* @var ResourceConnection
12+
*/
13+
protected $resourceConnection;
14+
15+
/**
16+
* Constructor
17+
*
18+
* @param ResourceConnection $resourceConnection
19+
* @param \Magento\Framework\Model\Context $context
20+
* @param \Magento\Framework\Registry $registry
21+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
22+
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
23+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
24+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
25+
* @param array $data
26+
*/
27+
public function __construct(
28+
ResourceConnection $resourceConnection,
29+
\Magento\Framework\Model\Context $context,
30+
\Magento\Framework\Registry $registry,
31+
\Magento\Framework\App\Config\ScopeConfigInterface $config,
32+
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
33+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
34+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
35+
array $data = []
36+
) {
37+
$this->resourceConnection = $resourceConnection;
38+
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
39+
}
40+
41+
/**
42+
* Delete row from core_config_data if value is empty
43+
*
44+
* @return $this
45+
*/
46+
public function beforeSave()
47+
{
48+
try {
49+
$value = $this->getValue();
50+
51+
// If the value is empty, delete the row
52+
if (empty($value)) {
53+
$connection = $this->resourceConnection->getConnection();
54+
$tableName = $this->resourceConnection->getTableName('core_config_data');
55+
56+
$connection->delete(
57+
$tableName,
58+
[
59+
'path = ?' => $this->getPath(),
60+
'scope = ?' => $this->getScope(),
61+
'scope_id = ?' => $this->getScopeId()
62+
]
63+
);
64+
65+
// Prevent saving an empty value
66+
$this->setValue(null);
67+
}
68+
} catch (\Exception $e) {
69+
$this->_logger->critical($e->getMessage());
70+
}
71+
72+
return parent::beforeSave();
73+
}
74+
}

Setup/UpgradeData.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,24 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
568568
$this->addCustomerLastPayByBankIssuer($setup);
569569
}
570570

571+
if (version_compare($context->getVersion(), '1.51.0', '<')) {
572+
// Update buckaroo_magento2_mrcash title to 'Bancontact'
573+
$setup->getConnection()->update(
574+
$setup->getTable('core_config_data'),
575+
['value' => 'Bancontact'],
576+
['path = ?' => 'payment/buckaroo_magento2_mrcash/title']
577+
);
578+
579+
// Update buckaroo_magento2_billink title to 'Billink'
580+
$setup->getConnection()->update(
581+
$setup->getTable('core_config_data'),
582+
['value' => 'Billink'],
583+
['path = ?' => 'payment/buckaroo_magento2_billink/title']
584+
);
585+
}
586+
571587
$this->setCustomerIDIN($setup);
572-
588+
573589
$this->setCustomerIsEighteenOrOlder($setup);
574590

575591
$this->setProductIDIN($setup);

etc/adminhtml/system/payment_methods/afterpay.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_afterpay/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/afterpay2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_afterpay2/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/afterpay20.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_afterpay20/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/alipay.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_alipay/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/applepay.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@
4242
<label>Frontend label</label>
4343
<comment><![CDATA[Determines the frontend label shown.]]></comment>
4444
<config_path>payment/buckaroo_magento2_applepay/title</config_path>
45+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
4546
</field>
4647

4748
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
4849
<label>Frontend subtext</label>
4950
<comment><![CDATA[This controls the description which the user sees during checkout.]]></comment>
5051
<config_path>payment/buckaroo_magento2_applepay/subtext</config_path>
5152
</field>
52-
53+
5354
<field id="subtext_style" translate="label comment" type="select" sortOrder="26" showInDefault="1" showInWebsite="1" showInStore="1">
5455
<label>Frontend subtext style</label>
5556
<comment><![CDATA[Choose a font style for the subtext.]]></comment>

etc/adminhtml/system/payment_methods/belfius.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_belfius/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/billink.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_billink/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

etc/adminhtml/system/payment_methods/blik.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<label>Frontend label</label>
3737
<comment><![CDATA[Determines the frontend label shown.]]></comment>
3838
<config_path>payment/buckaroo_magento2_blik/title</config_path>
39+
<backend_model>Buckaroo\Magento2\Model\Config\Backend\EmptyToDelete</backend_model>
3940
</field>
4041

4142
<field id="subtext" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">

0 commit comments

Comments
 (0)