Skip to content

Commit a57fb41

Browse files
author
Karpenko, Oleksandr
committed
Merge branch 'develop' of github.com:magento/magento2ce into PR
2 parents 6fc80f3 + 5f1cfd1 commit a57fb41

File tree

9 files changed

+56
-11
lines changed

9 files changed

+56
-11
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function execute()
9797
$productTypeId = $this->getRequest()->getParam('type');
9898
if ($data) {
9999
try {
100+
$this->unserializeProductData($data);
100101
$product = $this->initializationHelper->initialize(
101102
$this->productBuilder->build($this->getRequest())
102103
);
@@ -180,6 +181,30 @@ public function execute()
180181
return $resultRedirect;
181182
}
182183

184+
/**
185+
* Unserialize product data for configurable products
186+
*
187+
* @param array $postData
188+
* @return void
189+
*/
190+
private function unserializeProductData($postData)
191+
{
192+
if (isset($postData["configurable-matrix-serialized"])) {
193+
$configurableMatrixSerialized = $postData["configurable-matrix-serialized"];
194+
if ($configurableMatrixSerialized != null && !empty($configurableMatrixSerialized)) {
195+
$postData["configurable-matrix"] = json_decode($configurableMatrixSerialized, true);
196+
unset($postData["configurable-matrix-serialized"]);
197+
}
198+
}
199+
if (isset($postData["associated_product_ids_serialized"])) {
200+
$associatedProductIdsSerialized = $postData["associated_product_ids_serialized"];
201+
if ($associatedProductIdsSerialized != null && !empty($associatedProductIdsSerialized)) {
202+
$postData["associated_product_ids"] = json_decode($associatedProductIdsSerialized, true);
203+
unset($postData["associated_product_ids_serialized"]);
204+
}
205+
}
206+
}
207+
183208
/**
184209
* Notify customer when image was not deleted in specific case.
185210
* TODO: temporary workaround must be eliminated in MAGETWO-45306

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Configurable.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ public function afterInitialize(Helper $subject, ProductInterface $product)
127127
*/
128128
private function setLinkedProducts(ProductInterface $product, ProductExtensionInterface $extensionAttributes)
129129
{
130-
$associatedProductIds = $this->request->getPost('associated_product_ids', []);
130+
$associatedProductIds = $this->request->getPost('associated_product_ids_serialized', '[]');
131+
if ($associatedProductIds != null && !empty($associatedProductIds)) {
132+
$associatedProductIds = json_decode($associatedProductIds, true);
133+
}
134+
131135
$variationsMatrix = $this->getVariationMatrix();
132136

133137
if ($associatedProductIds || $variationsMatrix) {
@@ -149,7 +153,10 @@ private function setLinkedProducts(ProductInterface $product, ProductExtensionIn
149153
protected function getVariationMatrix()
150154
{
151155
$result = [];
152-
$configurableMatrix = $this->request->getParam('configurable-matrix', []);
156+
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
157+
if ($configurableMatrix != null && !empty($configurableMatrix)) {
158+
$configurableMatrix = json_decode($configurableMatrix, true);
159+
}
153160

154161
foreach ($configurableMatrix as $item) {
155162
if ($item['newProduct']) {

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurations.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ public function afterInitialize(
8585
protected function getConfigurations()
8686
{
8787
$result = [];
88-
$configurableMatrix = $this->request->getParam('configurable-matrix', []);
88+
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
89+
if ($configurableMatrix != null && !empty($configurableMatrix)) {
90+
$configurableMatrix = json_decode($configurableMatrix, true);
91+
}
92+
8993
foreach ($configurableMatrix as $item) {
9094
if (!$item['newProduct']) {
9195
$result[$item['id']] = $this->mapData($item);

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/ConfigurableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testAfterInitializeWithAttributesAndVariations()
101101
];
102102
$valueMap = [
103103
['new-variations-attribute-set-id', null, 24],
104-
['associated_product_ids', [], []],
104+
['associated_product_ids_serialized', '[]', []],
105105
['product', [], ['configurable_attributes_data' => $attributes]],
106106
];
107107
$simpleProductsIds = [1, 2, 3];
@@ -150,7 +150,7 @@ public function testAfterInitializeWithAttributesAndVariations()
150150
]
151151
];
152152
$paramValueMap = [
153-
['configurable-matrix', [], $simpleProducts],
153+
['configurable-matrix-serialized', '[]', json_encode($simpleProducts)],
154154
['attributes', null, $attributes],
155155
];
156156

@@ -212,11 +212,11 @@ public function testAfterInitializeWithAttributesAndWithoutVariations()
212212
];
213213
$valueMap = [
214214
['new-variations-attribute-set-id', null, 24],
215-
['associated_product_ids', [], []],
215+
['associated_product_ids_serialized', '[]', []],
216216
['product', [], ['configurable_attributes_data' => $attributes]],
217217
];
218218
$paramValueMap = [
219-
['configurable-matrix', [], []],
219+
['configurable-matrix-serialized', '[]', []],
220220
['attributes', null, $attributes],
221221
];
222222

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testAfterInitialize()
127127
->willReturnMap(
128128
[
129129
['store', 0, 0],
130-
['configurable-matrix', [], $configurableMatrix]
130+
['configurable-matrix-serialized', '[]', json_encode($configurableMatrix)]
131131
]
132132
);
133133
$this->variationHandlerMock->expects(static::once())

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ define([
301301
* Chose action for the form save button
302302
*/
303303
saveFormHandler: function() {
304+
this.source.data["configurable-matrix-serialized"] =
305+
JSON.stringify(this.source.data["configurable-matrix"]);
306+
delete this.source.data["configurable-matrix"];
307+
this.source.data["associated_product_ids_serialized"] =
308+
JSON.stringify(this.source.data["associated_product_ids"]);
309+
delete this.source.data["associated_product_ids"];
304310
if (this.checkForNewAttributes()) {
305311
this.formSaveParams = arguments;
306312
this.attributeSetHandlerModal().openModal();

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ protected function prepareVariationsMatrix(array $data)
313313
$row
314314
);
315315
}
316-
317316
}
318317
}
319318

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function prepareData(FixtureInterface $fixture)
5555
$data['new-variations-attribute-set-id'] = $attributeSetId;
5656
$data['associated_product_ids'] = $this->prepareAssociatedProductIds($configurableAttributesData);
5757

58-
return $this->replaceMappingData($data);
58+
$this->replaceMappingData($data);
59+
$data['configurable-matrix-serialized'] = json_encode($data['configurable-matrix']);
60+
$data['associated_product_ids_serialized'] = json_encode($data['associated_product_ids']);
61+
return $data;
5962
}
6063

6164
/**

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Controller/Adminhtml/ProductTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ class ProductTest extends \Magento\TestFramework\TestCase\AbstractBackendControl
2020
public function testSaveActionAssociatedProductIds()
2121
{
2222
$associatedProductIds = [3, 14, 15, 92];
23+
$associatedProductIdsJSON = json_encode($associatedProductIds);
2324
$this->getRequest()->setPostValue(
2425
[
2526
'attributes' => [$this->_getConfigurableAttribute()->getId()],
26-
'associated_product_ids' => $associatedProductIds,
27+
'associated_product_ids_serialized' => $associatedProductIdsJSON,
2728
]
2829
);
2930

0 commit comments

Comments
 (0)