Eav collection: $collection->addAttributeToSelect('*');
Flat collection: $collection->addFieldToSelect('*');
Collections of flat tables are inherited from:
Magento\Framework\Data\Collection
/**
* Convert collection to array
*/
public function toArray($arrRequiredFields = [])
{
$arrItems = [];
$arrItems['totalRecords'] = $this->getSize();
$arrItems['items'] = [];
foreach ($this as $item) {
$arrItems['items'][] = $item->toArray($arrRequiredFields);
}
return $arrItems;
}
Collection of EAV entities have abstract layer from:
Magento\Eav\Model\Entity\Collection\AbstractCollection
Magento\Framework\Data\Collection\AbstractDb
/**
* Retrieve array of attributes
*/
public function toArray($arrAttributes = [])
{
$arr = [];
foreach ($this->getItems() as $key => $item) {
$arr[$key] = $item->toArray($arrAttributes);
}
return $arr;
}
/**
* Retrieve collection items
*
* @return \Magento\Framework\DataObject[]
*/
public function getItems()
{
$this->load();
return $this->_items;
}
/**
* Load data
*
*/
public function load($printQuery = false, $logQuery = false)
{
return $this->loadData($printQuery, $logQuery);
}