Skip to content

Commit

Permalink
Merge pull request #247 from magento-fearless-kiwis
Browse files Browse the repository at this point in the history
Fixed issues:
 - MAGETWO-54653: Adding too many configurable product option causes browser to hang.
  • Loading branch information
Oleksii Korshenko authored Aug 15, 2016
2 parents 903dcbb + b75fc4f commit 5f1cfd1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 11 deletions.
25 changes: 25 additions & 0 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function execute()
$productTypeId = $this->getRequest()->getParam('type');
if ($data) {
try {
$this->unserializeProductData($data);
$product = $this->initializationHelper->initialize(
$this->productBuilder->build($this->getRequest())
);
Expand Down Expand Up @@ -180,6 +181,30 @@ public function execute()
return $resultRedirect;
}

/**
* Unserialize product data for configurable products
*
* @param array $postData
* @return void
*/
private function unserializeProductData($postData)
{
if (isset($postData["configurable-matrix-serialized"])) {
$configurableMatrixSerialized = $postData["configurable-matrix-serialized"];
if ($configurableMatrixSerialized != null && !empty($configurableMatrixSerialized)) {
$postData["configurable-matrix"] = json_decode($configurableMatrixSerialized, true);
unset($postData["configurable-matrix-serialized"]);
}
}
if (isset($postData["associated_product_ids_serialized"])) {
$associatedProductIdsSerialized = $postData["associated_product_ids_serialized"];
if ($associatedProductIdsSerialized != null && !empty($associatedProductIdsSerialized)) {
$postData["associated_product_ids"] = json_decode($associatedProductIdsSerialized, true);
unset($postData["associated_product_ids_serialized"]);
}
}
}

/**
* Notify customer when image was not deleted in specific case.
* TODO: temporary workaround must be eliminated in MAGETWO-45306
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ public function afterInitialize(Helper $subject, ProductInterface $product)
*/
private function setLinkedProducts(ProductInterface $product, ProductExtensionInterface $extensionAttributes)
{
$associatedProductIds = $this->request->getPost('associated_product_ids', []);
$associatedProductIds = $this->request->getPost('associated_product_ids_serialized', '[]');
if ($associatedProductIds != null && !empty($associatedProductIds)) {
$associatedProductIds = json_decode($associatedProductIds, true);
}

$variationsMatrix = $this->getVariationMatrix();

if ($associatedProductIds || $variationsMatrix) {
Expand All @@ -149,7 +153,10 @@ private function setLinkedProducts(ProductInterface $product, ProductExtensionIn
protected function getVariationMatrix()
{
$result = [];
$configurableMatrix = $this->request->getParam('configurable-matrix', []);
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
if ($configurableMatrix != null && !empty($configurableMatrix)) {
$configurableMatrix = json_decode($configurableMatrix, true);
}

foreach ($configurableMatrix as $item) {
if ($item['newProduct']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function afterInitialize(
protected function getConfigurations()
{
$result = [];
$configurableMatrix = $this->request->getParam('configurable-matrix', []);
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
if ($configurableMatrix != null && !empty($configurableMatrix)) {
$configurableMatrix = json_decode($configurableMatrix, true);
}

foreach ($configurableMatrix as $item) {
if (!$item['newProduct']) {
$result[$item['id']] = $this->mapData($item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testAfterInitializeWithAttributesAndVariations()
];
$valueMap = [
['new-variations-attribute-set-id', null, 24],
['associated_product_ids', [], []],
['associated_product_ids_serialized', '[]', []],
['product', [], ['configurable_attributes_data' => $attributes]],
];
$simpleProductsIds = [1, 2, 3];
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testAfterInitializeWithAttributesAndVariations()
]
];
$paramValueMap = [
['configurable-matrix', [], $simpleProducts],
['configurable-matrix-serialized', '[]', json_encode($simpleProducts)],
['attributes', null, $attributes],
];

Expand Down Expand Up @@ -212,11 +212,11 @@ public function testAfterInitializeWithAttributesAndWithoutVariations()
];
$valueMap = [
['new-variations-attribute-set-id', null, 24],
['associated_product_ids', [], []],
['associated_product_ids_serialized', '[]', []],
['product', [], ['configurable_attributes_data' => $attributes]],
];
$paramValueMap = [
['configurable-matrix', [], []],
['configurable-matrix-serialized', '[]', []],
['attributes', null, $attributes],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testAfterInitialize()
->willReturnMap(
[
['store', 0, 0],
['configurable-matrix', [], $configurableMatrix]
['configurable-matrix-serialized', '[]', json_encode($configurableMatrix)]
]
);
$this->variationHandlerMock->expects(static::once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ define([
* Chose action for the form save button
*/
saveFormHandler: function() {
this.source.data["configurable-matrix-serialized"] =
JSON.stringify(this.source.data["configurable-matrix"]);
delete this.source.data["configurable-matrix"];
this.source.data["associated_product_ids_serialized"] =
JSON.stringify(this.source.data["associated_product_ids"]);
delete this.source.data["associated_product_ids"];
if (this.checkForNewAttributes()) {
this.formSaveParams = arguments;
this.attributeSetHandlerModal().openModal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ protected function prepareVariationsMatrix(array $data)
$row
);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public function prepareData(FixtureInterface $fixture)
$data['new-variations-attribute-set-id'] = $attributeSetId;
$data['associated_product_ids'] = $this->prepareAssociatedProductIds($configurableAttributesData);

return $this->replaceMappingData($data);
$this->replaceMappingData($data);
$data['configurable-matrix-serialized'] = json_encode($data['configurable-matrix']);
$data['associated_product_ids_serialized'] = json_encode($data['associated_product_ids']);
return $data;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class ProductTest extends \Magento\TestFramework\TestCase\AbstractBackendControl
public function testSaveActionAssociatedProductIds()
{
$associatedProductIds = [3, 14, 15, 92];
$associatedProductIdsJSON = json_encode($associatedProductIds);
$this->getRequest()->setPostValue(
[
'attributes' => [$this->_getConfigurableAttribute()->getId()],
'associated_product_ids' => $associatedProductIds,
'associated_product_ids_serialized' => $associatedProductIdsJSON,
]
);

Expand Down

0 comments on commit 5f1cfd1

Please sign in to comment.