Skip to content

Commit cb8126c

Browse files
author
Robert He
committed
Merge branch 'develop' into MAGETWO-69004-upgrade_captcha-2.2
2 parents 9dc31d5 + d4f730e commit cb8126c

File tree

32 files changed

+938
-186
lines changed

32 files changed

+938
-186
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/opengraph/general.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
?>
1111

1212
<meta property="og:type" content="og:product" />
13-
<meta property="og:title" content="<?php echo $block->escapeHtml($block->getProduct()->getName()); ?>" />
13+
<meta property="og:title" content="<?php echo $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())); ?>" />
1414
<meta property="og:image" content="<?php echo $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()); ?>" />
15-
<meta property="og:description" content="<?php echo $block->escapeHtml($block->getProduct()->getShortDescription()); ?>" />
15+
<meta property="og:description" content="<?php echo $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())); ?>" />
1616
<meta property="og:url" content="<?php echo $block->escapeUrl($block->getProduct()->getProductUrl()); ?>" />
1717
<?php if ($priceAmount = $block->getProduct()->getFinalPrice()):?>
1818
<meta property="product:price:amount" content="<?php /* @escapeNotVerified */ echo $priceAmount; ?>"/>

app/code/Magento/CatalogSearch/Model/Adapter/Aggregation/AggregationResolver.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ class AggregationResolver implements AggregationResolverInterface
3636
*/
3737
private $config;
3838

39+
/**
40+
* @var RequestCheckerInterface
41+
*/
42+
private $requestChecker;
43+
3944
/**
4045
* @var AttributeCollection
4146
*/
4247
private $attributeCollection;
43-
48+
4449
/**
4550
* AggregationResolver constructor
4651
*
@@ -49,27 +54,35 @@ class AggregationResolver implements AggregationResolverInterface
4954
* @param SearchCriteriaBuilder $searchCriteriaBuilder
5055
* @param Config $config
5156
* @param AttributeCollection $attributeCollection [optional]
57+
* @param RequestCheckerInterface|null $aggregationChecker
5258
*/
5359
public function __construct(
5460
AttributeSetFinderInterface $attributeSetFinder,
5561
ProductAttributeRepositoryInterface $productAttributeRepository,
5662
SearchCriteriaBuilder $searchCriteriaBuilder,
5763
Config $config,
58-
AttributeCollection $attributeCollection = null
64+
AttributeCollection $attributeCollection = null,
65+
RequestCheckerInterface $aggregationChecker = null
5966
) {
6067
$this->attributeSetFinder = $attributeSetFinder;
6168
$this->productAttributeRepository = $productAttributeRepository;
6269
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
6370
$this->config = $config;
6471
$this->attributeCollection = $attributeCollection
6572
?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeCollection::class);
73+
$this->requestChecker = $aggregationChecker ?: \Magento\Framework\App\ObjectManager::getInstance()
74+
->get(RequestCheckerInterface::class);
6675
}
6776

6877
/**
6978
* {@inheritdoc}
7079
*/
7180
public function resolve(RequestInterface $request, array $documentIds)
7281
{
82+
if (!$this->requestChecker->isApplicable($request)) {
83+
return [];
84+
}
85+
7386
$data = $this->config->get($request->getName());
7487

7588
$bucketKeys = isset($data['aggregations']) ? array_keys($data['aggregations']) : [];
@@ -79,7 +92,8 @@ public function resolve(RequestInterface $request, array $documentIds)
7992
$request->getAggregation(),
8093
function ($bucket) use ($attributeCodes, $bucketKeys) {
8194
/** @var BucketInterface $bucket */
82-
return in_array($bucket->getField(), $attributeCodes) || in_array($bucket->getName(), $bucketKeys);
95+
return in_array($bucket->getField(), $attributeCodes, true) ||
96+
in_array($bucket->getName(), $bucketKeys, true);
8397
}
8498
);
8599
return array_values($resolvedAggregation);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query;
7+
8+
use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface;
9+
use Magento\Framework\Search\RequestInterface;
10+
11+
/**
12+
* Request checker for advanced search.
13+
*
14+
* Checks advanced search query whether required to collect all attributes for entity.
15+
*/
16+
class AdvancedSearch implements RequestCheckerInterface
17+
{
18+
/**
19+
* Identifier for query name
20+
*/
21+
private $name;
22+
23+
/**
24+
* @param string $name
25+
*/
26+
public function __construct($name)
27+
{
28+
$this->name = $name;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function isApplicable(RequestInterface $request)
35+
{
36+
$result = true;
37+
// It's no need to render LN filters for advanced search
38+
if ($request->getName() === $this->name) {
39+
$result = false;
40+
}
41+
42+
return $result;
43+
}
44+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query;
7+
8+
use Magento\Framework\Search\RequestInterface;
9+
use Magento\Catalog\Api\CategoryRepositoryInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Framework\Search\Request\QueryInterface;
12+
use Magento\Framework\Search\Request\Query\BoolExpression;
13+
use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
16+
/**
17+
* Request checker for catalog view.
18+
*
19+
* Checks catalog view query whether required to collect all attributes for entity.
20+
*/
21+
class CatalogView implements RequestCheckerInterface
22+
{
23+
/**
24+
* Identifier for query name
25+
*/
26+
private $name;
27+
28+
/**
29+
* @var CategoryRepositoryInterface
30+
*/
31+
private $categoryRepository;
32+
33+
/**
34+
* @var StoreManagerInterface
35+
*/
36+
private $storeManager;
37+
38+
/**
39+
* @param CategoryRepositoryInterface $categoryRepository
40+
* @param StoreManagerInterface $storeManager
41+
* @param string $name
42+
*/
43+
public function __construct(
44+
CategoryRepositoryInterface $categoryRepository,
45+
StoreManagerInterface $storeManager,
46+
$name
47+
) {
48+
$this->categoryRepository = $categoryRepository;
49+
$this->storeManager = $storeManager;
50+
$this->name = $name;
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function isApplicable(RequestInterface $request)
57+
{
58+
$result = true;
59+
if ($request->getName() === $this->name) {
60+
$result = $this->hasAnchorCategory($request);
61+
}
62+
63+
return $result;
64+
}
65+
66+
/**
67+
* Check whether category is anchor.
68+
*
69+
* Proceeds with request and check whether at least one of categories is anchor.
70+
*
71+
* @param RequestInterface $request
72+
* @return bool
73+
*/
74+
private function hasAnchorCategory(RequestInterface $request)
75+
{
76+
$queryType = $request->getQuery()->getType();
77+
$result = false;
78+
79+
if ($queryType === QueryInterface::TYPE_BOOL) {
80+
$categories = $this->getCategoriesFromQuery($request->getQuery());
81+
82+
/** @var \Magento\Catalog\Api\Data\CategoryInterface $category */
83+
foreach ($categories as $category) {
84+
// It's no need to render LN filters for non anchor categories
85+
if ($category && $category->getIsAnchor()) {
86+
$result = true;
87+
break;
88+
}
89+
}
90+
}
91+
92+
return $result;
93+
}
94+
95+
/**
96+
* Get categories based on query filter data.
97+
*
98+
* Get categories from query will allow to check if category is anchor
99+
* And proceed with attribute aggregation if it's not
100+
*
101+
* @param QueryInterface $queryExpression
102+
* @return \Magento\Catalog\Api\Data\CategoryInterface[]|[]
103+
*/
104+
private function getCategoriesFromQuery(QueryInterface $queryExpression)
105+
{
106+
/** @var BoolExpression $queryExpression */
107+
$categoryIds = $this->getCategoryIdsFromQuery($queryExpression);
108+
$categories = [];
109+
110+
foreach ($categoryIds as $categoryId) {
111+
try {
112+
$categories[] = $this->categoryRepository
113+
->get($categoryId, $this->storeManager->getStore()->getId());
114+
} catch (NoSuchEntityException $e) {
115+
// do nothing if category is not found by id
116+
}
117+
}
118+
119+
return $categories;
120+
}
121+
122+
/**
123+
* Get Category Ids from search query.
124+
*
125+
* Get Category Ids from Must and Should search queries.
126+
*
127+
* @param QueryInterface $queryExpression
128+
* @return array
129+
*/
130+
private function getCategoryIdsFromQuery(QueryInterface $queryExpression)
131+
{
132+
$queryFilterArray = [];
133+
/** @var BoolExpression $queryExpression */
134+
$queryFilterArray[] = $queryExpression->getMust();
135+
$queryFilterArray[] = $queryExpression->getShould();
136+
$categoryIds = [];
137+
138+
foreach ($queryFilterArray as $item) {
139+
if (!empty($item) && isset($item['category'])) {
140+
$queryFilter = $item['category'];
141+
/** @var \Magento\Framework\Search\Request\Query\Filter $queryFilter */
142+
$categoryIds[] = $queryFilter->getReference()->getValue();
143+
}
144+
}
145+
146+
return $categoryIds;
147+
}
148+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Adapter\Aggregation;
7+
8+
use Magento\Framework\Search\RequestInterface;
9+
use Magento\Catalog\Api\CategoryRepositoryInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
12+
class RequestCheckerComposite implements RequestCheckerInterface
13+
{
14+
/**
15+
* @var CategoryRepositoryInterface
16+
*/
17+
private $categoryRepository;
18+
19+
/**
20+
* @var StoreManagerInterface
21+
*/
22+
private $storeManager;
23+
24+
/**
25+
* @var RequestCheckerInterface[]
26+
*/
27+
private $queryCheckers;
28+
29+
/**
30+
* @param CategoryRepositoryInterface $categoryRepository
31+
* @param StoreManagerInterface $storeManager
32+
* @param RequestCheckerInterface[] $queryCheckers
33+
* @throws \InvalidArgumentException
34+
*/
35+
public function __construct(
36+
CategoryRepositoryInterface $categoryRepository,
37+
StoreManagerInterface $storeManager,
38+
array $queryCheckers
39+
) {
40+
$this->categoryRepository = $categoryRepository;
41+
$this->storeManager = $storeManager;
42+
$this->queryCheckers = $queryCheckers;
43+
44+
foreach ($this->queryCheckers as $queryChecker) {
45+
if (!$queryChecker instanceof RequestCheckerInterface) {
46+
throw new \InvalidArgumentException(
47+
get_class($queryChecker) .
48+
' does not implement ' .
49+
\Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface::class
50+
);
51+
}
52+
}
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function isApplicable(RequestInterface $request)
59+
{
60+
$result = true;
61+
62+
foreach ($this->queryCheckers as $item) {
63+
/** @var RequestCheckerInterface $item */
64+
$result = $item->isApplicable($request);
65+
if (!$result) {
66+
break;
67+
}
68+
}
69+
70+
return $result;
71+
}
72+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Adapter\Aggregation;
7+
8+
use Magento\Framework\Search\RequestInterface;
9+
10+
/**
11+
* RequestCheckerInterface provides the interface to work with query checkers.
12+
*/
13+
interface RequestCheckerInterface
14+
{
15+
/**
16+
* Provided to check if it's needed to collect all attributes for entity.
17+
*
18+
* Avoiding unnecessary expensive attribute aggregation operation will improve performance.
19+
*
20+
* @param RequestInterface $request
21+
* @return bool
22+
*/
23+
public function isApplicable(RequestInterface $request);
24+
}

0 commit comments

Comments
 (0)