Skip to content

Commit

Permalink
ENGCOM-2331: [Forwardport] Improve attribute checking #16767
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Jul 18, 2018
2 parents 056acee + a4c0013 commit 4a19041
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ abstract class AbstractType
*/
public static $commonAttributesCache = [];

/**
* Maintain a list of invisible attributes
*
* @var array
*/
public static $invAttributesCache = [];

/**
* Attribute Code to Id cache
*
Expand Down Expand Up @@ -278,7 +285,14 @@ protected function _initAttributes()
}
}
foreach ($absentKeys as $attributeSetName => $attributeIds) {
$this->attachAttributesById($attributeSetName, $attributeIds);
$unknownAttributeIds = array_diff(
$attributeIds,
array_keys(self::$commonAttributesCache),
self::$invAttributesCache
);
if ($unknownAttributeIds || $this->_forcedAttributesCodes) {
$this->attachAttributesById($attributeSetName, $attributeIds);
}
}
foreach ($entityAttributes as $attributeRow) {
if (isset(self::$commonAttributesCache[$attributeRow['attribute_id']])) {
Expand All @@ -303,37 +317,45 @@ protected function _initAttributes()
protected function attachAttributesById($attributeSetName, $attributeIds)
{
foreach ($this->_prodAttrColFac->create()->addFieldToFilter(
'main_table.attribute_id',
['in' => $attributeIds]
['main_table.attribute_id', 'main_table.attribute_code'],
[
['in' => $attributeIds],
['in' => $this->_forcedAttributesCodes]
]
) as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$attributeId = $attribute->getId();

if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
self::$commonAttributesCache[$attributeId] = [
'id' => $attributeId,
'code' => $attributeCode,
'is_global' => $attribute->getIsGlobal(),
'is_required' => $attribute->getIsRequired(),
'is_unique' => $attribute->getIsUnique(),
'frontend_label' => $attribute->getFrontendLabel(),
'is_static' => $attribute->isStatic(),
'apply_to' => $attribute->getApplyTo(),
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
'default_value' => strlen(
$attribute->getDefaultValue()
) ? $attribute->getDefaultValue() : null,
'options' => $this->_entityModel->getAttributeOptions(
$attribute,
$this->_indexValueAttributes
),
];
if (!isset(self::$commonAttributesCache[$attributeId])) {
self::$commonAttributesCache[$attributeId] = [
'id' => $attributeId,
'code' => $attributeCode,
'is_global' => $attribute->getIsGlobal(),
'is_required' => $attribute->getIsRequired(),
'is_unique' => $attribute->getIsUnique(),
'frontend_label' => $attribute->getFrontendLabel(),
'is_static' => $attribute->isStatic(),
'apply_to' => $attribute->getApplyTo(),
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
'default_value' => strlen(
$attribute->getDefaultValue()
) ? $attribute->getDefaultValue() : null,
'options' => $this->_entityModel->getAttributeOptions(
$attribute,
$this->_indexValueAttributes
),
];
}

self::$attributeCodeToId[$attributeCode] = $attributeId;
$this->_addAttributeParams(
$attributeSetName,
self::$commonAttributesCache[$attributeId],
$attribute
);
} else {
self::$invAttributesCache[] = $attributeId;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,28 @@ protected function setUp()
->expects($this->any())
->method('addFieldToFilter')
->with(
'main_table.attribute_id',
['in' => ['attribute_id', 'boolean_attribute']]
['main_table.attribute_id', 'main_table.attribute_code'],
[
[
'in' =>
[
'attribute_id',
'boolean_attribute',
],
],
[
'in' =>
[
'related_tgtr_position_behavior',
'related_tgtr_position_limit',
'upsell_tgtr_position_behavior',
'upsell_tgtr_position_limit',
'thumbnail_label',
'small_image_label',
'image_label',
],
],
]
)
->willReturn([$attribute1, $attribute2]);

Expand Down

0 comments on commit 4a19041

Please sign in to comment.