Skip to content

Commit 76f4fdf

Browse files
committed
Merge branch 'MAGETWO-61826' into MAGETWO-61826_63014
2 parents 4148ee1 + 234e42b commit 76f4fdf

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,27 @@ define([
5454
if (!data) {
5555
return;
5656
}
57-
data.each(function (item) {
57+
_.each(data, function (item) {
5858
if (!item.options) {
5959
return;
6060
}
61-
item.options.each(function (option) {
61+
_.each(item.options, function (option) {
6262
currentOption = utils.copy(option);
6363

6464
if (currentOption.hasOwnProperty('sort_order')) {
6565
delete currentOption['sort_order'];
6666
}
67-
currentOption['option_id'] = ++maxId;
67+
68+
if (currentOption.hasOwnProperty('option_id')) {
69+
delete currentOption['option_id'];
70+
}
71+
72+
if (currentOption.values.length > 0) {
73+
_.each(currentOption.values, function (optionValue) {
74+
delete optionValue['option_id'];
75+
delete optionValue['option_type_id'];
76+
});
77+
}
6878
options.push(currentOption);
6979
});
7080
});
@@ -73,7 +83,7 @@ define([
7383
return;
7484
}
7585
this.cacheGridData = options;
76-
options.each(function (opt) {
86+
_.each(options, function (opt) {
7787
this.mappingValue(opt);
7888
}, this);
7989

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
8+
define([
9+
'Magento_Catalog/js/components/dynamic-rows-import-custom-options'
10+
], function (DynamicRows) {
11+
'use strict';
12+
13+
describe('Magento_Catalog/js/components/dynamic-rows-import-custom-options', function () {
14+
var model, data;
15+
16+
beforeEach(function () {
17+
model = new DynamicRows({
18+
index: 'dynamic_rows',
19+
name: 'dynamic_rows',
20+
indexField: 'id',
21+
dataScope: '',
22+
rows: [{
23+
identifier: 'row'
24+
}]
25+
});
26+
data = [{
27+
'options': [
28+
{
29+
'sort_order': 1,
30+
'option_id': 1,
31+
'option_type_id': 1,
32+
'values': [{
33+
'option_id': 1,
34+
'option_type_id': 1,
35+
'some_fake_value': 1
36+
}]
37+
},
38+
{
39+
'sort_order': 2,
40+
'option_id': 2,
41+
'option_type_id': 2,
42+
'values': [{
43+
'option_id': 2,
44+
'option_type_id': 2
45+
}]
46+
}
47+
]
48+
}];
49+
model.source = {
50+
set: jasmine.createSpy()
51+
};
52+
model.insertData = jasmine.createSpy().and.returnValue([]);
53+
});
54+
55+
describe('Check processingInsertData', function () {
56+
it('Check with empty data.', function () {
57+
model.processingInsertData();
58+
expect(model.cacheGridData).toEqual([]);
59+
expect(model.insertData).not.toHaveBeenCalled();
60+
});
61+
62+
it('Check with empty options data.', function () {
63+
data = [{
64+
'options': []
65+
}];
66+
model.processingInsertData(data);
67+
expect(model.cacheGridData).toEqual([]);
68+
expect(model.insertData).not.toHaveBeenCalled();
69+
});
70+
71+
it('Check with fake imported custom options data.', function () {
72+
model.processingInsertData(data);
73+
expect(model.insertData).toHaveBeenCalled();
74+
expect(model.cacheGridData[0]).toEqual({
75+
'option_type_id': 1,
76+
'position': 1,
77+
'values': [{
78+
'some_fake_value': 1
79+
}]
80+
});
81+
expect(model.cacheGridData[1]).toEqual({
82+
'option_type_id': 2,
83+
'position': 2,
84+
'values': [{}]
85+
});
86+
});
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)