Skip to content

Commit 6ef131b

Browse files
authored
Merge pull request #540 from magento-performance/ACPT-1327-without-ACPT-1327
ACPT-1327 without ACPT-1327
2 parents 8c8cb94 + 3149102 commit 6ef131b

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

app/code/Magento/Catalog/Model/Product/Media/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Config implements ConfigInterface, ResetAfterRequestInterface
3030
private $attributeHelper;
3131

3232
/**
33-
* @var string[]
33+
* @var string[]|null
3434
*/
3535
private $mediaAttributeCodes;
3636

@@ -206,6 +206,6 @@ private function getAttributeHelper()
206206
*/
207207
public function _resetState(): void
208208
{
209-
$this->mediaAttributeCodes = [];
209+
$this->mediaAttributeCodes = null;
210210
}
211211
}

app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface;
1919
use Magento\Framework\Api\SearchCriteriaBuilder;
2020
use Magento\Catalog\Model\ResourceModel\Category\Collection;
21+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
2122
use Magento\Framework\App\ObjectManager;
2223
use Magento\Store\Model\StoreManagerInterface;
2324

@@ -29,9 +30,9 @@ class DynamicField implements FieldProviderInterface
2930
/**
3031
* Category collection.
3132
*
32-
* @var Collection
33+
* @var CollectionFactory
3334
*/
34-
private $categoryCollection;
35+
private $categoryCollectionFactory;
3536

3637
/**
3738
* Customer group repository.
@@ -41,8 +42,6 @@ class DynamicField implements FieldProviderInterface
4142
private $groupRepository;
4243

4344
/**
44-
* Search criteria builder.
45-
*
4645
* @var SearchCriteriaBuilder
4746
*/
4847
private $searchCriteriaBuilder;
@@ -79,8 +78,10 @@ class DynamicField implements FieldProviderInterface
7978
* @param SearchCriteriaBuilder $searchCriteriaBuilder
8079
* @param FieldNameResolver $fieldNameResolver
8180
* @param AttributeProvider $attributeAdapterProvider
82-
* @param Collection $categoryCollection
81+
* @param Collection $categoryCollection @deprecated @see $categoryCollectionFactory
8382
* @param StoreManagerInterface|null $storeManager
83+
* @param CollectionFactory|null $categoryCollectionFactory
84+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8485
*/
8586
public function __construct(
8687
FieldTypeConverterInterface $fieldTypeConverter,
@@ -90,15 +91,17 @@ public function __construct(
9091
FieldNameResolver $fieldNameResolver,
9192
AttributeProvider $attributeAdapterProvider,
9293
Collection $categoryCollection,
93-
?StoreManagerInterface $storeManager = null
94+
?StoreManagerInterface $storeManager = null,
95+
?CollectionFactory $categoryCollectionFactory = null
9496
) {
9597
$this->groupRepository = $groupRepository;
9698
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
9799
$this->fieldTypeConverter = $fieldTypeConverter;
98100
$this->indexTypeConverter = $indexTypeConverter;
99101
$this->fieldNameResolver = $fieldNameResolver;
100102
$this->attributeAdapterProvider = $attributeAdapterProvider;
101-
$this->categoryCollection = $categoryCollection;
103+
$this->categoryCollectionFactory = $categoryCollectionFactory
104+
?: ObjectManager::getInstance()->get(CollectionFactory::class);
102105
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
103106
}
104107

@@ -108,7 +111,7 @@ public function __construct(
108111
public function getFields(array $context = []): array
109112
{
110113
$allAttributes = [];
111-
$categoryIds = $this->categoryCollection->getAllIds();
114+
$categoryIds = $this->categoryCollectionFactory->create()->getAllIds();
112115
$positionAttribute = $this->attributeAdapterProvider->getByAttributeCode('position');
113116
$categoryNameAttribute = $this->attributeAdapterProvider->getByAttributeCode('category_name');
114117
foreach ($categoryIds as $categoryId) {

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Elasticsearch\Test\Unit\Model\Adapter\FieldMapper\Product\FieldProvider;
99

1010
use Magento\Catalog\Model\ResourceModel\Category\Collection;
11+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1112
use Magento\Customer\Api\Data\GroupInterface;
1213
use Magento\Customer\Api\Data\GroupSearchResultsInterface;
1314
use Magento\Customer\Api\GroupRepositoryInterface;
@@ -111,8 +112,13 @@ protected function setUp(): void
111112
->disableOriginalConstructor()
112113
->onlyMethods(['getAllIds'])
113114
->getMock();
115+
$categoryCollection = $this->getMockBuilder(CollectionFactory::class)
116+
->disableOriginalConstructor()
117+
->onlyMethods(['create'])
118+
->getMock();
119+
$categoryCollection->method('create')
120+
->willReturn($this->categoryCollection);
114121
$this->storeManager = $this->createMock(StoreManagerInterface::class);
115-
116122
$this->provider = new DynamicField(
117123
$this->fieldTypeConverter,
118124
$this->indexTypeConverter,
@@ -121,7 +127,8 @@ protected function setUp(): void
121127
$this->fieldNameResolver,
122128
$this->attributeAdapterProvider,
123129
$this->categoryCollection,
124-
$this->storeManager
130+
$this->storeManager,
131+
$categoryCollection
125132
);
126133
}
127134

dev/tests/api-functional/testsuite/Magento/GraphQl/PaymentGraphQl/StoreConfigTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
/**
1313
* Test coverage for zero subtotal and check/money order payment methods in the store config
1414
*
15-
* @magentoDbIsolation enabled
1615
*/
1716
class StoreConfigTest extends GraphQlAbstract
1817
{
19-
const STORE_CONFIG_QUERY = <<<QUERY
18+
public const STORE_CONFIG_QUERY = <<<QUERY
2019
{
2120
storeConfig {
2221
zero_subtotal_enabled

0 commit comments

Comments
 (0)