Skip to content

Commit f39ad29

Browse files
author
Oleksii Korshenko
authored
Merge pull request #445 from magento-dragons/092016-pr-2.2
Fixed issues: - MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline - MAGETWO-57924: Unable to add "Customer Group Price" - MAGETWO-55341: Request to ESI doesn't return any data - MAGETWO-57892: L4 Plan fails on mainline branch - MAGETWO-56150: Order comments history shows time of comment twice - MAGETWO-57933: Product quantity is not updated on 'cart/configure' page second time - MAGETWO-53041: 'Yes/No' attribute shown in Advanced Search result even it not used in filtration - MAGETWO-52926: Impossible to find product on Store Front with name like lowerCamelCaseNumber
2 parents 0cb8b17 + 79bacd3 commit f39ad29

File tree

24 files changed

+611
-133
lines changed

24 files changed

+611
-133
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ private function getTierPriceStructure($tierPricePath)
493493
'data' => [
494494
'config' => [
495495
'componentType' => Field::NAME,
496-
'component' => 'Magento_Catalog/js/form/element/price-input',
497496
'formElement' => Input::NAME,
498497
'dataType' => Price::NAME,
499498
'label' => __('Price'),

app/code/Magento/Catalog/view/adminhtml/web/js/form/element/price-input.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/code/Magento/Catalog/view/adminhtml/web/template/form/element/price-input.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/code/Magento/CatalogSearch/Block/Advanced/Result.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function __construct(
6464
*/
6565
protected function _prepareLayout()
6666
{
67+
$this->pageConfig->getTitle()->set($this->getPageTitle());
6768
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
6869
if ($breadcrumbs) {
6970
$breadcrumbs->addCrumb(
@@ -84,6 +85,16 @@ protected function _prepareLayout()
8485
return parent::_prepareLayout();
8586
}
8687

88+
/**
89+
* Get page title
90+
*
91+
* @return \Magento\Framework\Phrase
92+
*/
93+
private function getPageTitle()
94+
{
95+
return __('Advanced Search Results');
96+
}
97+
8798
/**
8899
* Set order options
89100
*

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,11 @@ protected function getPreparedSearchCriteria($attribute, $value)
368368
$value = $value['label'];
369369
}
370370
} elseif ($attribute->getFrontendInput() == 'boolean') {
371-
$value = $value == 1
372-
? __('Yes')
373-
: __('No');
371+
if (is_numeric($value)) {
372+
$value = $value == 1 ? __('Yes') : __('No');
373+
} else {
374+
$value = false;
375+
}
374376
}
375377

376378
return $value;

app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use Magento\Catalog\Api\Data\EavAttributeInterface;
99
use Magento\Catalog\Model\Entity\Attribute;
1010
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
11-
use Magento\Framework\Search\Request\BucketInterface;
11+
use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\Search\Request\FilterInterface;
1314
use Magento\Framework\Search\Request\QueryInterface;
1415

@@ -25,12 +26,22 @@ class RequestGenerator
2526
*/
2627
private $productAttributeCollectionFactory;
2728

29+
/**
30+
* @var GeneratorResolver
31+
*/
32+
private $generatorResolver;
33+
2834
/**
2935
* @param CollectionFactory $productAttributeCollectionFactory
36+
* @param GeneratorResolver $generatorResolver
3037
*/
31-
public function __construct(CollectionFactory $productAttributeCollectionFactory)
32-
{
38+
public function __construct(
39+
CollectionFactory $productAttributeCollectionFactory,
40+
GeneratorResolver $generatorResolver = null
41+
) {
3342
$this->productAttributeCollectionFactory = $productAttributeCollectionFactory;
43+
$this->generatorResolver = $generatorResolver
44+
?: ObjectManager::getInstance()->get(GeneratorResolver::class);
3445
}
3546

3647
/**
@@ -62,7 +73,7 @@ private function generateRequest($attributeType, $container, $useFulltext)
6273
$request = [];
6374
foreach ($this->getSearchableAttributes() as $attribute) {
6475
if ($attribute->getData($attributeType)) {
65-
if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'])) {
76+
if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'], true)) {
6677
$queryName = $attribute->getAttributeCode() . '_query';
6778

6879
$request['queries'][$container]['queryReference'][] = [
@@ -76,58 +87,33 @@ private function generateRequest($attributeType, $container, $useFulltext)
7687
'filterReference' => [['ref' => $filterName]],
7788
];
7889
$bucketName = $attribute->getAttributeCode() . self::BUCKET_SUFFIX;
79-
if ($attribute->getBackendType() == 'decimal') {
80-
$request['filters'][$filterName] = [
81-
'type' => FilterInterface::TYPE_RANGE,
82-
'name' => $filterName,
83-
'field' => $attribute->getAttributeCode(),
84-
'from' => '$' . $attribute->getAttributeCode() . '.from$',
85-
'to' => '$' . $attribute->getAttributeCode() . '.to$',
86-
];
87-
$request['aggregations'][$bucketName] = [
88-
'type' => BucketInterface::TYPE_DYNAMIC,
89-
'name' => $bucketName,
90-
'field' => $attribute->getAttributeCode(),
91-
'method' => 'manual',
92-
'metric' => [["type" => "count"]],
93-
];
94-
} else {
95-
$request['filters'][$filterName] = [
96-
'type' => FilterInterface::TYPE_TERM,
97-
'name' => $filterName,
98-
'field' => $attribute->getAttributeCode(),
99-
'value' => '$' . $attribute->getAttributeCode() . '$',
100-
];
101-
$request['aggregations'][$bucketName] = [
102-
'type' => BucketInterface::TYPE_TERM,
103-
'name' => $bucketName,
104-
'field' => $attribute->getAttributeCode(),
105-
'metric' => [["type" => "count"]],
106-
];
107-
}
90+
$generator = $this->generatorResolver->getGeneratorForType($attribute->getBackendType());
91+
$request['filters'][$filterName] = $generator->getFilterData($attribute, $filterName);
92+
$request['aggregations'][$bucketName] = $generator->getAggregationData($attribute, $bucketName);
10893
}
10994
}
11095
/** @var $attribute Attribute */
111-
if (in_array($attribute->getAttributeCode(), ['price', 'sku'])
112-
|| !$attribute->getIsSearchable()
113-
) {
114-
//same fields have special semantics
96+
if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price', 'sku'], true)) {
97+
// Some fields have their own specific handlers
11598
continue;
11699
}
117-
if ($useFulltext) {
100+
101+
// Match search by custom price attribute isn't supported
102+
if ($useFulltext && $attribute->getFrontendInput() !== 'price') {
118103
$request['queries']['search']['match'][] = [
119104
'field' => $attribute->getAttributeCode(),
120105
'boost' => $attribute->getSearchWeight() ?: 1,
121106
];
122107
}
123108
}
109+
124110
return $request;
125111
}
126112

127113
/**
128114
* Retrieve searchable attributes
129115
*
130-
* @return \Magento\Catalog\Model\Entity\Attribute[]
116+
* @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
131117
*/
132118
protected function getSearchableAttributes()
133119
{
@@ -231,6 +217,7 @@ private function generateAdvancedSearchRequest()
231217
];
232218
}
233219
}
220+
234221
return $request;
235222
}
236223
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Model\Search\RequestGenerator;
8+
9+
10+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
11+
use Magento\Framework\Search\Request\BucketInterface;
12+
use Magento\Framework\Search\Request\FilterInterface;
13+
14+
class Decimal implements GeneratorInterface
15+
{
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function getFilterData(Attribute $attribute, $filterName)
21+
{
22+
return [
23+
'type' => FilterInterface::TYPE_RANGE,
24+
'name' => $filterName,
25+
'field' => $attribute->getAttributeCode(),
26+
'from' => '$' . $attribute->getAttributeCode() . '.from$',
27+
'to' => '$' . $attribute->getAttributeCode() . '.to$',
28+
];
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function getAggregationData(Attribute $attribute, $bucketName)
35+
{
36+
return [
37+
'type' => BucketInterface::TYPE_DYNAMIC,
38+
'name' => $bucketName,
39+
'field' => $attribute->getAttributeCode(),
40+
'method' => 'manual',
41+
'metric' => [['type' => 'count']],
42+
];
43+
}
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Model\Search\RequestGenerator;
8+
9+
10+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
11+
use Magento\Framework\Search\Request\BucketInterface;
12+
use Magento\Framework\Search\Request\FilterInterface;
13+
14+
class General implements GeneratorInterface
15+
{
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function getFilterData(Attribute $attribute, $filterName)
21+
{
22+
return [
23+
'type' => FilterInterface::TYPE_TERM,
24+
'name' => $filterName,
25+
'field' => $attribute->getAttributeCode(),
26+
'value' => '$' . $attribute->getAttributeCode() . '$',
27+
];
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function getAggregationData(Attribute $attribute, $bucketName)
34+
{
35+
return [
36+
'type' => BucketInterface::TYPE_TERM,
37+
'name' => $bucketName,
38+
'field' => $attribute->getAttributeCode(),
39+
'metric' => [['type' => 'count']],
40+
];
41+
}
42+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Model\Search\RequestGenerator;
8+
9+
10+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
11+
12+
interface GeneratorInterface
13+
{
14+
/**
15+
* Get filter data for specific attribute
16+
* @param Attribute $attribute
17+
* @param string $filterName
18+
* @return array
19+
*/
20+
public function getFilterData(Attribute $attribute, $filterName);
21+
22+
/**
23+
* Get aggregation data for specific attribute
24+
* @param Attribute $attribute
25+
* @param string $bucketName
26+
* @return array
27+
*/
28+
public function getAggregationData(Attribute $attribute, $bucketName);
29+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Model\Search\RequestGenerator;
8+
9+
class GeneratorResolver
10+
{
11+
/**
12+
* @var GeneratorInterface[]
13+
*/
14+
private $generators;
15+
16+
/**
17+
* @var GeneratorInterface
18+
*/
19+
private $defaultGenerator;
20+
21+
/**
22+
* @param GeneratorInterface $defaultGenerator
23+
* @param GeneratorInterface[] $generators
24+
*/
25+
public function __construct(GeneratorInterface $defaultGenerator, array $generators)
26+
{
27+
$this->defaultGenerator = $defaultGenerator;
28+
$this->generators = $generators;
29+
}
30+
31+
/**
32+
* @param string $type
33+
* @return GeneratorInterface
34+
* @throws \InvalidArgumentException
35+
*/
36+
public function getGeneratorForType($type)
37+
{
38+
$generator = isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator;
39+
if (!($generator instanceof GeneratorInterface)) {
40+
throw new \InvalidArgumentException(
41+
'Generator must implement ' . GeneratorInterface::class
42+
);
43+
}
44+
return $generator;
45+
}
46+
}

app/code/Magento/CatalogSearch/Test/Unit/Model/AdvancedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function addFiltersDataProvider()
170170
'static'
171171
)
172172
],
173-
'values' => ['is_active' => false],
173+
'values' => ['is_active' => 0],
174174
'currentCurrencyCode' => 'GBP',
175175
'baseCurrencyCode' => 'USD'
176176
],

0 commit comments

Comments
 (0)