Skip to content

Commit f413b3e

Browse files
glo23503devarul
authored andcommitted
ACP2E-1422: No products in categories or search
1 parent 56aaac9 commit f413b3e

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Catalog\Model\Product\Attribute;
88

99
use Laminas\Validator\Regex;
10-
use Magento\Eav\Api\Data\AttributeInterface;
10+
use Magento\Catalog\Api\Data\EavAttributeInterface;
1111
use Magento\Eav\Model\Entity\Attribute;
1212
use Magento\Framework\Exception\InputException;
1313
use Magento\Framework\Exception\NoSuchEntityException;
@@ -19,6 +19,8 @@
1919
*/
2020
class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInterface
2121
{
22+
private const FILTERABLE_ALLOWED_INPUT_TYPES = ['date', 'datetime', 'price', 'text', 'textarea', 'texteditor'];
23+
2224
/**
2325
* @var \Magento\Catalog\Model\ResourceModel\Attribute
2426
*/
@@ -110,6 +112,20 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
110112
*/
111113
public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute)
112114
{
115+
if (in_array($attribute->getFrontendInput(), self::FILTERABLE_ALLOWED_INPUT_TYPES)) {
116+
if ($attribute->getIsFilterable()) {
117+
throw InputException::invalidFieldValue(
118+
EavAttributeInterface::IS_FILTERABLE, $attribute->getIsFilterable()
119+
);
120+
}
121+
122+
if ($attribute->getIsFilterableInSearch()) {
123+
throw InputException::invalidFieldValue(
124+
EavAttributeInterface::IS_FILTERABLE_IN_SEARCH, $attribute->getIsFilterableInSearch()
125+
);
126+
}
127+
}
128+
113129
$attribute->setEntityTypeId(
114130
$this->eavConfig
115131
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
@@ -156,7 +172,7 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
156172
);
157173
$attribute->setIsUserDefined(1);
158174
}
159-
if (!empty($attribute->getData(AttributeInterface::OPTIONS))) {
175+
if (!empty($attribute->getData(EavAttributeInterface::OPTIONS))) {
160176
$options = [];
161177
$sortOrder = 0;
162178
$default = [];

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,42 @@ public function testSaveInputExceptionRequiredField()
241241
$this->model->save($attributeMock);
242242
}
243243

244+
/**
245+
* @param string $field
246+
* @param string $method
247+
* @param bool $filterable
248+
*
249+
* @return void
250+
* @dataProvider filterableDataProvider
251+
*/
252+
public function testSaveInputExceptionInvalidIsFilterableFieldValue(
253+
string $field,
254+
string $method,
255+
bool $filterable
256+
) : void {
257+
$this->expectException('Magento\Framework\Exception\InputException');
258+
$this->expectExceptionMessage('Invalid value of "'.$filterable.'" provided for the '.$field.' field.');
259+
$attributeMock = $this->createPartialMock(
260+
Attribute::class,
261+
['getFrontendInput', $method]
262+
);
263+
$attributeMock->expects($this->atLeastOnce())->method('getFrontendInput')->willReturn('text');
264+
$attributeMock->expects($this->atLeastOnce())->method($method)->willReturn($filterable);
265+
266+
$this->model->save($attributeMock);
267+
}
268+
269+
/**
270+
* @return array
271+
*/
272+
public function filterableDataProvider(): array
273+
{
274+
return [
275+
[ProductAttributeInterface::IS_FILTERABLE, 'getIsFilterable', true],
276+
[ProductAttributeInterface::IS_FILTERABLE_IN_SEARCH, 'getIsFilterableInSearch', true]
277+
];
278+
}
279+
244280
public function testSaveInputExceptionInvalidFieldValue()
245281
{
246282
$this->expectException('Magento\Framework\Exception\InputException');

0 commit comments

Comments
 (0)