Exemple #1
0
 /**
  * Add attribute to entities in collection
  * If $attribute=='*' select all attributes
  *
  * @param array|string|integer|\Magento\Framework\App\Config\Element $attribute
  * @param bool|string $joinType
  * @return $this
  */
 public function addAttributeToSelect($attribute, $joinType = false)
 {
     if ($this->isEnabledFlat()) {
         if (!is_array($attribute)) {
             $attribute = array($attribute);
         }
         foreach ($attribute as $attributeCode) {
             if ($attributeCode == '*') {
                 foreach ($this->getEntity()->getAllTableColumns() as $column) {
                     $this->getSelect()->columns('e.' . $column);
                     $this->_selectAttributes[$column] = $column;
                     $this->_staticFields[$column] = $column;
                 }
             } else {
                 $columns = $this->getEntity()->getAttributeForSelect($attributeCode);
                 if ($columns) {
                     foreach ($columns as $alias => $column) {
                         $this->getSelect()->columns(array($alias => 'e.' . $column));
                         $this->_selectAttributes[$column] = $column;
                         $this->_staticFields[$column] = $column;
                     }
                 }
             }
         }
         return $this;
     }
     return parent::addAttributeToSelect($attribute, $joinType);
 }