/** * Initialize attributes parameters for all attributes' sets. * * @return $this */ protected function _initAttributes() { // temporary storage for attributes' parameters to avoid double querying inside the loop $entityId = $this->_entityModel->getEntityTypeId(); $entityAttributes = $this->_connection->fetchPairs($this->_connection->select()->from(['attr' => $this->_resource->getTableName('eav_entity_attribute')], ['attr.attribute_id'])->joinLeft(['set' => $this->_resource->getTableName('eav_attribute_set')], 'set.attribute_set_id = attr.attribute_set_id', ['set.attribute_set_name'])->where($this->_connection->quoteInto('attr.entity_type_id IN (?)', $entityId))); $absentKeys = []; foreach ($entityAttributes as $attributeId => $attributeSetName) { if (!isset(self::$commonAttributesCache[$attributeId])) { if (!isset($absentKeys[$attributeSetName])) { $absentKeys[$attributeSetName] = []; } $absentKeys[$attributeSetName][] = $attributeId; } } foreach ($absentKeys as $attributeSetName => $attributeIds) { $this->attachAttributesById($attributeSetName, $attributeIds); } foreach ($entityAttributes as $attributeId => $attributeSetName) { if (isset(self::$commonAttributesCache[$attributeId])) { $attribute = self::$commonAttributesCache[$attributeId]; $this->_addAttributeParams($attributeSetName, self::$commonAttributesCache[$attributeId], $attribute); } } return $this; }
/** * Initialize attributes parameters for all attributes' sets. * * @return $this */ protected function _initAttributes() { // temporary storage for attributes' parameters to avoid double querying inside the loop $attributesCache = []; foreach ($this->_attrSetColFac->create()->setEntityTypeFilter($this->_entityModel->getEntityTypeId()) as $attributeSet) { foreach ($this->_prodAttrColFac->create()->setAttributeSetFilter($attributeSet->getId()) as $attribute) { $attributeCode = $attribute->getAttributeCode(); $attributeId = $attribute->getId(); if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) { if (!isset($attributesCache[$attributeId])) { $attributesCache[$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)]; } $this->_addAttributeParams($attributeSet->getAttributeSetName(), $attributesCache[$attributeId], $attribute); } } } return $this; }