Skip to content

Commit 7a69a27

Browse files
author
Kasian,Andrii(akasian)
committed
Merge pull request #501 from magento-dragons/S72
[Dragons] S72
2 parents 607763e + 259bcb0 commit 7a69a27

File tree

52 files changed

+1049
-476
lines changed

Some content is hidden

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

52 files changed

+1049
-476
lines changed

app/code/Magento/Bundle/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,13 @@
9090
<argument name="stockState" xsi:type="object">Magento\CatalogInventory\Api\StockStateInterface\Proxy</argument>
9191
</arguments>
9292
</type>
93+
<type name="Magento\Catalog\Helper\Product">
94+
<arguments>
95+
<argument name="reindexPriceIndexerData" xsi:type="array">
96+
<item name="byDataResult" xsi:type="array">
97+
<item name="is_relations_changed" xsi:type="string">is_relations_changed</item>
98+
</item>
99+
</argument>
100+
</arguments>
101+
</type>
93102
</config>

app/code/Magento/Catalog/Model/Layer/Category/FilterableAttributeList.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,18 @@ class FilterableAttributeList implements FilterableAttributeListInterface
2121
*/
2222
protected $storeManager;
2323

24-
/**
25-
* @var \Magento\Catalog\Model\Layer
26-
*/
27-
protected $layer;
28-
2924
/**
3025
* FilterableAttributeList constructor
3126
*
3227
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory
3328
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
34-
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
3529
*/
3630
public function __construct(
3731
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory,
38-
\Magento\Store\Model\StoreManagerInterface $storeManager,
39-
\Magento\Catalog\Model\Layer\Resolver $layerResolver
32+
\Magento\Store\Model\StoreManagerInterface $storeManager
4033
) {
4134
$this->collectionFactory = $collectionFactory;
4235
$this->storeManager = $storeManager;
43-
$this->layer = $layerResolver->get();
4436
}
4537

4638
/**
@@ -50,14 +42,9 @@ public function __construct(
5042
*/
5143
public function getList()
5244
{
53-
$setIds = $this->layer->getProductCollection()->getSetIds();
54-
if (!$setIds) {
55-
return [];
56-
}
5745
/** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
5846
$collection = $this->collectionFactory->create();
5947
$collection->setItemObjectClass('Magento\Catalog\Model\Resource\Eav\Attribute')
60-
->setAttributeSetFilter($setIds)
6148
->addStoreLabel($this->storeManager->getStore()->getId())
6249
->setOrder('position', 'ASC');
6350
$collection = $this->_prepareAttributeCollection($collection);

app/code/Magento/Catalog/Model/Layer/Search/CollectionFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public function filter(
6464
->addStoreFilter()
6565
->addUrlRewrite()
6666
->setVisibility($this->productVisibility->getVisibleInSearchIds())
67-
->setOrder('relevance', Select::SQL_ASC);
67+
->setOrder('relevance', Select::SQL_DESC);
6868
}
6969
}

app/code/Magento/Catalog/Model/Layer/Search/FilterableAttributeList.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@
88

99
class FilterableAttributeList extends \Magento\Catalog\Model\Layer\Category\FilterableAttributeList
1010
{
11-
/**
12-
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory
13-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
14-
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
15-
*/
16-
public function __construct(
17-
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory,
18-
\Magento\Store\Model\StoreManagerInterface $storeManager,
19-
\Magento\Catalog\Model\Layer\Resolver $layerResolver
20-
) {
21-
parent::__construct($collectionFactory, $storeManager, $layerResolver);
22-
}
23-
2411
/**
2512
* @param \Magento\Catalog\Model\Resource\Product\Attribute\Collection $collection
2613
* @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection

app/code/Magento/Catalog/Test/Unit/Model/Layer/Category/FilterableAttributeListTest.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class FilterableAttributeListTest extends \PHPUnit_Framework_TestCase
2525
*/
2626
protected $storeManagerMock;
2727

28-
/**
29-
* @var \PHPUnit_Framework_MockObject_MockObject
30-
*/
31-
protected $layerMock;
32-
3328
protected function setUp()
3429
{
3530
$this->collectionFactoryMock = $this->getMock(
@@ -39,50 +34,15 @@ protected function setUp()
3934
'\Magento\Store\Model\StoreManagerInterface', [], [], '', false
4035
);
4136

42-
$this->layerMock = $this->getMock(
43-
'Magento\Catalog\Model\Layer\Search', [], [], '', false
44-
);
45-
46-
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver $layerResolver */
47-
$layerResolver = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Resolver')
48-
->disableOriginalConstructor()
49-
->setMethods(['get', 'create'])
50-
->getMock();
51-
$layerResolver->expects($this->any())
52-
->method($this->anything())
53-
->will($this->returnValue($this->layerMock));
54-
5537
$this->model = new \Magento\Catalog\Model\Layer\Search\FilterableAttributeList(
5638
$this->collectionFactoryMock,
57-
$this->storeManagerMock,
58-
$layerResolver
59-
);
60-
61-
}
62-
63-
public function testGetListWithEmptyIds()
64-
{
65-
$productCollectionMock = $this->getMock(
66-
'\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false
39+
$this->storeManagerMock
6740
);
68-
$this->layerMock->expects($this->once())->method('getProductCollection')
69-
->will($this->returnValue($productCollectionMock));
70-
$productCollectionMock->expects($this->once())->method('getSetIds')->will($this->returnValue([]));
7141

72-
$this->collectionFactoryMock->expects($this->never())->method('create');
73-
$this->assertEquals([], $this->model->getList());
7442
}
7543

7644
public function testGetList()
7745
{
78-
$productCollectionMock = $this->getMock(
79-
'\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false
80-
);
81-
$this->layerMock->expects($this->once())->method('getProductCollection')
82-
->will($this->returnValue($productCollectionMock));
83-
$setIds = [2, 3, 5];
84-
$productCollectionMock->expects($this->once())->method('getSetIds')->will($this->returnValue($setIds));
85-
8646
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
8747
$this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
8848

@@ -102,11 +62,6 @@ public function testGetList()
10262
->method('setItemObjectClass')
10363
->with('Magento\Catalog\Model\Resource\Eav\Attribute')
10464
->will($this->returnSelf());
105-
$collectionMock
106-
->expects($this->once())
107-
->method('setAttributeSetFilter')
108-
->with($setIds)
109-
->will($this->returnSelf());
11065
$collectionMock
11166
->expects($this->once())
11267
->method('addStoreLabel')

app/code/Magento/Catalog/Test/Unit/Model/Layer/Search/FilterableAttributeListTest.php

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class FilterableAttributeListTest extends \PHPUnit_Framework_TestCase
2525
*/
2626
protected $storeManagerMock;
2727

28-
/**
29-
* @var \PHPUnit_Framework_MockObject_MockObject
30-
*/
31-
protected $layerMock;
32-
3328
protected function setUp()
3429
{
3530
$this->collectionFactoryMock = $this->getMock(
@@ -39,23 +34,9 @@ protected function setUp()
3934
'\Magento\Store\Model\StoreManagerInterface', [], [], '', false
4035
);
4136

42-
$this->layerMock = $this->getMock(
43-
'\Magento\Catalog\Model\Layer\Search', [], [], '', false
44-
);
45-
46-
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver $layerResolver */
47-
$layerResolver = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Resolver')
48-
->disableOriginalConstructor()
49-
->setMethods(['get', 'create'])
50-
->getMock();
51-
$layerResolver->expects($this->any())
52-
->method($this->anything())
53-
->will($this->returnValue($this->layerMock));
54-
5537
$this->model = new \Magento\Catalog\Model\Layer\Search\FilterableAttributeList(
5638
$this->collectionFactoryMock,
57-
$this->storeManagerMock,
58-
$layerResolver
39+
$this->storeManagerMock
5940
);
6041

6142
}
@@ -65,14 +46,6 @@ protected function setUp()
6546
*/
6647
public function testGetList()
6748
{
68-
$productCollectionMock = $this->getMock(
69-
'\Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false
70-
);
71-
$this->layerMock->expects($this->once())->method('getProductCollection')
72-
->will($this->returnValue($productCollectionMock));
73-
$setIds = [2, 3, 5];
74-
$productCollectionMock->expects($this->once())->method('getSetIds')->will($this->returnValue($setIds));
75-
7649
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
7750
$this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
7851

@@ -92,11 +65,6 @@ public function testGetList()
9265
->method('setItemObjectClass')
9366
->with('Magento\Catalog\Model\Resource\Eav\Attribute')
9467
->will($this->returnSelf());
95-
$collectionMock
96-
->expects($this->once())
97-
->method('setAttributeSetFilter')
98-
->with($setIds)
99-
->will($this->returnSelf());
10068
$collectionMock
10169
->expects($this->once())
10270
->method('addStoreLabel')

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use Magento\Framework\App\Resource;
1212
use Magento\Framework\App\ScopeResolverInterface;
1313
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\DB\Ddl\Table;
1415
use Magento\Framework\DB\Select;
1516
use Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderInterface;
1617
use Magento\Framework\Search\Request\BucketInterface;
17-
use Magento\Store\Model\Store;
1818

1919
/**
2020
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -68,28 +68,31 @@ public function __construct(
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function getDataSet(BucketInterface $bucket, array $dimensions)
72-
{
71+
public function getDataSet(
72+
BucketInterface $bucket,
73+
array $dimensions,
74+
Table $entityIdsTable
75+
) {
7376
$currentScope = $dimensions['scope']->getValue();
7477

7578
$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());
7679

80+
$select = $this->getSelect();
81+
7782
if ($attribute->getAttributeCode() == 'price') {
7883
/** @var \Magento\Store\Model\Store $store */
7984
$store = $this->scopeResolver->getScope($currentScope);
8085
if (!$store instanceof \Magento\Store\Model\Store) {
8186
throw new \RuntimeException('Illegal scope resolved');
8287
}
8388
$table = $this->resource->getTableName('catalog_product_index_price');
84-
$select = $this->getSelect();
8589
$select->from(['main_table' => $table], null)
8690
->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price'])
8791
->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
8892
->where('main_table.website_id = ?', $store->getWebsiteId());
8993
} else {
9094
$currentScopeId = $this->scopeResolver->getScope($currentScope)
9195
->getId();
92-
$select = $this->getSelect();
9396
$table = $this->resource->getTableName(
9497
'catalog_product_index_eav' . ($attribute->getBackendType() == 'decimal' ? '_decimal' : '')
9598
);
@@ -98,6 +101,12 @@ public function getDataSet(BucketInterface $bucket, array $dimensions)
98101
->where('main_table.store_id = ? ', $currentScopeId);
99102
}
100103

104+
$select->joinInner(
105+
['entities' => $entityIdsTable->getName()],
106+
'main_table.entity_id = entities.entity_id',
107+
[]
108+
);
109+
101110
return $select;
102111
}
103112

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Customer\Model\Session;
1010
use Magento\Framework\App\Resource;
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use Magento\Framework\DB\Ddl\Table;
1213
use Magento\Framework\DB\Select;
1314
use Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderInterface as MysqlDataProviderInterface;
1415
use Magento\Framework\Search\Dynamic\DataProviderInterface;
@@ -83,20 +84,22 @@ public function getRange()
8384
/**
8485
* {@inheritdoc}
8586
*/
86-
public function getAggregations(array $entityIds)
87+
public function getAggregations(\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
8788
{
8889
$aggregation = [
89-
'count' => 'count(DISTINCT entity_id)',
90+
'count' => 'count(DISTINCT main_table.entity_id)',
9091
'max' => 'MAX(min_price)',
9192
'min' => 'MIN(min_price)',
92-
'std' => 'STDDEV_SAMP(min_price)'
93+
'std' => 'STDDEV_SAMP(min_price)',
9394
];
9495

9596
$select = $this->getSelect();
9697

9798
$tableName = $this->resource->getTableName('catalog_product_index_price');
98-
$select->from($tableName, [])
99-
->where('entity_id IN (?)', $entityIds)
99+
/** @var Table $table */
100+
$table = $entityStorage->getSource();
101+
$select->from(['main_table' => $tableName], [])
102+
->joinInner(['entities' => $table->getName()], 'main_table.entity_id = entities.entity_id', [])
100103
->columns($aggregation);
101104

102105
$select = $this->setCustomerGroupId($select);
@@ -109,20 +112,26 @@ public function getAggregations(array $entityIds)
109112
/**
110113
* {@inheritdoc}
111114
*/
112-
public function getInterval(BucketInterface $bucket, array $dimensions, array $entityIds)
113-
{
114-
$select = $this->dataProvider->getDataSet($bucket, $dimensions);
115-
$select->where('main_table.entity_id IN (?)', $entityIds);
115+
public function getInterval(
116+
BucketInterface $bucket,
117+
array $dimensions,
118+
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
119+
) {
120+
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
116121

117122
return $this->intervalFactory->create(['select' => $select]);
118123
}
119124

120125
/**
121126
* {@inheritdoc}
122127
*/
123-
public function getAggregation(BucketInterface $bucket, array $dimensions, $range, array $entityIds)
124-
{
125-
$select = $this->dataProvider->getDataSet($bucket, $dimensions);
128+
public function getAggregation(
129+
BucketInterface $bucket,
130+
array $dimensions,
131+
$range,
132+
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
133+
) {
134+
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
126135
$column = $select->getPart(Select::COLUMNS)[0];
127136
$select->reset(Select::COLUMNS);
128137
$rangeExpr = new \Zend_Db_Expr(
@@ -132,7 +141,6 @@ public function getAggregation(BucketInterface $bucket, array $dimensions, $rang
132141
$select
133142
->columns(['range' => $rangeExpr])
134143
->columns(['metrix' => 'COUNT(*)'])
135-
->where('main_table.entity_id in (?)', $entityIds)
136144
->group('range')
137145
->order('range');
138146
$result = $this->connection->fetchPairs($select);
@@ -157,7 +165,7 @@ public function prepareData($range, array $dbRanges)
157165
$data[] = [
158166
'from' => $fromPrice,
159167
'to' => $toPrice,
160-
'count' => $count
168+
'count' => $count,
161169
];
162170
}
163171
}

0 commit comments

Comments
 (0)