Skip to content

Commit 6ae1fce

Browse files
author
cspruiell
committed
MAGETWO-58348: Cannot create configurable product with child by REST API
- Merge remote-tracking branch 'mainline/develop' into MAGETWO-58348-Cannot-create-configurable-product-with-child-by-REST-API-2.2
2 parents 0e67b0e + d0688f2 commit 6ae1fce

File tree

61 files changed

+2740
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2740
-500
lines changed

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,12 @@ protected function getBundleOptions()
268268
'arguments' => [
269269
'data' => [
270270
'config' => [
271-
'componentType' => 'dynamicRows',
271+
'componentType' => Container::NAME,
272+
'component' => 'Magento_Bundle/js/components/bundle-dynamic-rows',
272273
'template' => 'ui/dynamic-rows/templates/collapsible',
273-
'label' => '',
274274
'additionalClasses' => 'admin__field-wide',
275-
'collapsibleHeader' => true,
276-
'columnsHeader' => false,
277-
'deleteProperty' => false,
278-
'addButton' => false,
279275
'dataScope' => 'data.bundle_options',
276+
'bundleSelectionsName' => 'product_bundle_container.bundle_selections'
280277
],
281278
],
282279
],
@@ -318,14 +315,11 @@ protected function getBundleOptions()
318315
'arguments' => [
319316
'data' => [
320317
'config' => [
321-
'componentType' => DynamicRows::NAME,
322-
'label' => '',
318+
'componentType' => Container::NAME,
319+
'component' => 'Magento_Bundle/js/components/bundle-dynamic-rows-grid',
323320
'sortOrder' => 50,
324321
'additionalClasses' => 'admin__field-wide',
325-
'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows-grid',
326322
'template' => 'ui/dynamic-rows/templates/default',
327-
'columnsHeader' => false,
328-
'columnsHeaderAfterRender' => true,
329323
'provider' => 'product_form.product_form_data_source',
330324
'dataProvider' => '${ $.dataScope }' . '.bundle_button_proxy',
331325
'identificationDRProperty' => 'product_id',
@@ -343,8 +337,7 @@ protected function getBundleOptions()
343337
'selection_qty' => '',
344338
],
345339
'links' => ['insertData' => '${ $.provider }:${ $.dataProvider }'],
346-
'source' => 'product',
347-
'addButton' => false,
340+
'source' => 'product'
348341
],
349342
],
350343
],
@@ -561,7 +554,7 @@ protected function getBundleSelections()
561554
'componentType' => Container::NAME,
562555
'isTemplate' => true,
563556
'component' => 'Magento_Ui/js/dynamic-rows/record',
564-
'is_collection' => true,
557+
'is_collection' => true
565558
],
566559
],
567560
],
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'underscore',
8+
'Magento_Ui/js/dynamic-rows/dynamic-rows-grid'
9+
], function (_, dynamicRowsGrid) {
10+
'use strict';
11+
12+
return dynamicRowsGrid.extend({
13+
defaults: {
14+
label: '',
15+
columnsHeader: false,
16+
columnsHeaderAfterRender: true,
17+
addButton: false
18+
},
19+
20+
/**
21+
* Initialize elements from grid
22+
*
23+
* @param {Array} data
24+
*
25+
* @returns {Object} Chainable.
26+
*/
27+
initElements: function (data) {
28+
var newData = this.getNewData(data),
29+
recordIndex;
30+
31+
this.parsePagesData(data);
32+
33+
if (newData.length) {
34+
if (this.insertData().length) {
35+
recordIndex = data.length - newData.length - 1;
36+
37+
_.each(newData, function (newRecord) {
38+
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
39+
}, this);
40+
}
41+
}
42+
43+
return this;
44+
},
45+
46+
/**
47+
* Mapping value from grid
48+
*
49+
* @param {Array} data
50+
*/
51+
mappingValue: function (data) {
52+
if (_.isEmpty(data)) {
53+
return;
54+
}
55+
56+
this._super();
57+
}
58+
});
59+
});
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'underscore',
8+
'mageUtils',
9+
'uiRegistry',
10+
'Magento_Ui/js/dynamic-rows/dynamic-rows'
11+
], function (_, utils, registry, dynamicRows) {
12+
'use strict';
13+
14+
return dynamicRows.extend({
15+
defaults: {
16+
label: '',
17+
collapsibleHeader: true,
18+
columnsHeader: false,
19+
deleteProperty: false,
20+
addButton: false
21+
},
22+
23+
/**
24+
* Set new data to dataSource,
25+
* delete element
26+
*
27+
* @param {Array} data - record data
28+
*/
29+
_updateData: function (data) {
30+
var elems = _.clone(this.elems()),
31+
path,
32+
dataArr,
33+
optionBaseData;
34+
35+
dataArr = this.recordData.splice(this.startIndex, this.recordData().length - this.startIndex);
36+
dataArr.splice(0, this.pageSize);
37+
elems = _.sortBy(this.elems(), function (elem) {
38+
return ~~elem.index;
39+
});
40+
41+
data.concat(dataArr).forEach(function (rec, idx) {
42+
if (elems[idx]) {
43+
elems[idx].recordId = rec[this.identificationProperty];
44+
}
45+
46+
if (!rec.position) {
47+
rec.position = this.maxPosition;
48+
this.setMaxPosition();
49+
}
50+
51+
path = this.dataScope + '.' + this.index + '.' + (this.startIndex + idx);
52+
optionBaseData = _.pick(rec, function (value) {
53+
return !_.isObject(value);
54+
});
55+
this.source.set(path, optionBaseData);
56+
this.source.set(path + '.bundle_button_proxy', []);
57+
this.source.set(path + '.bundle_selections', []);
58+
this.removeBundleItemsFromOption(idx);
59+
_.each(rec['bundle_selections'], function (obj, index) {
60+
this.source.set(path + '.bundle_button_proxy' + '.' + index, rec['bundle_button_proxy'][index]);
61+
this.source.set(path + '.bundle_selections' + '.' + index, obj);
62+
}, this);
63+
}, this);
64+
65+
this.elems(elems);
66+
},
67+
68+
/**
69+
* Removes nested dynamic-rows-grid rendered records from option
70+
*
71+
* @param {Number|String} index - element index
72+
*/
73+
removeBundleItemsFromOption: function (index) {
74+
var bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName),
75+
bundleSelectionsLength = (bundleSelections.elems() || []).length,
76+
i;
77+
78+
if (bundleSelectionsLength) {
79+
for (i = 0; i < bundleSelectionsLength; i++) {
80+
bundleSelections.elems()[0].destroy();
81+
}
82+
}
83+
},
84+
85+
/**
86+
* {@inheritdoc}
87+
*/
88+
processingAddChild: function (ctx, index, prop) {
89+
var recordIds = _.map(this.recordData(), function (rec) {
90+
return parseInt(rec['record_id'], 10);
91+
}),
92+
maxRecordId = _.max(recordIds);
93+
94+
prop = maxRecordId > -1 ? maxRecordId + 1 : prop;
95+
this._super(ctx, index, prop);
96+
}
97+
});
98+
});

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,25 @@ protected function _prepareRelationIndexSelect($parentIds = null)
197197
)->joinLeft(
198198
['e' => $this->getTable('catalog_product_entity')],
199199
'e.' . $linkField .' = l.parent_id',
200-
['e.entity_id as parent_id']
200+
[]
201201
)->join(
202202
['cs' => $this->getTable('store')],
203203
'',
204204
[]
205205
)->join(
206206
['i' => $idxTable],
207207
'l.child_id = i.entity_id AND cs.store_id = i.store_id',
208-
['attribute_id', 'store_id', 'value']
208+
[]
209209
)->group(
210-
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value']
210+
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value', 'l.child_id']
211+
)->columns(
212+
[
213+
'parent_id' => 'e.entity_id',
214+
'attribute_id' => 'i.attribute_id',
215+
'store_id' => 'i.store_id',
216+
'value' => 'i.value',
217+
'source_id' => 'l.child_id'
218+
]
211219
);
212220
if ($parentIds !== null) {
213221
$select->where('e.entity_id IN(?)', $parentIds);
@@ -222,7 +230,7 @@ protected function _prepareRelationIndexSelect($parentIds = null)
222230
'select' => $select,
223231
'entity_field' => new \Zend_Db_Expr('l.parent_id'),
224232
'website_field' => new \Zend_Db_Expr('cs.website_id'),
225-
'store_field' => new \Zend_Db_Expr('cs.store_id')
233+
'store_field' => new \Zend_Db_Expr('cs.store_id'),
226234
]
227235
);
228236

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Decimal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
8585
'pdd.attribute_id',
8686
'cs.store_id',
8787
'value' => $productValueExpression,
88+
'source_id' => 'cpe.entity_id',
8889
]
8990
);
9091

@@ -116,7 +117,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
116117
'select' => $select,
117118
'entity_field' => new \Zend_Db_Expr('cpe.entity_id'),
118119
'website_field' => new \Zend_Db_Expr('cs.website_id'),
119-
'store_field' => new \Zend_Db_Expr('cs.store_id')
120+
'store_field' => new \Zend_Db_Expr('cs.store_id'),
120121
]
121122
);
122123

0 commit comments

Comments
 (0)