-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1097 from magento-firedrakes/bugfixes
Fixed issues: - MAGETWO-67291: [Performance] Layered Navigation built for Non Anchored categories - MAGETWO-64834: Spinner is Always Displayed on Shopping Cart page in Summary block for virtual quote - MAGETWO-59826: [Github] Opengraphs og:description contains html tags #6776
- Loading branch information
Showing
13 changed files
with
526 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/Checker/Query/AdvancedSearch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query; | ||
|
||
use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface; | ||
use Magento\Framework\Search\RequestInterface; | ||
|
||
/** | ||
* Request checker for advanced search. | ||
* | ||
* Checks advanced search query whether required to collect all attributes for entity. | ||
*/ | ||
class AdvancedSearch implements RequestCheckerInterface | ||
{ | ||
/** | ||
* Identifier for query name | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function __construct($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isApplicable(RequestInterface $request) | ||
{ | ||
$result = true; | ||
// It's no need to render LN filters for advanced search | ||
if ($request->getName() === $this->name) { | ||
$result = false; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/Checker/Query/CatalogView.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query; | ||
|
||
use Magento\Framework\Search\RequestInterface; | ||
use Magento\Catalog\Api\CategoryRepositoryInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\Search\Request\QueryInterface; | ||
use Magento\Framework\Search\Request\Query\BoolExpression; | ||
use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
/** | ||
* Request checker for catalog view. | ||
* | ||
* Checks catalog view query whether required to collect all attributes for entity. | ||
*/ | ||
class CatalogView implements RequestCheckerInterface | ||
{ | ||
/** | ||
* Identifier for query name | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var CategoryRepositoryInterface | ||
*/ | ||
private $categoryRepository; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @param CategoryRepositoryInterface $categoryRepository | ||
* @param StoreManagerInterface $storeManager | ||
* @param string $name | ||
*/ | ||
public function __construct( | ||
CategoryRepositoryInterface $categoryRepository, | ||
StoreManagerInterface $storeManager, | ||
$name | ||
) { | ||
$this->categoryRepository = $categoryRepository; | ||
$this->storeManager = $storeManager; | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isApplicable(RequestInterface $request) | ||
{ | ||
$result = true; | ||
if ($request->getName() === $this->name) { | ||
$result = $this->hasAnchorCategory($request); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Check whether category is anchor. | ||
* | ||
* Proceeds with request and check whether at least one of categories is anchor. | ||
* | ||
* @param RequestInterface $request | ||
* @return bool | ||
*/ | ||
private function hasAnchorCategory(RequestInterface $request) | ||
{ | ||
$queryType = $request->getQuery()->getType(); | ||
$result = false; | ||
|
||
if ($queryType === QueryInterface::TYPE_BOOL) { | ||
$categories = $this->getCategoriesFromQuery($request->getQuery()); | ||
|
||
/** @var \Magento\Catalog\Api\Data\CategoryInterface $category */ | ||
foreach ($categories as $category) { | ||
// It's no need to render LN filters for non anchor categories | ||
if ($category && $category->getIsAnchor()) { | ||
$result = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Get categories based on query filter data. | ||
* | ||
* Get categories from query will allow to check if category is anchor | ||
* And proceed with attribute aggregation if it's not | ||
* | ||
* @param QueryInterface $queryExpression | ||
* @return \Magento\Catalog\Api\Data\CategoryInterface[]|[] | ||
*/ | ||
private function getCategoriesFromQuery(QueryInterface $queryExpression) | ||
{ | ||
/** @var BoolExpression $queryExpression */ | ||
$categoryIds = $this->getCategoryIdsFromQuery($queryExpression); | ||
$categories = []; | ||
|
||
foreach ($categoryIds as $categoryId) { | ||
try { | ||
$categories[] = $this->categoryRepository | ||
->get($categoryId, $this->storeManager->getStore()->getId()); | ||
} catch (NoSuchEntityException $e) { | ||
// do nothing if category is not found by id | ||
} | ||
} | ||
|
||
return $categories; | ||
} | ||
|
||
/** | ||
* Get Category Ids from search query. | ||
* | ||
* Get Category Ids from Must and Should search queries. | ||
* | ||
* @param QueryInterface $queryExpression | ||
* @return array | ||
*/ | ||
private function getCategoryIdsFromQuery(QueryInterface $queryExpression) | ||
{ | ||
$queryFilterArray = []; | ||
/** @var BoolExpression $queryExpression */ | ||
$queryFilterArray[] = $queryExpression->getMust(); | ||
$queryFilterArray[] = $queryExpression->getShould(); | ||
$categoryIds = []; | ||
|
||
foreach ($queryFilterArray as $item) { | ||
if (!empty($item) && isset($item['category'])) { | ||
$queryFilter = $item['category']; | ||
/** @var \Magento\Framework\Search\Request\Query\Filter $queryFilter */ | ||
$categoryIds[] = $queryFilter->getReference()->getValue(); | ||
} | ||
} | ||
|
||
return $categoryIds; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/RequestCheckerComposite.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Adapter\Aggregation; | ||
|
||
use Magento\Framework\Search\RequestInterface; | ||
use Magento\Catalog\Api\CategoryRepositoryInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
class RequestCheckerComposite implements RequestCheckerInterface | ||
{ | ||
/** | ||
* @var CategoryRepositoryInterface | ||
*/ | ||
private $categoryRepository; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var RequestCheckerInterface[] | ||
*/ | ||
private $queryCheckers; | ||
|
||
/** | ||
* @param CategoryRepositoryInterface $categoryRepository | ||
* @param StoreManagerInterface $storeManager | ||
* @param RequestCheckerInterface[] $queryCheckers | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function __construct( | ||
CategoryRepositoryInterface $categoryRepository, | ||
StoreManagerInterface $storeManager, | ||
array $queryCheckers | ||
) { | ||
$this->categoryRepository = $categoryRepository; | ||
$this->storeManager = $storeManager; | ||
$this->queryCheckers = $queryCheckers; | ||
|
||
foreach ($this->queryCheckers as $queryChecker) { | ||
if (!$queryChecker instanceof RequestCheckerInterface) { | ||
throw new \InvalidArgumentException( | ||
get_class($queryChecker) . | ||
' does not implement ' . | ||
\Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface::class | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isApplicable(RequestInterface $request) | ||
{ | ||
$result = true; | ||
|
||
foreach ($this->queryCheckers as $item) { | ||
/** @var RequestCheckerInterface $item */ | ||
$result = $item->isApplicable($request); | ||
if (!$result) { | ||
break; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/RequestCheckerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSearch\Model\Adapter\Aggregation; | ||
|
||
use Magento\Framework\Search\RequestInterface; | ||
|
||
/** | ||
* RequestCheckerInterface provides the interface to work with query checkers. | ||
*/ | ||
interface RequestCheckerInterface | ||
{ | ||
/** | ||
* Provided to check if it's needed to collect all attributes for entity. | ||
* | ||
* Avoiding unnecessary expensive attribute aggregation operation will improve performance. | ||
* | ||
* @param RequestInterface $request | ||
* @return bool | ||
*/ | ||
public function isApplicable(RequestInterface $request); | ||
} |
Oops, something went wrong.