Skip to content

Commit 8bd1166

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'mainline/develop' into cart-price-rules
2 parents e2f09f1 + 3beb931 commit 8bd1166

File tree

141 files changed

+5039
-2286
lines changed

Some content is hidden

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

141 files changed

+5039
-2286
lines changed

app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@
2727
</form>
2828
<script data-template="search-suggest" type="text/x-magento-template">
2929
<ul class="search-global-menu">
30-
<% if (data.items.length) { %>
30+
<li class="item">
31+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('catalog/product/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Products</a>
32+
</li>
33+
<li class="item">
34+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('sales/order/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Orders</a>
35+
</li>
36+
<li class="item">
37+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('customer/index/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Customers</a>
38+
</li>
39+
<li class="item">
40+
<a href="<?php /* @escapeNotVerified */ echo $block->getURL('cms/page/index/'); ?>?search=<%- data.term%>" class="title">"<%- data.term%>" in Pages</a>
41+
</li>
42+
<% if (data.items.length) { %>
3143
<% _.each(data.items, function(value){ %>
3244
<li class="item"
3345
<%- data.optionData(value) %>

app/code/Magento/Catalog/Model/Indexer/Product/Flat/AbstractAction.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Product\Flat;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Framework\Model\Entity\MetadataPool;
911

1012
/**
1113
* Abstract action reindex class
12-
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1315
*/
1416
abstract class AbstractAction
1517
{
@@ -72,6 +74,12 @@ abstract class AbstractAction
7274
protected $_flatTableBuilder;
7375

7476
/**
77+
* @var MetadataPool
78+
*/
79+
private $metadataPool;
80+
81+
/**
82+
* @param MetadataPool $metadataPool
7583
* @param \Magento\Framework\App\ResourceConnection $resource
7684
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
7785
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
@@ -80,6 +88,7 @@ abstract class AbstractAction
8088
* @param FlatTableBuilder $flatTableBuilder
8189
*/
8290
public function __construct(
91+
MetadataPool $metadataPool,
8392
\Magento\Framework\App\ResourceConnection $resource,
8493
\Magento\Store\Model\StoreManagerInterface $storeManager,
8594
\Magento\Catalog\Helper\Product\Flat\Indexer $productHelper,
@@ -93,6 +102,7 @@ public function __construct(
93102
$this->_connection = $resource->getConnection();
94103
$this->_tableBuilder = $tableBuilder;
95104
$this->_flatTableBuilder = $flatTableBuilder;
105+
$this->metadataPool = $metadataPool;
96106
}
97107

98108
/**
@@ -194,6 +204,8 @@ protected function _updateRelationProducts($storeId, $productIds = null)
194204
return $this;
195205
}
196206

207+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
208+
197209
foreach ($this->_getProductTypeInstances() as $typeInstance) {
198210
/** @var $typeInstance \Magento\Catalog\Model\Product\Type\AbstractType */
199211
if (!$typeInstance->isComposite(null)) {
@@ -210,7 +222,11 @@ protected function _updateRelationProducts($storeId, $productIds = null)
210222
/** @var $select \Magento\Framework\DB\Select */
211223
$select = $this->_connection->select()->from(
212224
['t' => $this->_productIndexerHelper->getTable($relation->getTable())],
213-
[$relation->getParentFieldName(), $relation->getChildFieldName(), new \Zend_Db_Expr('1')]
225+
[$relation->getChildFieldName(), new \Zend_Db_Expr('1')]
226+
)->join(
227+
['entity_table' => $this->_connection->getTableName('catalog_product_entity')],
228+
'entity_table.' . $metadata->getLinkField() . 't.' . $relation->getParentFieldName(),
229+
[$relation->getParentFieldName() => 'entity_table.entity_id']
214230
)->join(
215231
['e' => $this->_productIndexerHelper->getFlatTableName($storeId)],
216232
"e.entity_id = t.{$relation->getChildFieldName()}",
@@ -222,7 +238,7 @@ protected function _updateRelationProducts($storeId, $productIds = null)
222238
if ($productIds !== null) {
223239
$cond = [
224240
$this->_connection->quoteInto("{$relation->getChildFieldName()} IN(?)", $productIds),
225-
$this->_connection->quoteInto("{$relation->getParentFieldName()} IN(?)", $productIds),
241+
$this->_connection->quoteInto("entity_table.entity_id IN(?)", $productIds),
226242
];
227243

228244
$select->where(implode(' OR ', $cond));
@@ -247,6 +263,8 @@ protected function _cleanRelationProducts($storeId)
247263
return $this;
248264
}
249265

266+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
267+
250268
foreach ($this->_getProductTypeInstances() as $typeInstance) {
251269
/** @var $typeInstance \Magento\Catalog\Model\Product\Type\AbstractType */
252270
if (!$typeInstance->isComposite(null)) {
@@ -258,11 +276,15 @@ protected function _cleanRelationProducts($storeId)
258276
$select = $this->_connection->select()->distinct(
259277
true
260278
)->from(
261-
$this->_productIndexerHelper->getTable($relation->getTable()),
262-
"{$relation->getParentFieldName()}"
279+
['t' => $this->_productIndexerHelper->getTable($relation->getTable())],
280+
[]
281+
)->join(
282+
['entity_table' => $this->_connection->getTableName('catalog_product_entity')],
283+
'entity_table.' . $metadata->getLinkField() . 't.' . $relation->getParentFieldName(),
284+
[$relation->getParentFieldName() => 'entity_table.entity_id']
263285
);
264286
$joinLeftCond = [
265-
"e.entity_id = t.{$relation->getParentFieldName()}",
287+
"e.entity_id = entity_table.entity_id",
266288
"e.child_id = t.{$relation->getChildFieldName()}",
267289
];
268290
if ($relation->getWhere() !== null) {

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
99
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;
10+
use Magento\Framework\Model\Entity\MetadataPool;
1011

1112
/**
1213
* Class Row reindex action
@@ -24,6 +25,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
2425
protected $flatItemEraser;
2526

2627
/**
28+
* @param MetadataPool $metadataPool
2729
* @param \Magento\Framework\App\ResourceConnection $resource
2830
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
2931
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
@@ -34,6 +36,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
3436
* @param Eraser $flatItemEraser
3537
*/
3638
public function __construct(
39+
MetadataPool $metadataPool,
3740
\Magento\Framework\App\ResourceConnection $resource,
3841
\Magento\Store\Model\StoreManagerInterface $storeManager,
3942
\Magento\Catalog\Helper\Product\Flat\Indexer $productHelper,
@@ -44,6 +47,7 @@ public function __construct(
4447
Eraser $flatItemEraser
4548
) {
4649
parent::__construct(
50+
$metadataPool,
4751
$resource,
4852
$storeManager,
4953
$productHelper,

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Rows.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
99
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;
10+
use Magento\Framework\Model\Entity\MetadataPool;
1011

1112
/**
1213
* Class Rows reindex action for mass actions
@@ -20,6 +21,7 @@ class Rows extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
2021
protected $flatItemEraser;
2122

2223
/**
24+
* @param MetadataPool $metadataPool
2325
* @param \Magento\Framework\App\ResourceConnection $resource
2426
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
2527
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
@@ -29,6 +31,7 @@ class Rows extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
2931
* @param Eraser $flatItemEraser
3032
*/
3133
public function __construct(
34+
MetadataPool $metadataPool,
3235
\Magento\Framework\App\ResourceConnection $resource,
3336
\Magento\Store\Model\StoreManagerInterface $storeManager,
3437
\Magento\Catalog\Helper\Product\Flat\Indexer $productHelper,
@@ -38,6 +41,7 @@ public function __construct(
3841
Eraser $flatItemEraser
3942
) {
4043
parent::__construct(
44+
$metadataPool,
4145
$resource,
4246
$storeManager,
4347
$productHelper,

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,21 +372,13 @@ public function getProductChildIds($productId, $typeId)
372372
['main' => $this->getTable($relation->getTable())],
373373
[$relation->getChildFieldName()]
374374
);
375-
//TODO: Will be removed in MAGETWO-47395
376-
if ($typeId === 'configurable') {
377-
$select->where(
378-
$relation->getParentFieldName() . ' = ?',
379-
$productId
380-
);
381-
} else {
382-
$select->join(
383-
['e' => $this->resource->getTableName('catalog_product_entity')],
384-
'e.' . $this->metadata->getLinkField() . ' = main.' . $relation->getParentFieldName()
385-
)->where(
386-
'e.entity_id = ?',
387-
$productId
388-
);
389-
}
375+
$select->join(
376+
['e' => $this->resource->getTableName('catalog_product_entity')],
377+
'e.' . $this->metadata->getLinkField() . ' = main.' . $relation->getParentFieldName()
378+
)->where(
379+
'e.entity_id = ?',
380+
$productId
381+
);
390382

391383
if ($relation->getWhere() !== null) {
392384
$select->where($relation->getWhere());

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\CatalogSearch\Model\ResourceModel\Advanced;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\Framework\Api\FilterBuilder;
10+
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
911
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
1012

1113
/**
@@ -23,19 +25,24 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
2325
private $filters = [];
2426

2527
/**
26-
* @var \Magento\CatalogSearch\Model\Advanced\Request\Builder
28+
* @var \Magento\Search\Api\SearchInterface
2729
*/
28-
private $requestBuilder;
30+
private $search;
2931

3032
/**
31-
* @var \Magento\Search\Model\SearchEngine
33+
* @var \Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory
3234
*/
33-
private $searchEngine;
35+
private $temporaryStorageFactory;
3436

3537
/**
36-
* @var \Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory
38+
* @var SearchCriteriaBuilder
3739
*/
38-
private $temporaryStorageFactory;
40+
private $searchCriteriaBuilder;
41+
42+
/**
43+
* @var FilterBuilder
44+
*/
45+
private $filterBuilder;
3946

4047
/**
4148
* Collection constructor.
@@ -59,10 +66,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
5966
* @param \Magento\Framework\Stdlib\DateTime $dateTime
6067
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
6168
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation $productLimitation
62-
* @param \Magento\CatalogSearch\Model\Advanced\Request\Builder $requestBuilder
63-
* @param \Magento\Search\Model\SearchEngine $searchEngine
69+
* @param \Magento\Search\Api\SearchInterface $search
6470
* @param \Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory $temporaryStorageFactory
65-
* @param \Zend_Db_Adapter_Abstract $connection
71+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
72+
* @param FilterBuilder $filterBuilder
73+
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
6674
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6775
*/
6876
public function __construct(
@@ -86,14 +94,16 @@ public function __construct(
8694
\Magento\Framework\Stdlib\DateTime $dateTime,
8795
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
8896
\Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation $productLimitation,
89-
\Magento\CatalogSearch\Model\Advanced\Request\Builder $requestBuilder,
90-
\Magento\Search\Model\SearchEngine $searchEngine,
97+
\Magento\Search\Api\SearchInterface $search,
9198
\Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory $temporaryStorageFactory,
92-
$connection = null
99+
SearchCriteriaBuilder $searchCriteriaBuilder,
100+
FilterBuilder $filterBuilder,
101+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
93102
) {
94-
$this->requestBuilder = $requestBuilder;
95-
$this->searchEngine = $searchEngine;
103+
$this->search = $search;
96104
$this->temporaryStorageFactory = $temporaryStorageFactory;
105+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
106+
$this->filterBuilder = $filterBuilder;
97107
parent::__construct(
98108
$entityFactory,
99109
$logger,
@@ -140,19 +150,18 @@ public function addFieldsToFilter($fields)
140150
protected function _renderFiltersBefore()
141151
{
142152
if ($this->filters) {
143-
$this->requestBuilder->bindDimension('scope', $this->getStoreId());
144-
$this->requestBuilder->setRequestName('advanced_search_container');
145153
foreach ($this->filters as $attributes) {
146154
foreach ($attributes as $attributeCode => $attributeValue) {
147155
$attributeCode = $this->getAttributeCode($attributeCode);
148-
$this->requestBuilder->bindRequestValue($attributeCode, $attributeValue);
156+
$this->addAttributeToSearch($attributeCode, $attributeValue);
149157
}
150158
}
151-
$queryRequest = $this->requestBuilder->create();
152-
$queryResponse = $this->searchEngine->search($queryRequest);
159+
$searchCriteria = $this->searchCriteriaBuilder->create();
160+
$searchCriteria->setRequestName('advanced_search_container');
161+
$searchResult = $this->search->search($searchCriteria);
153162

154163
$temporaryStorage = $this->temporaryStorageFactory->create();
155-
$table = $temporaryStorage->storeDocuments($queryResponse->getIterator());
164+
$table = $temporaryStorage->storeApiDocuments($searchResult->getItems());
156165

157166
$this->getSelect()->joinInner(
158167
[
@@ -162,7 +171,7 @@ protected function _renderFiltersBefore()
162171
[]
163172
);
164173
}
165-
return parent::_renderFiltersBefore();
174+
parent::_renderFiltersBefore();
166175
}
167176

168177
/**
@@ -178,4 +187,49 @@ private function getAttributeCode($attributeCode)
178187

179188
return $attributeCode;
180189
}
190+
191+
/**
192+
* Create a filter and add it to the SearchCriteriaBuilder.
193+
*
194+
* @param string $attributeCode
195+
* @param array|string $attributeValue
196+
* @return void
197+
*/
198+
private function addAttributeToSearch($attributeCode, $attributeValue)
199+
{
200+
if (isset($attributeValue['from']) || isset($attributeValue['to'])) {
201+
$this->addRangeAttributeToSearch($attributeCode, $attributeValue);
202+
} elseif (!is_array($attributeValue)) {
203+
$this->filterBuilder->setField($attributeCode)->setValue($attributeValue);
204+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
205+
} elseif (isset($attributeValue['like'])) {
206+
$this->filterBuilder->setField($attributeCode)->setValue($attributeValue['like']);
207+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
208+
} elseif (isset($attributeValue['in'])) {
209+
$this->filterBuilder->setField($attributeCode)->setValue($attributeValue['in']);
210+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
211+
} elseif (isset($attributeValue['in_set'])) {
212+
$this->filterBuilder->setField($attributeCode)->setValue($attributeValue['in_set']);
213+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
214+
}
215+
}
216+
217+
/**
218+
* Add attributes that have a range (from,to) to the SearchCriteriaBuilder.
219+
*
220+
* @param string $attributeCode
221+
* @param array|string $attributeValue
222+
* @return void
223+
*/
224+
private function addRangeAttributeToSearch($attributeCode, $attributeValue)
225+
{
226+
if (isset($attributeValue['from']) && '' !== $attributeValue['from']) {
227+
$this->filterBuilder->setField("{$attributeCode}.from")->setValue($attributeValue['from']);
228+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
229+
}
230+
if (isset($attributeValue['to']) && '' !== $attributeValue['to']) {
231+
$this->filterBuilder->setField("{$attributeCode}.to")->setValue($attributeValue['to']);
232+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
233+
}
234+
}
181235
}

0 commit comments

Comments
 (0)