Skip to content

Commit 3408c23

Browse files
committed
MAGETWO-69854: Can't set allowed or default currencies using config:set command
1 parent 063c53d commit 3408c23

File tree

8 files changed

+52
-261
lines changed

8 files changed

+52
-261
lines changed

app/code/Magento/Config/Model/Config/Backend/Currency/AbstractCurrency.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class AbstractCurrency extends \Magento\Framework\App\Config\Value
2222
*/
2323
protected function _getAllowedCurrencies()
2424
{
25-
if ($this->getData('groups/options/fields/allow/inherit')) {
25+
if (!$this->isFormData() || $this->getData('groups/options/fields/allow/inherit')) {
2626
return explode(
2727
',',
2828
(string)$this->_config->getValue(
@@ -59,7 +59,8 @@ protected function _getInstalledCurrencies()
5959
*/
6060
protected function _getCurrencyBase()
6161
{
62-
if (!($value = $this->getData('groups/options/fields/base/value'))) {
62+
$value = $this->getData('groups/options/fields/base/value');
63+
if (!$this->isFormData() || !$value) {
6364
$value = $this->_config->getValue(
6465
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
6566
$this->getScope(),
@@ -76,7 +77,7 @@ protected function _getCurrencyBase()
7677
*/
7778
protected function _getCurrencyDefault()
7879
{
79-
if (!($value = $this->getData('groups/options/fields/default/value'))) {
80+
if (!$this->isFormData() || !($value = $this->getData('groups/options/fields/default/value'))) {
8081
$value = $this->_config->getValue(
8182
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
8283
$this->getScope(),
@@ -85,4 +86,14 @@ protected function _getCurrencyDefault()
8586
}
8687
return strval($value);
8788
}
89+
90+
/**
91+
* Check whether field saved from Admin form with other currency data or as single field, e.g. from CLI command
92+
*
93+
* @return bool True in case when field was saved from Admin form
94+
*/
95+
private function isFormData()
96+
{
97+
return $this->getData('groups/options/fields') !== null;
98+
}
8899
}

app/code/Magento/Config/Model/Config/Backend/Currency/Allow.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,22 @@ public function afterSave()
7373

7474
return parent::afterSave();
7575
}
76+
77+
/**
78+
* @inheritdoc
79+
*/
80+
protected function _getAllowedCurrencies()
81+
{
82+
$value = $this->getValue();
83+
$isFormData = $this->getData('groups/options/fields') !== null;
84+
if ($isFormData && $this->getData('groups/options/fields/allow/inherit')) {
85+
$value = (string)$this->_config->getValue(
86+
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
87+
$this->getScope(),
88+
$this->getScopeId()
89+
);
90+
}
91+
92+
return explode(',', $value);
93+
}
7694
}

app/code/Magento/Config/Model/Config/PreparedValue/AdditionalData.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

app/code/Magento/Config/Model/PreparedValueFactory.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Config\Model;
77

88
use Magento\Config\Model\Config\BackendFactory;
9-
use Magento\Config\Model\Config\PreparedValue\AdditionalData;
109
use Magento\Config\Model\Config\Structure;
1110
use Magento\Config\Model\Config\StructureFactory;
1211
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -52,32 +51,22 @@ class PreparedValueFactory
5251
*/
5352
private $config;
5453

55-
/**
56-
* Additional data applier for backend model.
57-
*
58-
* @var Config\PreparedValue\AdditionalData
59-
*/
60-
private $additionalData;
61-
6254
/**
6355
* @param ScopeResolverPool $scopeResolverPool The scope resolver pool
6456
* @param StructureFactory $structureFactory The manager for system configuration structure
6557
* @param BackendFactory $valueFactory The factory for configuration value objects
6658
* @param ScopeConfigInterface $config The scope configuration
67-
* @param AdditionalData $additionalData The additional data applier for backend model
6859
*/
6960
public function __construct(
7061
ScopeResolverPool $scopeResolverPool,
7162
StructureFactory $structureFactory,
7263
BackendFactory $valueFactory,
73-
ScopeConfigInterface $config,
74-
AdditionalData $additionalData
64+
ScopeConfigInterface $config
7565
) {
7666
$this->scopeResolverPool = $scopeResolverPool;
7767
$this->structureFactory = $structureFactory;
7868
$this->valueFactory = $valueFactory;
7969
$this->config = $config;
80-
$this->additionalData = $additionalData;
8170
}
8271

8372
/**
@@ -131,7 +120,6 @@ public function create($path, $value, $scope, $scopeCode = null)
131120
$backendModel->setScope($scope);
132121
$backendModel->setScopeId($scopeId);
133122
$backendModel->setValue($value);
134-
$this->additionalData->apply($backendModel);
135123
}
136124

137125
return $backendModel;

app/code/Magento/Config/Test/Unit/Model/Config/PreparedValue/AdditionalDataTest.php

Lines changed: 0 additions & 151 deletions
This file was deleted.

app/code/Magento/Config/Test/Unit/Model/PreparedValueFactoryTest.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Config\Test\Unit\Model;
77

88
use Magento\Config\Model\Config\BackendFactory;
9-
use Magento\Config\Model\Config\PreparedValue\AdditionalData;
109
use Magento\Config\Model\PreparedValueFactory;
1110
use Magento\Framework\App\Config\ScopeConfigInterface;
1211
use Magento\Config\Model\Config\StructureFactory;
@@ -70,11 +69,6 @@ class PreparedValueFactoryTest extends \PHPUnit_Framework_TestCase
7069
*/
7170
private $scopeMock;
7271

73-
/**
74-
* @var AdditionalData|Mock
75-
*/
76-
private $additionalDataMock;
77-
7872
/**
7973
* @var PreparedValueFactory
8074
*/
@@ -113,16 +107,12 @@ protected function setUp()
113107
->getMock();
114108
$this->scopeMock = $this->getMockBuilder(ScopeInterface::class)
115109
->getMockForAbstractClass();
116-
$this->additionalDataMock = $this->getMockBuilder(AdditionalData::class)
117-
->disableOriginalConstructor()
118-
->getMock();
119110

120111
$this->preparedValueFactory = new PreparedValueFactory(
121112
$this->scopeResolverPoolMock,
122113
$this->structureFactoryMock,
123114
$this->valueFactoryMock,
124-
$this->configMock,
125-
$this->additionalDataMock
115+
$this->configMock
126116
);
127117
}
128118

@@ -188,9 +178,6 @@ public function testCreate(
188178
->method('setValue')
189179
->with($value)
190180
->willReturnSelf();
191-
$this->additionalDataMock->expects($this->once())
192-
->method('apply')
193-
->with($this->valueMock);
194181

195182
$this->assertInstanceOf(
196183
Value::class,
@@ -307,8 +294,6 @@ public function testCreateNotInstanceOfValue(
307294
->method('setScopeId');
308295
$this->valueMock->expects($this->never())
309296
->method('setValue');
310-
$this->additionalDataMock->expects($this->never())
311-
->method('apply');
312297

313298
$this->assertSame(
314299
$value,

0 commit comments

Comments
 (0)