Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 
14 {
20  protected static $_entityTypes = [];
21 
27  protected static $_attributes = [];
28 
35  protected function _construct()
36  {
37  $this->_init('eav_entity_type', 'entity_type_id');
38  }
39 
45  protected function _loadTypes()
46  {
47  $connection = $this->getConnection();
48  if (!$connection) {
49  return $this;
50  }
51  if (empty(self::$_entityTypes)) {
52  $select = $connection->select()->from($this->getMainTable());
53  $data = $connection->fetchAll($select);
54  foreach ($data as $row) {
55  self::$_entityTypes['by_id'][$row['entity_type_id']] = $row;
56  self::$_entityTypes['by_code'][$row['entity_type_code']] = $row;
57  }
58  }
59 
60  return $this;
61  }
62 
69  protected function _loadTypeAttributes($typeId)
70  {
71  if (!isset(self::$_attributes[$typeId])) {
72  $connection = $this->getConnection();
73  $bind = ['entity_type_id' => $typeId];
74  $select = $connection->select()->from(
75  $this->getTable('eav_attribute')
76  )->where(
77  'entity_type_id = :entity_type_id'
78  );
79 
80  self::$_attributes[$typeId] = $connection->fetchAll($select, $bind);
81  }
82 
83  return self::$_attributes[$typeId];
84  }
85 
93  {
94  $this->_loadTypes();
95 
96  if (is_numeric($entityType)) {
97  $info = isset(
98  self::$_entityTypes['by_id'][$entityType]
99  ) ? self::$_entityTypes['by_id'][$entityType] : null;
100  } else {
101  $info = isset(
102  self::$_entityTypes['by_code'][$entityType]
103  ) ? self::$_entityTypes['by_code'][$entityType] : null;
104  }
105 
106  $data = [];
107  if ($info) {
108  $data['entity'] = $info;
109  $attributes = $this->_loadTypeAttributes($info['entity_type_id']);
110  $data['attributes'] = [];
111  foreach ($attributes as $attribute) {
112  $data['attributes'][$attribute['attribute_id']] = $attribute;
113  $data['attributes'][$attribute['attribute_code']] = $attribute['attribute_id'];
114  }
115  }
116 
117  return $data;
118  }
119 }
$attributes
Definition: matrix.phtml:13
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$connection
Definition: bulk.php:13
$_attributes