Skip to content

Commit 3ada67f

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-65466: [Backport] - Issue when deleting item from Product options grid containing more than 20 options - for 2.1
1 parent ba126b3 commit 3ada67f

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ private function fillProductOptions(Product $product, array $productOptions)
453453
continue;
454454
}
455455

456-
//Ignoring ID because front-end messes it up.
457-
$customOptionData['option_id'] = null;
456+
if (empty($customOptionData['option_id'])) {
457+
$customOptionData['option_id'] = null;
458+
}
458459
if (isset($customOptionData['values'])) {
459460
$customOptionData['values'] = array_filter(
460461
$customOptionData['values'],

app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,6 @@ define([
1010
], function (DynamicRows, _, utils) {
1111
'use strict';
1212

13-
var maxId = 0,
14-
15-
/**
16-
* Stores max option_id value of the options from recordData once on initialization
17-
* @param {Array} data - array with records data
18-
*/
19-
initMaxId = function (data) {
20-
if (data && data.length) {
21-
maxId = _.max(data, function (record) {
22-
return parseInt(record['option_id'], 10) || 0;
23-
})['option_id'];
24-
maxId = parseInt(maxId, 10) || 0;
25-
}
26-
};
27-
2813
return DynamicRows.extend({
2914
defaults: {
3015
mappingSettings: {
@@ -39,14 +24,6 @@ define([
3924
identificationDRProperty: 'option_id'
4025
},
4126

42-
/** @inheritdoc */
43-
initialize: function () {
44-
this._super();
45-
initMaxId(this.recordData());
46-
47-
return this;
48-
},
49-
5027
/** @inheritdoc */
5128
processingInsertData: function (data) {
5229
var options = [],
@@ -65,7 +42,16 @@ define([
6542
if (currentOption.hasOwnProperty('sort_order')) {
6643
delete currentOption['sort_order'];
6744
}
68-
currentOption['option_id'] = ++maxId;
45+
if (currentOption.hasOwnProperty('option_id')) {
46+
delete currentOption['option_id'];
47+
}
48+
if (currentOption.values.length > 0) {
49+
currentOption.values.each(function (optionValue) {
50+
delete optionValue['option_id'];
51+
delete optionValue['option_type_id'];
52+
})
53+
}
54+
6955
options.push(currentOption);
7056
});
7157
});
@@ -90,9 +76,7 @@ define([
9076

9177
/** @inheritdoc */
9278
processingAddChild: function (ctx, index, prop) {
93-
if (ctx && !_.isNumber(ctx['option_id'])) {
94-
ctx['option_id'] = ++maxId;
95-
} else if (!ctx) {
79+
if (!ctx) {
9680
this.showSpinner(true);
9781
this.addChild(ctx, index, prop);
9882

0 commit comments

Comments
 (0)