Example #1
0
 /**
  * Attach Attributes By Id
  *
  * @param string $attributeSetName
  * @param array $attributeIds
  * @return void
  */
 protected function attachAttributesById($attributeSetName, $attributeIds)
 {
     foreach ($this->_prodAttrColFac->create()->addFieldToFilter('main_table.attribute_id', ['in' => $attributeIds]) 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)];
             $this->_addAttributeParams($attributeSetName, self::$commonAttributesCache[$attributeId], $attribute);
         }
     }
 }
 /**
  * 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;
 }