Skip to content

Commit fe3792e

Browse files
MAGETWO-59467: Checkbox "User Defined" is visible for bundle product option with input type checkbox and multi select
1 parent 686df6b commit fe3792e

File tree

6 files changed

+102
-3
lines changed

6 files changed

+102
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ protected function getOptionInfo()
518518
'dataType' => Form\Element\DataType\Text::NAME,
519519
'formElement' => Form\Element\Select::NAME,
520520
'componentType' => Form\Field::NAME,
521-
'component' => 'Magento_Bundle/js/components/bundle-input-type',
521+
'component' => 'Magento_Ui/js/form/element/select',
522522
'parentContainer' => 'product_bundle_container',
523523
'selections' => 'bundle_selections',
524524
'isDefaultIndex' => 'is_default',
@@ -594,8 +594,11 @@ protected function getBundleSelections()
594594
'config' => [
595595
'componentType' => Container::NAME,
596596
'isTemplate' => true,
597-
'component' => 'Magento_Ui/js/dynamic-rows/record',
598-
'is_collection' => true
597+
'component' => 'Magento_Bundle/js/components/bundle-record',
598+
'is_collection' => true,
599+
'imports' => [
600+
'onTypeChanged' => '${ $.provider }:${ $.bundleOptionsDataScope }.type'
601+
]
599602
],
600603
],
601604
],

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-checkbox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ define([
5858

5959
this.prefer = typeMap[type];
6060
this.elementTmpl(this.templates[typeMap[type]]);
61+
62+
if (this.prefer === 'radio' && this.checked()) {
63+
this.clearValues();
64+
}
6165
},
6266

6367
/**

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows-grid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ define([
2929
recordIndex;
3030

3131
this.parsePagesData(data);
32+
this.templates.record.bundleOptionsDataScope = this.dataScope;
3233

3334
if (newData.length) {
3435
if (this.insertData().length) {

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-input-type.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/**
7+
* @deprecated Not used anymore
8+
* @see Magento_Bundle/js/components/bundle-record
9+
* @see Magento_Bundle/js/components/bundle-checkbox
10+
*/
611
define([
712
'Magento_Ui/js/form/element/select',
813
'uiRegistry'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'Magento_Ui/js/dynamic-rows/record',
7+
'uiRegistry'
8+
], function (Record, registry) {
9+
'use strict';
10+
11+
return Record.extend({
12+
/**
13+
* @param {String} val - type of Input Type
14+
*/
15+
onTypeChanged: function (val) {
16+
var columnVisibility = !(val === 'multi' || val === 'checkbox');
17+
18+
registry.async(this.name + '.' + 'selection_can_change_qty')(function (elem) {
19+
elem.visible(columnVisibility);
20+
});
21+
}
22+
});
23+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
8+
define(['Magento_Bundle/js/components/bundle-checkbox', 'uiRegistry'], function (BundleCheckbox, registry) {
9+
'use strict';
10+
11+
describe('Magento_Bundle/js/components/bundle-checkbox', function () {
12+
13+
var unit,
14+
typeMap = {
15+
typeMap: {
16+
select: 'radio',
17+
radio: 'radio',
18+
checkbox: 'checkbox',
19+
multi: 'checkbox'
20+
}
21+
};
22+
23+
beforeEach(function () {
24+
unit = new BundleCheckbox({
25+
dataScope: 'bundle-checkbox',
26+
elementTmpl: jasmine.createSpy(),
27+
clearValues: jasmine.createSpy()
28+
});
29+
});
30+
31+
describe('test changeType method', function () {
32+
it('Do not clear values for "multi" select type', function () {
33+
spyOn(registry, 'get').and.returnValue(typeMap);
34+
spyOn(unit, 'checked').and.returnValue(false);
35+
36+
unit.changeType('multi');
37+
38+
expect(unit.prefer).toBe('checkbox');
39+
expect(unit.clearValues).not.toHaveBeenCalled();
40+
});
41+
42+
it('Do not clear values for "radio" select type if item not checked', function () {
43+
spyOn(registry, 'get').and.returnValue(typeMap);
44+
spyOn(unit, 'checked').and.returnValue(false);
45+
46+
unit.changeType('select');
47+
48+
expect(unit.prefer).toBe('radio');
49+
expect(unit.clearValues).not.toHaveBeenCalled();
50+
});
51+
52+
it('Clear values for "radio" select type', function () {
53+
spyOn(registry, 'get').and.returnValue(typeMap);
54+
spyOn(unit, 'checked').and.returnValue(true);
55+
56+
unit.changeType('select');
57+
58+
expect(unit.prefer).toBe('radio');
59+
expect(unit.clearValues).toHaveBeenCalled();
60+
});
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)