Skip to content

Commit 74465b6

Browse files
Merge pull request #2295 from magento-tango/2.2-develop-PR-2
Bugs - MAGETWO-71662 Update On Save Reindex do not work on configurable product options changing - MAGETWO-86354 Deleting bundled options does not work
2 parents fb8ea46 + 6799b6f commit 74465b6

File tree

9 files changed

+163
-22
lines changed

9 files changed

+163
-22
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ protected function getBundleOptions()
314314
'template' => 'ui/dynamic-rows/templates/collapsible',
315315
'additionalClasses' => 'admin__field-wide',
316316
'dataScope' => 'data.bundle_options',
317+
'isDefaultFieldScope' => 'is_default',
317318
'bundleSelectionsName' => 'product_bundle_container.bundle_selections'
318319
],
319320
],
@@ -378,6 +379,9 @@ protected function getBundleOptions()
378379
'selection_qty' => '',
379380
],
380381
'links' => ['insertData' => '${ $.provider }:${ $.dataProvider }'],
382+
'imports' => [
383+
'inputType' => '${$.provider}:${$.dataScope}.type'
384+
],
381385
'source' => 'product'
382386
],
383387
],
@@ -594,10 +598,13 @@ protected function getBundleSelections()
594598
'config' => [
595599
'componentType' => Container::NAME,
596600
'isTemplate' => true,
597-
'component' => 'Magento_Bundle/js/components/bundle-record',
601+
'component' => 'Magento_Ui/js/dynamic-rows/record',
598602
'is_collection' => true,
599603
'imports' => [
600-
'onTypeChanged' => '${ $.provider }:${ $.bundleOptionsDataScope }.type'
604+
'inputType' => '${$.parentName}:inputType'
605+
],
606+
'exports' => [
607+
'isDefaultValue' => '${$.parentName}:isDefaultValue.${$.index}'
601608
]
602609
],
603610
],
@@ -691,11 +698,15 @@ protected function getBundleSelections()
691698
'componentType' => Form\Field::NAME,
692699
'formElement' => Form\Element\Checkbox::NAME,
693700
'dataType' => Form\Element\DataType\Price::NAME,
701+
'component' => 'Magento_Bundle/js/components/bundle-user-defined-checkbox',
694702
'label' => __('User Defined'),
695703
'dataScope' => 'selection_can_change_qty',
696704
'value' => '1',
697705
'valueMap' => ['true' => '1', 'false' => '0'],
698706
'sortOrder' => 110,
707+
'imports' => [
708+
'inputType' => '${$.parentName}:inputType'
709+
]
699710
],
700711
],
701712
],

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ define([
1414
clearing: false,
1515
parentContainer: '',
1616
parentSelections: '',
17-
changer: ''
17+
changer: '',
18+
exports: {
19+
value: '${$.parentName}:isDefaultValue'
20+
}
1821
},
1922

2023
/**
@@ -58,10 +61,6 @@ define([
5861

5962
this.prefer = typeMap[type];
6063
this.elementTmpl(this.templates[typeMap[type]]);
61-
62-
if (this.prefer === 'radio' && this.checked()) {
63-
this.clearValues();
64-
}
6564
},
6665

6766
/**

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,57 @@ define([
1414
label: '',
1515
columnsHeader: false,
1616
columnsHeaderAfterRender: true,
17-
addButton: false
17+
addButton: false,
18+
isDefaultFieldScope: 'is_default',
19+
defaultRecords: {
20+
use: [],
21+
moreThanOne: false,
22+
state: {}
23+
},
24+
listens: {
25+
inputType: 'onInputTypeChange',
26+
isDefaultValue: 'onIsDefaultValue'
27+
}
28+
},
29+
30+
/**
31+
* Handler for type select.
32+
*
33+
* @param {String} inputType - changed.
34+
*/
35+
onInputTypeChange: function (inputType) {
36+
if (this.defaultRecords.moreThanOne && (inputType === 'radio' || inputType === 'select')) {
37+
_.each(this.defaultRecords.use, function (index, counter) {
38+
this.source.set(
39+
this.dataScope + '.bundle_selections.' + index + '.' + this.isDefaultFieldScope,
40+
counter ? '0' : '1'
41+
);
42+
}.bind(this));
43+
}
44+
},
45+
46+
/**
47+
* Handler for is_default field.
48+
*
49+
* @param {Object} data - changed data.
50+
*/
51+
onIsDefaultValue: function (data) {
52+
var cb,
53+
use = 0;
54+
55+
this.defaultRecords.use = [];
56+
57+
cb = function (elem, key) {
58+
59+
if (~~elem) {
60+
this.defaultRecords.use.push(key);
61+
use++;
62+
}
63+
64+
this.defaultRecords.moreThanOne = use > 1;
65+
}.bind(this);
66+
67+
_.each(data, cb);
1868
},
1969

2070
/**
@@ -29,7 +79,6 @@ define([
2979
recordIndex;
3080

3181
this.parsePagesData(data);
32-
this.templates.record.bundleOptionsDataScope = this.dataScope;
3382

3483
if (newData.length) {
3584
if (this.insertData().length) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/element/single-checkbox'
8+
], function (Checkbox) {
9+
'use strict';
10+
11+
return Checkbox.extend({
12+
defaults: {
13+
listens: {
14+
inputType: 'onInputTypeChange'
15+
}
16+
},
17+
18+
/**
19+
* Handler for "inputType" property
20+
*
21+
* @param {String} data
22+
*/
23+
onInputTypeChange: function (data) {
24+
data === 'checkbox' || data === 'multi' ?
25+
this.clear()
26+
.visible(false) :
27+
this.visible(true);
28+
}
29+
});
30+
});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function reindexEntities($processIds)
8282
$this->_prepareIndex($processIds);
8383
$this->_prepareRelationIndex($processIds);
8484
$this->_removeNotVisibleEntityFromIndex();
85+
8586
return $this;
8687
}
8788

@@ -164,6 +165,7 @@ protected function _prepareRelationIndexSelect($parentIds = null)
164165
$connection = $this->getConnection();
165166
$idxTable = $this->getIdxTable();
166167
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
168+
167169
$select = $connection->select()->from(
168170
['l' => $this->getTable('catalog_product_relation')],
169171
[]
@@ -179,6 +181,16 @@ protected function _prepareRelationIndexSelect($parentIds = null)
179181
['i' => $idxTable],
180182
'l.child_id = i.entity_id AND cs.store_id = i.store_id',
181183
[]
184+
)->join(
185+
['sw' => $this->getTable('store_website')],
186+
"cs.website_id = sw.website_id",
187+
[]
188+
)->joinLeft(
189+
['cpw' => $this->getTable('catalog_product_website')],
190+
"i.entity_id = cpw.product_id AND sw.website_id = cpw.website_id",
191+
[]
192+
)->where(
193+
'cpw.product_id IS NOT NULL'
182194
)->group(
183195
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value', 'l.child_id']
184196
)->columns(

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,20 @@ public function testReindexWithoutArgumentsExecutesReindexAll()
113113
$this->_model->reindex();
114114
}
115115

116-
public function testReindexWithNotNullArgumentExecutesReindexEntities()
117-
{
118-
$childIds = [1, 2, 3];
119-
$parentIds = [4];
120-
$reindexIds = array_merge($childIds, $parentIds);
116+
/**
117+
* @param array $ids
118+
* @param array $parentIds
119+
* @param array $childIds
120+
* @throws \Exception
121+
* @dataProvider reindexEntitiesDataProvider
122+
*/
123+
public function testReindexWithNotNullArgumentExecutesReindexEntities(
124+
array $ids,
125+
array $parentIds,
126+
array $childIds
127+
) {
128+
$reindexIds = array_unique(array_merge($ids, $parentIds, $childIds));
129+
121130
$connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
122131
->getMockForAbstractClass();
123132

@@ -129,12 +138,23 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities()
129138
->disableOriginalConstructor()
130139
->getMock();
131140

132-
$eavSource->expects($this->once())->method('getRelationsByChild')->with($childIds)->willReturn($parentIds);
133-
$eavSource->expects($this->once())->method('getRelationsByParent')
134-
->with(array_unique(array_merge($parentIds, $childIds)))->willReturn($parentIds);
141+
$eavSource->expects($this->once())
142+
->method('getRelationsByChild')
143+
->with($ids)
144+
->willReturn($parentIds);
145+
$eavSource->expects($this->once())
146+
->method('getRelationsByParent')
147+
->with(array_unique(array_merge($parentIds, $ids)))
148+
->willReturn($childIds);
135149

136-
$eavDecimal->expects($this->once())->method('getRelationsByChild')->with($reindexIds)->willReturn($reindexIds);
137-
$eavDecimal->expects($this->once())->method('getRelationsByParent')->with($reindexIds)->willReturn([]);
150+
$eavDecimal->expects($this->once())
151+
->method('getRelationsByChild')
152+
->with($reindexIds)
153+
->willReturn($parentIds);
154+
$eavDecimal->expects($this->once())
155+
->method('getRelationsByParent')
156+
->with(array_unique(array_merge($parentIds, $reindexIds)))
157+
->willReturn($childIds);
138158

139159
$eavSource->expects($this->once())->method('getConnection')->willReturn($connectionMock);
140160
$eavDecimal->expects($this->once())->method('getConnection')->willReturn($connectionMock);
@@ -154,6 +174,15 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities()
154174
->method('create')
155175
->will($this->returnValue($eavDecimal));
156176

157-
$this->_model->reindex($childIds);
177+
$this->_model->reindex($ids);
178+
}
179+
180+
public function reindexEntitiesDataProvider()
181+
{
182+
return [
183+
[[4], [], [1, 2, 3]],
184+
[[3], [4], []],
185+
[[5], [], []]
186+
];
158187
}
159188
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public function testReindexEntitiesForConfigurableProduct()
9696

9797
$result = $connection->fetchAll($select);
9898
$this->assertCount(0, $result);
99+
100+
/** @var \Magento\Catalog\Model\Product $product1 **/
101+
$product1 = $productRepository->getById(10);
102+
$product1->setStatus(Status::STATUS_ENABLED)->setWebsiteIds([]);
103+
$productRepository->save($product1);
104+
105+
/** @var \Magento\Catalog\Model\Product $product2 **/
106+
$product2 = $productRepository->getById(20);
107+
$product2->setStatus(Status::STATUS_ENABLED);
108+
$productRepository->save($product2);
109+
110+
$result = $connection->fetchAll($select);
111+
$this->assertCount(1, $result);
99112
}
100113

101114
/**

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
525525
*/
526526
public function testAdvancedSearchCompositeProductWithOutOfStockOption()
527527
{
528-
$this->markTestSkipped('MAGETWO-71445: configurable product created incorrectly - children not linked').
529528
/** @var Attribute $attribute */
530529
$attribute = $this->objectManager->get(Attribute::class)
531530
->loadByCode(Product::ENTITY, 'test_configurable');

dev/tests/js/jasmine/tests/app/code/Magento/Bundle/adminhtml/js/components/bundle-checkbox.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ define(['Magento_Bundle/js/components/bundle-checkbox', 'uiRegistry'], function
5656
unit.changeType('select');
5757

5858
expect(unit.prefer).toBe('radio');
59-
expect(unit.clearValues).toHaveBeenCalled();
6059
});
6160
});
6261
});

0 commit comments

Comments
 (0)