Skip to content

Commit 0d31c3e

Browse files
authored
Merge pull request #559 from magento-performance/MAGETWO-55791
[Performance] Fast Display and Generation of Product Variations - MAGETWO-55300 [Customer] Fast Display and Generation of Product Variations for Configurable Products
2 parents 90e0f4c + 87274f3 commit 0d31c3e

File tree

15 files changed

+690
-158
lines changed

15 files changed

+690
-158
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function execute()
7373
$productTypeId = $this->getRequest()->getParam('type');
7474
if ($data) {
7575
try {
76+
$data = $this->unserializeData($data);
7677
$product = $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest()));
7778
$this->productTypeManager->processProduct($product);
7879

@@ -157,6 +158,29 @@ public function execute()
157158
return $resultRedirect;
158159
}
159160

161+
/**
162+
* @param array $data
163+
* @return array
164+
*/
165+
private function unserializeData($data)
166+
{
167+
if (isset($data["configurable-matrix-serialized"])) {
168+
$configurableMatrixSerialized = $data["configurable-matrix-serialized"];
169+
if ($configurableMatrixSerialized != null && !empty($configurableMatrixSerialized)) {
170+
$data["variations-matrix"] = json_decode($configurableMatrixSerialized, true);
171+
unset($data["configurable-matrix-serialized"]);
172+
}
173+
}
174+
if (isset($data["associated_product_ids_serialized"])) {
175+
$associatedProductIdsSerialized = $data["associated_product_ids_serialized"];
176+
if ($associatedProductIdsSerialized != null && !empty($associatedProductIdsSerialized)) {
177+
$data["associated_product_ids"] = json_decode($associatedProductIdsSerialized, true);
178+
unset($data["associated_product_ids_serialized"]);
179+
}
180+
}
181+
return $data;
182+
}
183+
160184
/**
161185
* Notify customer when image was not deleted in specific case.
162186
* TODO: temporary workaround must be eliminated in MAGETWO-45306

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ public function afterInitialize(
5555
$this->productType->setUsedProductAttributeIds($attributes, $product);
5656

5757
$product->setNewVariationsAttributeSetId($setId);
58-
$associatedProductIds = $this->request->getPost('associated_product_ids', []);
59-
$variationsMatrix = $this->request->getParam('variations-matrix', []);
58+
$associatedProductIds = $this->request->getPost('associated_product_ids_serialized', '[]');
59+
if ($associatedProductIds !== null && !empty($associatedProductIds)) {
60+
$associatedProductIds = json_decode($associatedProductIds, true);
61+
}
62+
$variationsMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
63+
if ($variationsMatrix !== null && !empty($variationsMatrix)) {
64+
$variationsMatrix = json_decode($variationsMatrix, true);
65+
}
6066
if (!empty($variationsMatrix)) {
6167
$generatedProductIds = $this->variationHandler->generateSimpleProducts($product, $variationsMatrix);
6268
$associatedProductIds = array_merge($associatedProductIds, $generatedProductIds);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function afterInitialize(
4747
\Magento\Catalog\Model\Product $configurableProduct
4848
) {
4949
$configurations = $this->request->getParam('configurations', []);
50+
if ($this->request->getParam('configurations_serialized')) {
51+
$configurations = json_decode($this->request->getParam('configurations_serialized'), true);
52+
}
5053
$configurations = $this->variationHandler->duplicateImagesForVariations($configurations);
5154
foreach ($configurations as $productId => $productData) {
5255
/** @var \Magento\Catalog\Model\Product $product */

app/code/Magento/ConfigurableProduct/Model/Product/Validator/Plugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public function aroundValidate(
6969
$product->setTypeId(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
7070
}
7171
$result = $proceed($product, $request, $response);
72-
$variationProducts = (array)$request->getPost('variations-matrix');
72+
$variationProducts = $request->getPost('configurable-matrix-serialized', '[]');
73+
$variationProducts = json_decode($variationProducts, true);
7374
if ($variationProducts) {
7475
$validationResult = $this->_validateProductVariations($product, $variationProducts, $request);
7576
if (!empty($validationResult)) {

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,23 @@ public function testAfterInitializeIfAttributesNotEmptyAndActionNameNotGenerateV
7979
{
8080
$this->productMock->expects($this->once())->method('getTypeId')->willReturn(ConfigurableProduct::TYPE_CODE);
8181
$associatedProductIds = ['key' => 'value'];
82+
$associatedProductIdsSerialized = json_encode($associatedProductIds);
8283
$generatedProductIds = ['key_one' => 'value_one'];
8384
$expectedArray = ['key' => 'value', 'key_one' => 'value_one'];
8485
$attributes = ['key' => 'value'];
8586
$postValue = 'postValue';
87+
$variationsMatrix = ['variationKey' => 'variationValue'];
88+
$variationsMatrixSerialized = json_encode($variationsMatrix);
89+
8690
$postValueMap = [
8791
['new-variations-attribute-set-id', null, $postValue],
88-
['associated_product_ids', [], $associatedProductIds],
92+
['associated_product_ids_serialized', '[]', $associatedProductIdsSerialized],
8993
['affect_configurable_product_attributes', null, $postValue],
9094
];
9195
$this->requestMock->expects($this->any())->method('getPost')->will($this->returnValueMap($postValueMap));
9296

9397
$paramValueMap = [
94-
['variations-matrix', [], $postValue],
98+
['configurable-matrix-serialized', '[]', $variationsMatrixSerialized],
9599
['attributes', null, $attributes],
96100
];
97101
$this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($paramValueMap));
@@ -110,7 +114,7 @@ public function testAfterInitializeIfAttributesNotEmptyAndActionNameNotGenerateV
110114
'generateSimpleProducts'
111115
)->with(
112116
$this->productMock,
113-
$postValue
117+
$variationsMatrix
114118
)->will(
115119
$this->returnValue($generatedProductIds)
116120
);
@@ -123,16 +127,17 @@ public function testAfterInitializeIfAttributesNotEmptyAndActionNameGenerateVari
123127
{
124128
$this->productMock->expects($this->once())->method('getTypeId')->willReturn(ConfigurableProduct::TYPE_CODE);
125129
$associatedProductIds = ['key' => 'value'];
130+
$associatedProductIdsSerialized = json_encode($associatedProductIds);
126131
$attributes = ['key' => 'value'];
127132
$postValue = 'postValue';
128133
$valueMap = [
129134
['new-variations-attribute-set-id', null, $postValue],
130-
['associated_product_ids', [], $associatedProductIds],
135+
['associated_product_ids_serialized', '[]', $associatedProductIdsSerialized],
131136
['affect_configurable_product_attributes', null, $postValue],
132137
];
133138
$this->requestMock->expects($this->any())->method('getPost')->will($this->returnValueMap($valueMap));
134139
$paramValueMap = [
135-
['variations-matrix', [], []],
140+
['variations-matrix', '[]', '[]'],
136141
['attributes', null, $attributes],
137142
];
138143
$this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($paramValueMap));

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Validator/PluginTest.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function setUp()
110110

111111
public function testAroundValidateWithVariationsValid()
112112
{
113-
$matrix = ['products'];
113+
$matrix = json_encode(['products']);
114114

115115
$plugin = $this->getMock(
116116
'Magento\ConfigurableProduct\Model\Product\Validator\Plugin',
@@ -124,7 +124,7 @@ public function testAroundValidateWithVariationsValid()
124124
'_validateProductVariations'
125125
)->with(
126126
$this->productMock,
127-
$matrix,
127+
json_decode($matrix),
128128
$this->requestMock
129129
)->will(
130130
$this->returnValue(null)
@@ -135,7 +135,8 @@ public function testAroundValidateWithVariationsValid()
135135
)->method(
136136
'getPost'
137137
)->with(
138-
'variations-matrix'
138+
'configurable-matrix-serialized',
139+
'[]'
139140
)->will(
140141
$this->returnValue($matrix)
141142
);
@@ -156,7 +157,7 @@ public function testAroundValidateWithVariationsValid()
156157

157158
public function testAroundValidateWithVariationsInvalid()
158159
{
159-
$matrix = ['products'];
160+
$matrix = json_encode(['products']);
160161

161162
$plugin = $this->getMock(
162163
'Magento\ConfigurableProduct\Model\Product\Validator\Plugin',
@@ -170,7 +171,7 @@ public function testAroundValidateWithVariationsInvalid()
170171
'_validateProductVariations'
171172
)->with(
172173
$this->productMock,
173-
$matrix,
174+
json_decode($matrix),
174175
$this->requestMock
175176
)->will(
176177
$this->returnValue(true)
@@ -181,7 +182,8 @@ public function testAroundValidateWithVariationsInvalid()
181182
)->method(
182183
'getPost'
183184
)->with(
184-
'variations-matrix'
185+
'configurable-matrix-serialized',
186+
'[]'
185187
)->will(
186188
$this->returnValue($matrix)
187189
);
@@ -208,9 +210,10 @@ public function testAroundValidateIfVariationsNotExist()
208210
)->method(
209211
'getPost'
210212
)->with(
211-
'variations-matrix'
213+
'configurable-matrix-serialized',
214+
'[]'
212215
)->will(
213-
$this->returnValue(null)
216+
$this->returnValue('[]')
214217
);
215218
$this->eventManagerMock->expects($this->never())->method('dispatch');
216219
$this->plugin->aroundValidate(
@@ -225,10 +228,11 @@ public function testAroundValidateIfVariationsNotExist()
225228
public function testAroundValidateWithVariationsAndRequiredAttributes()
226229
{
227230
$matrix = [
228-
['data1', 'data2', 'configurable_attribute' => ['data1']],
229-
['data3', 'data4', 'configurable_attribute' => ['data3']],
230-
['data5', 'data6', 'configurable_attribute' => ['data5']],
231+
['data1', 'data2', 'configurable_attribute' => ['data1'], 'price' => 10],
232+
['data3', 'data4', 'configurable_attribute' => ['data3'], 'price' => 10],
233+
['data5', 'data6', 'configurable_attribute' => ['data5'], 'price' => 10],
231234
];
235+
$encodedMatrix = json_encode($matrix);
232236

233237
$this->productMock->expects($this->any())
234238
->method('getData')
@@ -249,9 +253,10 @@ public function testAroundValidateWithVariationsAndRequiredAttributes()
249253
)->method(
250254
'getPost'
251255
)->with(
252-
'variations-matrix'
256+
'configurable-matrix-serialized',
257+
'[]'
253258
)->will(
254-
$this->returnValue($matrix)
259+
$this->returnValue($encodedMatrix)
255260
);
256261

257262
$attribute1 = $this->createAttribute('code1', true, true);

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/summary.phtml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,33 @@
1313

1414
<div class="admin__data-grid-wrap admin__data-grid-wrap-static">
1515
<!-- ko if: gridNew().length -->
16-
<!-- ko template: {name: getGridTemplate(), data: {
17-
grid: gridNew,
18-
id: getGridId(),
19-
title: $t('New Product Review'),
20-
note: $t('Here are the products you\'re about to create.')
21-
}} --><!-- /ko -->
16+
<!-- ko template: {name: getGridTemplate(), data: {
17+
grid: gridNew,
18+
paging: pagingNew,
19+
id: getGridId(),
20+
title: $t('New Product Review'),
21+
note: $t('Here are the products you\'re about to create.')
22+
}} --><!-- /ko -->
2223
<!-- /ko -->
2324

2425
<!-- ko if: gridExisting().length -->
25-
<!-- ko template: {name: getGridTemplate(), data: {
26-
grid: gridExisting,
27-
id: getGridId(),
28-
title: $t('Associated Products'),
29-
note: $t('You created these products for this configuration.')
30-
}} --><!-- /ko -->
26+
<!-- ko template: {name: getGridTemplate(), data: {
27+
paging: pagingExisting,
28+
grid: gridExisting,
29+
id: getGridId(),
30+
title: $t('Associated Products'),
31+
note: $t('You created these products for this configuration.')
32+
}} --><!-- /ko -->
3133
<!-- /ko -->
3234

3335
<!-- ko if: gridDeleted().length -->
34-
<!-- ko template: {name: getGridTemplate(), data: {
35-
grid: gridDeleted,
36-
id: getGridId(),
37-
title: $t('Disassociated Products'),
38-
note: $t('These products are not associated.')
39-
}} --><!-- /ko -->
36+
<!-- ko template: {name: getGridTemplate(), data: {
37+
paging: pagingDeleted,
38+
grid: gridDeleted,
39+
id: getGridId(),
40+
title: $t('Disassociated Products'),
41+
note: $t('These products are not associated.')
42+
}} --><!-- /ko -->
4043
<!-- /ko -->
4144
</div>
4245
</div>

0 commit comments

Comments
 (0)