Skip to content

Commit 4fa8ec0

Browse files
committed
ACP2E-3752: Duplicate of AC-13913 - Static attribute cleaning asynchronously.
1 parent 3207f61 commit 4fa8ec0

File tree

6 files changed

+237
-282
lines changed

6 files changed

+237
-282
lines changed

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\BundleImportExport\Test\Unit\Model\Import\Product\Type;
99

1010
use Magento\BundleImportExport\Model\Import\Product\Type\Bundle;
1111
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as ProductAttributeCollection;
13+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as ProductAttributeCollectionFactory;
1214
use Magento\CatalogImportExport\Model\Import\Product;
1315
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
14-
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory;
16+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
1517
use Magento\Framework\App\ResourceConnection;
1618
use Magento\Framework\App\ScopeInterface;
1719
use Magento\Framework\App\ScopeResolverInterface;
@@ -34,46 +36,46 @@ class BundleTest extends AbstractImportTestCase
3436
/**
3537
* @var Bundle
3638
*/
37-
protected $bundle;
39+
private $bundle;
3840

3941
/**
4042
* @var ResourceConnection|MockObject
4143
*/
42-
protected $resource;
44+
private $resource;
4345

4446
/**
4547
* @var Select|MockObject
4648
*/
47-
protected $select;
49+
private $select;
4850

4951
/**
5052
* @var Product|MockObject
5153
*/
52-
protected $entityModel;
54+
private $entityModel;
5355

5456
/**
5557
* @var []
5658
*/
57-
protected $params;
59+
private $params;
5860

5961
/** @var AdapterInterface|MockObject
6062
*/
61-
protected $connection;
63+
private $connection;
6264

6365
/**
64-
* @var MockObject
66+
* @var AttributeSetCollectionFactory|MockObject
6567
*/
66-
protected $attrSetColFac;
68+
private $attrSetColFac;
6769

6870
/**
69-
* @var MockObject
71+
* @var ProductAttributeCollectionFactory|MockObject
7072
*/
71-
protected $prodAttrColFac;
73+
private $prodAttrColFac;
7274

7375
/**
7476
* @var Collection|MockObject
7577
*/
76-
protected $setCollection;
78+
private $setCollection;
7779

7880
/**
7981
* @var ScopeResolverInterface|MockObject
@@ -179,36 +181,20 @@ protected function setUp(): void
179181
);
180182
$this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
181183
$this->resource->expects($this->any())->method('getTableName')->willReturn('tableName');
182-
$this->attrSetColFac = $this->createPartialMock(
183-
CollectionFactory::class,
184-
['create']
185-
);
186-
$this->setCollection = $this->createPartialMock(
187-
Collection::class,
188-
['setEntityTypeFilter']
189-
);
190-
$this->attrSetColFac->expects($this->any())->method('create')->willReturn(
191-
$this->setCollection
192-
);
193-
$this->setCollection->expects($this->any())
194-
->method('setEntityTypeFilter')
195-
->willReturn([]);
196-
$this->prodAttrColFac = $this->createPartialMock(
197-
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory::class,
198-
['create']
199-
);
200-
$attrCollection =
201-
$this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection::class);
202-
$attrCollection->expects($this->any())->method('addFieldToFilter')->willReturn([]);
184+
$this->attrSetColFac = $this->createMock(AttributeSetCollectionFactory::class);
185+
$this->setCollection = $this->createMock(Collection::class);
186+
$this->attrSetColFac->expects($this->any())->method('create')->willReturn($this->setCollection);
187+
$this->setCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([]);
188+
$this->prodAttrColFac = $this->createMock(ProductAttributeCollectionFactory::class);
189+
$attrCollection = $this->createMock(ProductAttributeCollection::class);
190+
$attrCollection->expects($this->any())->method('addFieldToFilter')->willReturnSelf();
191+
$attrCollection->expects($this->any())->method('getItems')->willReturn([]);
203192
$this->prodAttrColFac->expects($this->any())->method('create')->willReturn($attrCollection);
204193
$this->params = [
205194
0 => $this->entityModel,
206195
1 => 'bundle'
207196
];
208-
$this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class)
209-
->disableOriginalConstructor()
210-
->onlyMethods(['getScope'])
211-
->getMockForAbstractClass();
197+
$this->scopeResolver = $this->createMock(ScopeResolverInterface::class);
212198

213199
$objects = [
214200
[

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -352,45 +352,44 @@ private function attachAttributes(array $attributeIds): void
352352
$attributes = $attributeIds ? $this->_prodAttrColFac->create()
353353
->addFieldToFilter(['main_table.attribute_id'], [['in' => $attributeIds]])
354354
->getItems() : [];
355+
$attributes = array_filter($attributes, fn ($attribute) => $attribute->getIsVisible());
355356
if ($this->_forcedAttributesCodes) {
356357
$attributes += $this->_prodAttrColFac->create()
357358
->addFieldToFilter(['main_table.attribute_code'], [['in' => $this->_forcedAttributesCodes]])
358359
->getItems();
359360
}
360361

361-
$commonAttributes = $attributeCodeToId = $attributesToLoadFromTable = $invAttributes = [];
362+
$invAttributes = array_diff($attributeIds, array_keys($attributes));
363+
self::$invAttributesCache = array_merge(self::$invAttributesCache, $invAttributes);
364+
365+
$commonAttributes = $attributeCodeToId = $attributesToLoadFromTable = [];
362366
foreach ($attributes as $attribute) {
363367
$attributeCode = $attribute->getAttributeCode();
364368
$attributeId = $attribute->getId();
365-
if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
366-
$defaultValue = $attribute->getDefaultValue();
367-
$cachedAttribute = [
368-
'id' => $attributeId,
369-
'code' => $attributeCode,
370-
'is_global' => $attribute->getIsGlobal(),
371-
'is_required' => $attribute->getIsRequired(),
372-
'is_unique' => $attribute->getIsUnique(),
373-
'frontend_label' => $attribute->getFrontendLabel(),
374-
'is_static' => $attribute->isStatic(),
375-
'apply_to' => $attribute->getApplyTo(),
376-
'type' => Import::getAttributeType($attribute),
377-
'default_value' => is_string($defaultValue) && strlen($defaultValue) ? $defaultValue : null,
378-
'options' => [],
379-
];
380-
if (Table::class === $attribute->getSourceModel()) {
381-
$attributesToLoadFromTable[] = $attributeId;
382-
} else {
383-
$cachedAttribute['options'] = $this->_entityModel->getAttributeOptions(
384-
$attribute,
385-
$this->_indexValueAttributes
386-
);
387-
}
388-
389-
$commonAttributes[$attributeId] = $cachedAttribute;
390-
$attributeCodeToId[$attributeCode] = $attributeId;
369+
$defaultValue = $attribute->getDefaultValue();
370+
$cachedAttribute = [
371+
'id' => $attributeId,
372+
'code' => $attributeCode,
373+
'is_global' => $attribute->getIsGlobal(),
374+
'is_required' => $attribute->getIsRequired(),
375+
'is_unique' => $attribute->getIsUnique(),
376+
'frontend_label' => $attribute->getFrontendLabel(),
377+
'is_static' => $attribute->isStatic(),
378+
'apply_to' => $attribute->getApplyTo(),
379+
'type' => Import::getAttributeType($attribute),
380+
'default_value' => is_string($defaultValue) && strlen($defaultValue) ? $defaultValue : null,
381+
'options' => [],
382+
];
383+
if (Table::class === $attribute->getSourceModel()) {
384+
$attributesToLoadFromTable[] = $attributeId;
391385
} else {
392-
$invAttributes[] = $attributeId;
386+
$cachedAttribute['options'] = $this->_entityModel->getAttributeOptions(
387+
$attribute,
388+
$this->_indexValueAttributes
389+
);
393390
}
391+
$commonAttributes[$attributeId] = $cachedAttribute;
392+
$attributeCodeToId[$attributeCode] = $attributeId;
394393
}
395394

396395
foreach (array_chunk($attributesToLoadFromTable, 1000) as $ids) {
@@ -407,7 +406,6 @@ private function attachAttributes(array $attributeIds): void
407406

408407
self::$commonAttributesCache += $commonAttributes;
409408
self::$attributeCodeToId += $attributeCodeToId;
410-
self::$invAttributesCache = array_merge(self::$invAttributesCache, $invAttributes);
411409
}
412410

413411
/**
@@ -636,9 +634,7 @@ public function saveData()
636634
protected function getMetadataPool()
637635
{
638636
if (!$this->metadataPool) {
639-
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
640-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
641-
->get(MetadataPool::class);
637+
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()->get(MetadataPool::class);
642638
}
643639
return $this->metadataPool;
644640
}

0 commit comments

Comments
 (0)