Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4a19041

Browse files
author
Stanislav Idolov
authored
ENGCOM-2331: [Forwardport] Improve attribute checking #16767
2 parents 056acee + a4c0013 commit 4a19041

File tree

2 files changed

+65
-23
lines changed

2 files changed

+65
-23
lines changed

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

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ abstract class AbstractType
2828
*/
2929
public static $commonAttributesCache = [];
3030

31+
/**
32+
* Maintain a list of invisible attributes
33+
*
34+
* @var array
35+
*/
36+
public static $invAttributesCache = [];
37+
3138
/**
3239
* Attribute Code to Id cache
3340
*
@@ -278,7 +285,14 @@ protected function _initAttributes()
278285
}
279286
}
280287
foreach ($absentKeys as $attributeSetName => $attributeIds) {
281-
$this->attachAttributesById($attributeSetName, $attributeIds);
288+
$unknownAttributeIds = array_diff(
289+
$attributeIds,
290+
array_keys(self::$commonAttributesCache),
291+
self::$invAttributesCache
292+
);
293+
if ($unknownAttributeIds || $this->_forcedAttributesCodes) {
294+
$this->attachAttributesById($attributeSetName, $attributeIds);
295+
}
282296
}
283297
foreach ($entityAttributes as $attributeRow) {
284298
if (isset(self::$commonAttributesCache[$attributeRow['attribute_id']])) {
@@ -303,37 +317,45 @@ protected function _initAttributes()
303317
protected function attachAttributesById($attributeSetName, $attributeIds)
304318
{
305319
foreach ($this->_prodAttrColFac->create()->addFieldToFilter(
306-
'main_table.attribute_id',
307-
['in' => $attributeIds]
320+
['main_table.attribute_id', 'main_table.attribute_code'],
321+
[
322+
['in' => $attributeIds],
323+
['in' => $this->_forcedAttributesCodes]
324+
]
308325
) as $attribute) {
309326
$attributeCode = $attribute->getAttributeCode();
310327
$attributeId = $attribute->getId();
311328

312329
if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
313-
self::$commonAttributesCache[$attributeId] = [
314-
'id' => $attributeId,
315-
'code' => $attributeCode,
316-
'is_global' => $attribute->getIsGlobal(),
317-
'is_required' => $attribute->getIsRequired(),
318-
'is_unique' => $attribute->getIsUnique(),
319-
'frontend_label' => $attribute->getFrontendLabel(),
320-
'is_static' => $attribute->isStatic(),
321-
'apply_to' => $attribute->getApplyTo(),
322-
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
323-
'default_value' => strlen(
324-
$attribute->getDefaultValue()
325-
) ? $attribute->getDefaultValue() : null,
326-
'options' => $this->_entityModel->getAttributeOptions(
327-
$attribute,
328-
$this->_indexValueAttributes
329-
),
330-
];
330+
if (!isset(self::$commonAttributesCache[$attributeId])) {
331+
self::$commonAttributesCache[$attributeId] = [
332+
'id' => $attributeId,
333+
'code' => $attributeCode,
334+
'is_global' => $attribute->getIsGlobal(),
335+
'is_required' => $attribute->getIsRequired(),
336+
'is_unique' => $attribute->getIsUnique(),
337+
'frontend_label' => $attribute->getFrontendLabel(),
338+
'is_static' => $attribute->isStatic(),
339+
'apply_to' => $attribute->getApplyTo(),
340+
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
341+
'default_value' => strlen(
342+
$attribute->getDefaultValue()
343+
) ? $attribute->getDefaultValue() : null,
344+
'options' => $this->_entityModel->getAttributeOptions(
345+
$attribute,
346+
$this->_indexValueAttributes
347+
),
348+
];
349+
}
350+
331351
self::$attributeCodeToId[$attributeCode] = $attributeId;
332352
$this->_addAttributeParams(
333353
$attributeSetName,
334354
self::$commonAttributesCache[$attributeId],
335355
$attribute
336356
);
357+
} else {
358+
self::$invAttributesCache[] = $attributeId;
337359
}
338360
}
339361
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,28 @@ protected function setUp()
134134
->expects($this->any())
135135
->method('addFieldToFilter')
136136
->with(
137-
'main_table.attribute_id',
138-
['in' => ['attribute_id', 'boolean_attribute']]
137+
['main_table.attribute_id', 'main_table.attribute_code'],
138+
[
139+
[
140+
'in' =>
141+
[
142+
'attribute_id',
143+
'boolean_attribute',
144+
],
145+
],
146+
[
147+
'in' =>
148+
[
149+
'related_tgtr_position_behavior',
150+
'related_tgtr_position_limit',
151+
'upsell_tgtr_position_behavior',
152+
'upsell_tgtr_position_limit',
153+
'thumbnail_label',
154+
'small_image_label',
155+
'image_label',
156+
],
157+
],
158+
]
139159
)
140160
->willReturn([$attribute1, $attribute2]);
141161

0 commit comments

Comments
 (0)