/**
  * @todo to implement it.
  */
 public function testGetAttributeType()
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
     $attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['getFrontendInput', 'usesSource'])->disableOriginalConstructor()->getMock();
     $attribute->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
     $attribute->expects($this->any())->method('usesSource')->willReturn(true);
     $this->assertEquals('boolean', $this->import->getAttributeType($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;
 }
 /**
  * Initialize entity attributes
  *
  * @return $this
  */
 protected function _initAttributes()
 {
     /** @var $attribute \Magento\Eav\Model\Attribute */
     foreach ($this->_attributeCollection as $attribute) {
         $this->_attributes[$attribute->getAttributeCode()] = ['id' => $attribute->getId(), 'code' => $attribute->getAttributeCode(), 'table' => $attribute->getBackend()->getTable(), 'is_required' => $attribute->getIsRequired(), 'is_static' => $attribute->isStatic(), 'rules' => $attribute->getValidateRules() ? unserialize($attribute->getValidateRules()) : null, 'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute), 'options' => $this->getAttributeOptions($attribute)];
         $this->validColumnNames[] = $attribute->getAttributeCode();
     }
     return $this;
 }
Example #4
0
 /**
  * Initialize attribute option values and types.
  *
  * @return $this
  */
 protected function initAttributes()
 {
     foreach ($this->getAttributeCollection() as $attribute) {
         $this->_attributeValues[$attribute->getAttributeCode()] = $this->getAttributeOptions($attribute);
         $this->_attributeTypes[$attribute->getAttributeCode()] = \Magento\ImportExport\Model\Import::getAttributeType($attribute);
     }
     return $this;
 }
Example #5
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)];
             self::$attributeCodeToId[$attributeCode] = $attributeId;
             $this->_addAttributeParams($attributeSetName, self::$commonAttributesCache[$attributeId], $attribute);
         }
     }
 }