/**
  * Retrieve flat columns DDL definition
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function _getFlatColumnsDdlDefinition()
 {
     $columns = [];
     switch ($this->getBackendType()) {
         case 'static':
             $describe = $this->_getResource()->describeTable($this->getBackend()->getTable());
             if (!isset($describe[$this->getAttributeCode()])) {
                 break;
             }
             $prop = $describe[$this->getAttributeCode()];
             $type = $prop['DATA_TYPE'];
             $size = $prop['LENGTH'] ? $prop['LENGTH'] : null;
             $columns[$this->getAttributeCode()] = ['type' => $this->_resourceHelper->getDdlTypeByColumnType($type), 'length' => $size, 'unsigned' => $prop['UNSIGNED'] ? true : false, 'nullable' => $prop['NULLABLE'], 'default' => $prop['DEFAULT'], 'extra' => null];
             break;
         case 'datetime':
             $columns[$this->getAttributeCode()] = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, 'unsigned' => false, 'nullable' => true, 'default' => null, 'extra' => null];
             break;
         case 'decimal':
             $columns[$this->getAttributeCode()] = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'unsigned' => false, 'nullable' => true, 'default' => null, 'extra' => null];
             break;
         case 'int':
             $columns[$this->getAttributeCode()] = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 'unsigned' => false, 'nullable' => true, 'default' => null, 'extra' => null];
             break;
         case 'text':
             $columns[$this->getAttributeCode()] = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'unsigned' => false, 'nullable' => true, 'default' => null, 'extra' => null, 'length' => \Magento\Framework\DB\Ddl\Table::MAX_TEXT_SIZE];
             break;
         case 'varchar':
             $columns[$this->getAttributeCode()] = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'length' => '255', 'unsigned' => false, 'nullable' => true, 'default' => null, 'extra' => null];
             break;
         default:
             break;
     }
     return $columns;
 }
Example #2
0
 /**
  * Retrieve flat column definition
  *
  * @return array
  */
 public function getFlatColums()
 {
     $attributeType = $this->getAttribute()->getBackendType();
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $column = array('unsigned' => false, 'default' => null, 'extra' => null);
     $column['type'] = $this->_eavResourceHelper->getDdlTypeByColumnType($attributeType);
     $column['nullable'] = true;
     return array($attributeCode => $column);
 }
Example #3
0
 /**
  * Load model attributes data
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _loadModelAttributes($object)
 {
     if (!$object->getId()) {
         return $this;
     }
     \Magento\Framework\Profiler::start('load_model_attributes');
     $selects = array();
     foreach (array_keys($this->getAttributesByTable()) as $table) {
         $attribute = current($this->_attributesByTable[$table]);
         $eavType = $attribute->getBackendType();
         $select = $this->_getLoadAttributesSelect($object, $table);
         $selects[$eavType][] = $select->columns('*');
     }
     $selectGroups = $this->_resourceHelper->getLoadAttributesSelectGroups($selects);
     foreach ($selectGroups as $selects) {
         if (!empty($selects)) {
             $select = $this->_prepareLoadSelect($selects);
             $values = $this->_getReadAdapter()->fetchAll($select);
             foreach ($values as $valueRow) {
                 $this->_setAttributeValue($object, $valueRow);
             }
         }
     }
     \Magento\Framework\Profiler::stop('load_model_attributes');
     return $this;
 }
 /**
  * Load attributes into loaded entities
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  * @throws EavException
  * @throws \Exception
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function _loadAttributes($printQuery = false, $logQuery = false)
 {
     if (empty($this->_items) || empty($this->_itemsById) || empty($this->_selectAttributes)) {
         return $this;
     }
     $entity = $this->getEntity();
     $tableAttributes = [];
     $attributeTypes = [];
     foreach ($this->_selectAttributes as $attributeCode => $attributeId) {
         if (!$attributeId) {
             continue;
         }
         $attribute = $this->_eavConfig->getAttribute($entity->getType(), $attributeCode);
         if ($attribute && !$attribute->isStatic()) {
             $tableAttributes[$attribute->getBackendTable()][] = $attributeId;
             if (!isset($attributeTypes[$attribute->getBackendTable()])) {
                 $attributeTypes[$attribute->getBackendTable()] = $attribute->getBackendType();
             }
         }
     }
     $selects = [];
     foreach ($tableAttributes as $table => $attributes) {
         $select = $this->_getLoadAttributesSelect($table, $attributes);
         $selects[$attributeTypes[$table]][] = $this->_addLoadAttributesSelectValues($select, $table, $attributeTypes[$table]);
     }
     $selectGroups = $this->_resourceHelper->getLoadAttributesSelectGroups($selects);
     foreach ($selectGroups as $selects) {
         if (!empty($selects)) {
             try {
                 $select = implode(' UNION ALL ', $selects);
                 $values = $this->getConnection()->fetchAll($select);
             } catch (\Exception $e) {
                 $this->printLogQuery(true, true, $select);
                 throw $e;
             }
             foreach ($values as $value) {
                 $this->_setItemAttributeValue($value);
             }
         }
     }
     return $this;
 }
Example #5
0
 /**
  * Retrieve flat column definition
  *
  * @return array
  */
 public function getFlatColumns()
 {
     $attributeType = $this->getAttribute()->getBackendType();
     $attributeCode = $this->getAttribute()->getAttributeCode();
     return [$attributeCode => ['unsigned' => false, 'default' => null, 'extra' => null, 'type' => $this->_eavResourceHelper->getDdlTypeByColumnType($attributeType), 'nullable' => true]];
 }
Example #6
0
 /**
  * @param \Magento\Framework\App\Resource $resource
  * @param string $modulePrefix
  */
 public function __construct(\Magento\Framework\App\Resource $resource, $modulePrefix = 'Magento_Catalog')
 {
     parent::__construct($resource, $modulePrefix);
 }