Skip to content

Commit d9c3e7b

Browse files
MC-16650: Product Attribute Type Price Not Displaying
- use price filter for all attributes with catalog input type = 'price'
1 parent 8f9f248 commit d9c3e7b

File tree

6 files changed

+33
-37
lines changed

6 files changed

+33
-37
lines changed

app/code/Magento/Catalog/Model/Layer/FilterList.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Model\Layer;
89

10+
use Magento\Catalog\Model\Product\Attribute\Backend\Price;
11+
12+
/**
13+
* Layer navigation filters
14+
*/
915
class FilterList
1016
{
1117
const CATEGORY_FILTER = 'category';
@@ -106,9 +112,9 @@ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\
106112
{
107113
$filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
108114

109-
if ($attribute->getAttributeCode() == 'price') {
115+
if ($attribute->getBackendModel() === Price::class) {
110116
$filterClassName = $this->filterTypes[self::PRICE_FILTER];
111-
} elseif ($attribute->getBackendType() == 'decimal') {
117+
} elseif ($attribute->getBackendType() === 'decimal') {
112118
$filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
113119
}
114120

app/code/Magento/Catalog/Test/Unit/Model/Layer/FilterListTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Test\Unit\Model\Layer;
89

910
use \Magento\Catalog\Model\Layer\FilterList;
11+
use Magento\Catalog\Model\Product\Attribute\Backend\Price;
1012

1113
class FilterListTest extends \PHPUnit\Framework\TestCase
1214
{
@@ -95,8 +97,8 @@ public function getFiltersDataProvider()
9597
{
9698
return [
9799
[
98-
'method' => 'getAttributeCode',
99-
'value' => FilterList::PRICE_FILTER,
100+
'method' => 'getBackendModel',
101+
'value' => Price::class,
100102
'expectedClass' => 'PriceFilterClass',
101103
],
102104
[
@@ -105,7 +107,7 @@ public function getFiltersDataProvider()
105107
'expectedClass' => 'DecimalFilterClass',
106108
],
107109
[
108-
'method' => 'getAttributeCode',
110+
'method' => 'getBackendModel',
109111
'value' => null,
110112
'expectedClass' => 'AttributeFilterClass',
111113
]

app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CatalogSearch\Model\Layer\Filter;
79

810
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
@@ -11,6 +13,7 @@
1113
* Layer price filter based on Search API
1214
*
1315
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1417
*/
1518
class Price extends AbstractFilter
1619
{
@@ -138,7 +141,7 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
138141
list($from, $to) = $filter;
139142

140143
$this->getLayer()->getProductCollection()->addFieldToFilter(
141-
'price',
144+
$this->getAttributeModel()->getAttributeCode(),
142145
['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]
143146
);
144147

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,12 @@
1010
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1111
use Magento\Framework\Search\Request\BucketInterface;
1212
use Magento\Framework\Search\Request\FilterInterface;
13-
use Magento\Framework\App\Config\ScopeConfigInterface;
14-
use Magento\Framework\App\ObjectManager;
15-
use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
16-
use Magento\Store\Model\ScopeInterface;
1713

1814
/**
1915
* Catalog search range request generator.
2016
*/
2117
class Decimal implements GeneratorInterface
2218
{
23-
/**
24-
* @var \Magento\Store\Model\ScopeInterface
25-
*/
26-
private $scopeConfig;
27-
28-
/**
29-
* @param \Magento\Store\Model\ScopeInterface|null $scopeConfig
30-
*/
31-
public function __construct(ScopeConfigInterface $scopeConfig = null)
32-
{
33-
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
34-
}
35-
3619
/**
3720
* @inheritdoc
3821
*/
@@ -56,21 +39,8 @@ public function getAggregationData(Attribute $attribute, $bucketName)
5639
'type' => BucketInterface::TYPE_DYNAMIC,
5740
'name' => $bucketName,
5841
'field' => $attribute->getAttributeCode(),
59-
'method' => $this->getRangeCalculation(),
42+
'method' => 'manual',
6043
'metric' => [['type' => 'count']],
6144
];
6245
}
63-
64-
/**
65-
* Get range calculation by what was set in the configuration
66-
*
67-
* @return string
68-
*/
69-
private function getRangeCalculation(): string
70-
{
71-
return $this->scopeConfig->getValue(
72-
AlgorithmFactory::XML_PATH_RANGE_CALCULATION,
73-
ScopeInterface::SCOPE_STORE
74-
);
75-
}
7646
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogSearch\Test\Unit\Model\Layer\Filter;
89

@@ -208,6 +209,12 @@ public function testApply()
208209
$priceId = '15-50';
209210
$requestVar = 'test_request_var';
210211

212+
$this->target->setAttributeModel($this->attribute);
213+
$attributeCode = 'price';
214+
$this->attribute->expects($this->any())
215+
->method('getAttributeCode')
216+
->will($this->returnValue($attributeCode));
217+
211218
$this->target->setRequestVar($requestVar);
212219
$this->request->expects($this->exactly(1))
213220
->method('getParam')

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CatalogSearch\Model\Layer\Filter;
79

810
use Magento\TestFramework\Helper\Bootstrap;
@@ -35,10 +37,16 @@ protected function setUp()
3537
$category->load(4);
3638
$layer = $this->objectManager->get(\Magento\Catalog\Model\Layer\Category::class);
3739
$layer->setCurrentCategory($category);
40+
/** @var $attribute \Magento\Catalog\Model\Entity\Attribute */
41+
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
42+
\Magento\Catalog\Model\Entity\Attribute::class
43+
);
44+
$attribute->loadByCode('catalog_product', 'price');
3845
$this->_model = $this->objectManager->create(
3946
\Magento\CatalogSearch\Model\Layer\Filter\Price::class,
4047
['layer' => $layer]
4148
);
49+
$this->_model->setAttributeModel($attribute);
4250
}
4351

4452
public function testApplyNothing()

0 commit comments

Comments
 (0)