Skip to content

Commit 8b30062

Browse files
committed
MAGETWO-55299: [Customer] Fast Save of Product Variations
- MAGETWO-55787: Fast saving of product with high number of variations generated
1 parent ac6f209 commit 8b30062

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

app/code/Magento/Eav/Model/ResourceModel/CreateHandler.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
class CreateHandler implements AttributeInterface
2121
{
22+
/** Name of ATTRIBUTE_SET_ID field */
23+
const ATTRIBUTE_SET_ID = 'attribute_set_id';
24+
2225
/**
2326
* @var AttributeRepository
2427
*/
@@ -88,21 +91,35 @@ private function getAttributeCache()
8891
* @return \Magento\Eav\Api\Data\AttributeInterface[]
8992
* @throws \Exception
9093
*/
91-
protected function getAttributes($entityType)
94+
protected function getAttributes($entityType, $attributeSetId = null)
9295
{
9396
/** @var AttributeCache $cache */
9497
$cache = $this->getAttributeCache();
95-
if ($attributes = $cache->getAttributes($entityType)) {
98+
$suffix = 'attribute_set_id-' . ($attributeSetId ?: 'all');
99+
if ($attributes = $cache->getAttributes($entityType, $suffix)) {
96100
return $attributes;
97101
}
98102

99103
$metadata = $this->metadataPool->getMetadata($entityType);
100104

105+
if ($attributeSetId === null) {
106+
$criteria = $this->searchCriteriaBuilder->addFilter(self::ATTRIBUTE_SET_ID . '', null, 'neq')->create();
107+
} else {
108+
$criteria = $this->searchCriteriaBuilder->addFilter(self::ATTRIBUTE_SET_ID, $attributeSetId)->create();
109+
}
110+
101111
$searchResult = $this->attributeRepository->getList(
102112
$metadata->getEavEntityType(),
103-
$this->searchCriteriaBuilder->addFilter('attribute_set_id', null, 'neq')->create()
113+
$criteria
114+
);
115+
$attributes = $searchResult->getItems();
116+
117+
$this->attributeCache->saveAttributes(
118+
$entityType,
119+
$attributes,
120+
$suffix
104121
);
105-
return $searchResult->getItems();
122+
return $attributes;
106123
}
107124

108125
/**
@@ -120,8 +137,9 @@ public function execute($entityType, $entityData, $arguments = [])
120137
if ($metadata->getEavEntityType()) {
121138
$processed = [];
122139
$entityLinkField = $metadata->getLinkField();
140+
$attributeSetId = isset($entityData[self::ATTRIBUTE_SET_ID]) ? $entityData[self::ATTRIBUTE_SET_ID] : null;
123141
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
124-
foreach ($this->getAttributes($entityType) as $attribute) {
142+
foreach ($this->getAttributes($entityType, $attributeSetId) as $attribute) {
125143
if ($attribute->isStatic()) {
126144
continue;
127145
}

0 commit comments

Comments
 (0)