Skip to content

Commit 7cf0256

Browse files
committed
ACP2E-1508: Elastic search CRITICAL errors
1 parent bd8634b commit 7cf0256

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\System\Config\Backend\Rss;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
12+
use Magento\Framework\App\Cache\TypeListInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\Config\Value as ConfigValue;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\Data\Collection\AbstractDb;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Model\ResourceModel\AbstractResource;
19+
use Magento\Framework\Registry;
20+
21+
class Category extends ConfigValue
22+
{
23+
/**
24+
* @var ProductAttributeRepositoryInterface
25+
*/
26+
private $productAttributeRepository;
27+
28+
public function __construct(
29+
Context $context,
30+
Registry $registry,
31+
ScopeConfigInterface $config,
32+
TypeListInterface $cacheTypeList,
33+
AbstractResource $resource = null,
34+
AbstractDb $resourceCollection = null,
35+
array $data = [],
36+
ProductAttributeRepositoryInterface $productAttributeRepository = null
37+
) {
38+
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
39+
40+
$this->productAttributeRepository = $productAttributeRepository ??
41+
ObjectManager::getInstance()->get(ProductAttributeRepositoryInterface::class);
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function afterSave()
48+
{
49+
if ($this->isValueChanged() && $this->getValue()) {
50+
$updatedAtAttr = $this->productAttributeRepository->get(ProductInterface::UPDATED_AT);
51+
if (!$updatedAtAttr->getUsedForSortBy()) {
52+
$updatedAtAttr->setUsedForSortBy(true);
53+
$this->productAttributeRepository->save($updatedAtAttr);
54+
}
55+
}
56+
57+
return parent::afterSave();
58+
}
59+
}

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<field id="category" translate="label" type="select" sortOrder="14" showInDefault="1" showInWebsite="1" showInStore="1">
200200
<label>Top Level Category</label>
201201
<source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model>
202+
<backend_model>Magento\Catalog\Model\System\Config\Backend\Rss\Category</backend_model>
202203
</field>
203204
</group>
204205
</section>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Rss;
9+
10+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Config\Model\Config as ConfigModel;
13+
use Magento\Framework\App\Area;
14+
use Magento\Framework\App\Config\ConfigResource\ConfigInterface as ConfigResource;
15+
use Magento\Framework\Indexer\IndexerRegistry;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\TestFramework\Fixture\AppArea;
18+
use Magento\TestFramework\Fixture\DataFixture;
19+
use Magento\TestFramework\Fixture\DataFixtureStorage;
20+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
21+
use Magento\TestFramework\Fixture\DbIsolation;
22+
use Magento\TestFramework\Helper\Bootstrap;
23+
use PHPUnit\Framework\TestCase;
24+
25+
#[
26+
AppArea(Area::AREA_ADMINHTML),
27+
DbIsolation(false),
28+
]
29+
class CategoryTest extends TestCase
30+
{
31+
/**
32+
* @var DataFixtureStorage
33+
*/
34+
private $fixtureStorage;
35+
36+
/**
37+
* @var Category
38+
*/
39+
private $model;
40+
41+
/**
42+
* @var StoreManagerInterface
43+
*/
44+
private $storeManager;
45+
46+
protected function setUp(): void
47+
{
48+
$configModel = Bootstrap::getObjectManager()->create(ConfigModel::class);
49+
$configModel->setDataByPath('rss/catalog/category', 1);
50+
$configModel->save();
51+
$indexerRegistry = Bootstrap::getObjectManager()->get(IndexerRegistry::class);
52+
$indexerRegistry->get('catalogsearch_fulltext')->reindexAll();
53+
54+
$this->fixtureStorage = DataFixtureStorageManager::getStorage();
55+
$this->model = Bootstrap::getObjectManager()->create(Category::class);
56+
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
57+
}
58+
59+
protected function tearDown(): void
60+
{
61+
$configResource = Bootstrap::getObjectManager()->get(ConfigResource::class);
62+
$configResource->deleteConfig('rss/catalog/category');
63+
}
64+
65+
#[
66+
DataFixture(CategoryFixture::class, as: 'c1'),
67+
DataFixture(ProductFixture::class, ['sku' => 'p1', 'category_ids' => ['$c1.id$']], 'p1'),
68+
]
69+
public function testGetProductCollection(): void
70+
{
71+
$category = $this->fixtureStorage->get('c1');
72+
$store = $this->storeManager->getStore('default');
73+
$productCollection = $this->model->getProductCollection($category, $store->getId());
74+
self::assertEquals(1, $productCollection->count());
75+
$product = $productCollection->getFirstItem();
76+
self::assertEquals('p1', $product->getSku());
77+
}
78+
}

0 commit comments

Comments
 (0)