Skip to content

Commit c8f3f17

Browse files
committed
MAGETWO-94819: Swatch validation breaks the whole attribute form
1 parent 814fe73 commit c8f3f17

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Save extends Attribute implements HttpPostActionInterface
8282
/**
8383
* @var FormData|null
8484
*/
85-
private $dataSerializer;
85+
private $formDataSerializer;
8686

8787
/**
8888
* @param Context $context
@@ -97,7 +97,7 @@ class Save extends Attribute implements HttpPostActionInterface
9797
* @param Product $productHelper
9898
* @param LayoutFactory $layoutFactory
9999
* @param Presentation|null $presentation
100-
* @param FormData|null $dataSerializer
100+
* @param FormData|null $formDataSerializer
101101
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
102102
*/
103103
public function __construct(
@@ -113,7 +113,7 @@ public function __construct(
113113
Product $productHelper,
114114
LayoutFactory $layoutFactory,
115115
Presentation $presentation = null,
116-
FormData $dataSerializer = null
116+
FormData $formDataSerializer = null
117117
) {
118118
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
119119
$this->buildFactory = $buildFactory;
@@ -124,7 +124,7 @@ public function __construct(
124124
$this->groupCollectionFactory = $groupCollectionFactory;
125125
$this->layoutFactory = $layoutFactory;
126126
$this->presentation = $presentation ?: ObjectManager::getInstance()->get(Presentation::class);
127-
$this->dataSerializer = $dataSerializer
127+
$this->formDataSerializer = $formDataSerializer
128128
?: ObjectManager::getInstance()->get(FormData::class);
129129
}
130130

@@ -140,7 +140,7 @@ public function __construct(
140140
public function execute()
141141
{
142142
try {
143-
$optionData = $this->dataSerializer
143+
$optionData = $this->formDataSerializer
144144
->unserialize($this->getRequest()->getParam('serialized_options', '[]'));
145145
} catch (\InvalidArgumentException $e) {
146146
$message = __("The attribute couldn't be saved due to an error. Verify your information and try again. "
@@ -150,7 +150,7 @@ public function execute()
150150
}
151151

152152
$data = $this->getRequest()->getPostValue();
153-
$data = array_merge_recursive(
153+
$data = array_replace_recursive(
154154
$data,
155155
$optionData
156156
);

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
4141
/**
4242
* @var FormData|null
4343
*/
44-
private $dataSerializer;
44+
private $formDataSerializer;
4545

4646
/**
4747
* Constructor
@@ -53,7 +53,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
5353
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
5454
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
5555
* @param array $multipleAttributeList
56-
* @param FormData|null $dataSerializer
56+
* @param FormData|null $formDataSerializer
5757
*/
5858
public function __construct(
5959
\Magento\Backend\App\Action\Context $context,
@@ -63,13 +63,13 @@ public function __construct(
6363
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
6464
\Magento\Framework\View\LayoutFactory $layoutFactory,
6565
array $multipleAttributeList = [],
66-
FormData $dataSerializer = null
66+
FormData $formDataSerializer = null
6767
) {
6868
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
6969
$this->resultJsonFactory = $resultJsonFactory;
7070
$this->layoutFactory = $layoutFactory;
7171
$this->multipleAttributeList = $multipleAttributeList;
72-
$this->dataSerializer = $dataSerializer ?: ObjectManager::getInstance()
72+
$this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance()
7373
->get(FormData::class);
7474
}
7575

@@ -85,7 +85,7 @@ public function execute()
8585
$response = new DataObject();
8686
$response->setError(false);
8787
try {
88-
$optionsData = $this->dataSerializer
88+
$optionsData = $this->formDataSerializer
8989
->unserialize($this->getRequest()->getParam('serialized_options', '[]'));
9090
} catch (\InvalidArgumentException $e) {
9191
$message = __("The attribute couldn't be validated due to an error. Verify your information and try again. "

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class SaveTest extends AttributeTest
8787
/**
8888
* @var FormData|\PHPUnit_Framework_MockObject_MockObject
8989
*/
90-
private $dataSerializerMock;
90+
private $formDataSerializerMock;
9191

9292
/**
9393
* @var ProductAttributeInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -135,7 +135,7 @@ protected function setUp()
135135
$this->inputTypeValidatorMock = $this->getMockBuilder(InputTypeValidator::class)
136136
->disableOriginalConstructor()
137137
->getMock();
138-
$this->dataSerializerMock = $this->getMockBuilder(FormData::class)
138+
$this->formDataSerializerMock = $this->getMockBuilder(FormData::class)
139139
->disableOriginalConstructor()
140140
->getMock();
141141
$this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
@@ -170,7 +170,7 @@ protected function getModel()
170170
'validatorFactory' => $this->validatorFactoryMock,
171171
'groupCollectionFactory' => $this->groupCollectionFactoryMock,
172172
'layoutFactory' => $this->layoutFactoryMock,
173-
'dataSerializer' => $this->dataSerializerMock,
173+
'formDataSerializer' => $this->formDataSerializerMock,
174174
]);
175175
}
176176

@@ -182,7 +182,7 @@ public function testExecuteWithEmptyData()
182182
['isAjax', null, null],
183183
['serialized_options', '[]', ''],
184184
]);
185-
$this->dataSerializerMock
185+
$this->formDataSerializerMock
186186
->expects($this->once())
187187
->method('unserialize')
188188
->with('')
@@ -213,7 +213,7 @@ public function testExecute()
213213
['isAjax', null, null],
214214
['serialized_options', '[]', ''],
215215
]);
216-
$this->dataSerializerMock
216+
$this->formDataSerializerMock
217217
->expects($this->once())
218218
->method('unserialize')
219219
->with('')
@@ -273,7 +273,7 @@ public function testExecuteWithOptionsDataError()
273273
['isAjax', null, true],
274274
['serialized_options', '[]', $serializedOptions],
275275
]);
276-
$this->dataSerializerMock
276+
$this->formDataSerializerMock
277277
->expects($this->once())
278278
->method('unserialize')
279279
->with($serializedOptions)

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ValidateTest extends AttributeTest
6565
/**
6666
* @var FormData|\PHPUnit_Framework_MockObject_MockObject
6767
*/
68-
private $dataSerializerMock;
68+
private $formDataSerializerMock;
6969

7070
protected function setUp()
7171
{
@@ -92,7 +92,7 @@ protected function setUp()
9292
->getMock();
9393
$this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
9494
->getMockForAbstractClass();
95-
$this->dataSerializerMock = $this->getMockBuilder(FormData::class)
95+
$this->formDataSerializerMock = $this->getMockBuilder(FormData::class)
9696
->disableOriginalConstructor()
9797
->getMock();
9898

@@ -116,7 +116,7 @@ protected function getModel()
116116
'resultJsonFactory' => $this->resultJsonFactoryMock,
117117
'layoutFactory' => $this->layoutFactoryMock,
118118
'multipleAttributeList' => ['select' => 'option'],
119-
'dataSerializer' => $this->dataSerializerMock,
119+
'formDataSerializer' => $this->formDataSerializerMock,
120120
]
121121
);
122122
}
@@ -184,7 +184,7 @@ public function testUniqueValidation(array $options, $isError)
184184
['serialized_options', '[]', $serializedOptions],
185185
]);
186186

187-
$this->dataSerializerMock
187+
$this->formDataSerializerMock
188188
->expects($this->once())
189189
->method('unserialize')
190190
->with($serializedOptions)
@@ -319,7 +319,7 @@ public function testEmptyOption(array $options, $result)
319319
['serialized_options', '[]', $serializedOptions],
320320
]);
321321

322-
$this->dataSerializerMock
322+
$this->formDataSerializerMock
323323
->expects($this->once())
324324
->method('unserialize')
325325
->with($serializedOptions)
@@ -431,7 +431,7 @@ public function testExecuteWithOptionsDataError()
431431
['serialized_options', '[]', $serializedOptions],
432432
]);
433433

434-
$this->dataSerializerMock
434+
$this->formDataSerializerMock
435435
->expects($this->once())
436436
->method('unserialize')
437437
->with($serializedOptions)

0 commit comments

Comments
 (0)