Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Config Class Reference
Inheritance diagram for Config:
Config

Public Member Functions

 __construct (\Magento\Framework\App\CacheInterface $cache, \Magento\Eav\Model\Entity\TypeFactory $entityTypeFactory, \Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory $entityTypeCollectionFactory, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\ResourceModel\ConfigFactory $configFactory, \Magento\Catalog\Model\Product\TypeFactory $productTypeFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\Config $eavConfig, SerializerInterface $serializer=null)
 
 setStoreId ($storeId)
 
 getStoreId ()
 
 loadAttributeSets ()
 
 getAttributeSetName ($entityTypeId, $id)
 
 getAttributeSetId ($entityTypeId, $name=null)
 
 loadAttributeGroups ()
 
 getAttributeGroupName ($attributeSetId, $id)
 
 getAttributeGroupId ($attributeSetId, $name)
 
 loadProductTypes ()
 
 getProductTypeId ($name)
 
 getProductTypeName ($id)
 
 getSourceOptionId ($source, $value)
 
 getProductAttributes ()
 
 getAttributesUsedInProductListing ()
 
 getAttributesUsedForSortBy ()
 
 getAttributeUsedForSortByArray ()
 
 getProductListDefaultSortBy ($store=null)
 
- Public Member Functions inherited from Config
 __construct (\Magento\Framework\App\CacheInterface $cache, \Magento\Eav\Model\Entity\TypeFactory $entityTypeFactory, \Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory $entityTypeCollectionFactory, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\Validator\UniversalFactory $universalFactory, SerializerInterface $serializer=null)
 
 getCache ()
 
 clear ()
 
 isCacheEnabled ()
 
 getEntityType ($code)
 
 getAttributes ($entityType)
 
 getAttribute ($entityType, $code)
 
 getEntityAttributeCodes ($entityType, $object=null)
 
 getEntityAttributes ($entityType, $object=null)
 
 importAttributesData ($entityType, array $attributes)
 

Data Fields

const XML_PATH_LIST_DEFAULT_SORT_BY = 'catalog/frontend/default_sort_by'
 
- Data Fields inherited from Config
const ENTITIES_CACHE_ID = 'EAV_ENTITY_TYPES'
 
const ATTRIBUTES_CACHE_ID = 'EAV_ENTITY_ATTRIBUTES'
 
const ATTRIBUTES_CODES_CACHE_ID = 'EAV_ENTITY_ATTRIBUTES_CODES'
 

Protected Member Functions

 _construct ()
 
 _getResource ()
 
- Protected Member Functions inherited from Config
 _load ($id)
 
 _save ($obj, $id)
 
 _addEntityTypeReference ($id, $code)
 
 _getEntityTypeReference ($id)
 
 _addAttributeReference ($id, $code, $entityTypeCode)
 
 _getAttributeReference ($id, $entityTypeCode)
 
 _getEntityKey ($code)
 
 _getAttributeKey ($entityTypeCode, $attributeCode)
 
 _initEntityTypes ()
 
 _initAttributes ($entityType)
 
 _validateAttributeData ($attributeData=null)
 

Protected Attributes

 $_attributeSetsById
 
 $_attributeSetsByName
 
 $_attributeGroupsById
 
 $_attributeGroupsByName
 
 $_productTypesById
 
 $_productAttributes
 
 $_usedInProductListing
 
 $_usedForSortBy
 
 $_storeId = null
 
 $_scopeConfig
 
 $_eavConfig
 
 $_storeManager
 
 $_setCollectionFactory
 
 $_groupCollectionFactory
 
 $_productTypeFactory
 
 $_configFactory
 
- Protected Attributes inherited from Config
 $_entityTypeData
 
 $_attributeData
 
 $_attributeCodes
 
 $_objects
 
 $_references
 
 $_isCacheEnabled = null
 
 $_cache
 
 $_cacheState
 
 $_entityTypeFactory
 
 $entityTypeCollectionFactory
 
 $_universalFactory
 

Detailed Description

@SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\CacheInterface  $cache,
\Magento\Eav\Model\Entity\TypeFactory  $entityTypeFactory,
\Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory  $entityTypeCollectionFactory,
\Magento\Framework\App\Cache\StateInterface  $cacheState,
\Magento\Framework\Validator\UniversalFactory  $universalFactory,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Catalog\Model\ResourceModel\ConfigFactory  $configFactory,
\Magento\Catalog\Model\Product\TypeFactory  $productTypeFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory  $groupCollectionFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory  $setCollectionFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Eav\Model\Config  $eavConfig,
SerializerInterface  $serializer = null 
)

Constructor

Parameters
\Magento\Framework\App\CacheInterface$cache
\Magento\Eav\Model\Entity\TypeFactory$entityTypeFactory
\Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory$entityTypeCollectionFactory

Definition at line 139 of file Config.php.

153  {
154  $this->_scopeConfig = $scopeConfig;
155  $this->_configFactory = $configFactory;
156  $this->_productTypeFactory = $productTypeFactory;
157  $this->_groupCollectionFactory = $groupCollectionFactory;
158  $this->_setCollectionFactory = $setCollectionFactory;
159  $this->_storeManager = $storeManager;
160  $this->_eavConfig = $eavConfig;
161 
162  parent::__construct(
163  $cache,
164  $entityTypeFactory,
166  $cacheState,
167  $universalFactory,
168  $serializer
169  );
170  }
$storeManager
$configFactory
Definition: config_data.php:43

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize resource model

Returns
void

Definition at line 177 of file Config.php.

178  {
179  $this->_init(\Magento\Catalog\Model\ResourceModel\Config::class);
180  }

◆ _getResource()

_getResource ( )
protected

Retrieve resource model

Returns
\Magento\Catalog\Model\ResourceModel\Config

Definition at line 420 of file Config.php.

421  {
422  return $this->_configFactory->create();
423  }

◆ getAttributeGroupId()

getAttributeGroupId (   $attributeSetId,
  $name 
)
Parameters
float | int | string$attributeSetId
string$name
Returns
bool|string|int|float

Definition at line 318 of file Config.php.

319  {
320  if (is_numeric($name)) {
321  return $name;
322  }
323 
324  $this->loadAttributeGroups();
325 
326  if (!is_numeric($attributeSetId)) {
328  }
329  $name = strtolower($name);
330  return isset(
331  $this->_attributeGroupsByName[$attributeSetId][$name]
332  ) ? $this->_attributeGroupsByName[$attributeSetId][$name] : false;
333  }
getAttributeSetId($entityTypeId, $name=null)
Definition: Config.php:254
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getAttributeGroupName()

getAttributeGroupName (   $attributeSetId,
  $id 
)
Parameters
float | int | string$attributeSetId
float | int | string$id
Returns
bool|string

Definition at line 297 of file Config.php.

298  {
299  if (!is_numeric($id)) {
300  return $id;
301  }
302 
303  $this->loadAttributeGroups();
304 
305  if (!is_numeric($attributeSetId)) {
307  }
308  return isset(
309  $this->_attributeGroupsById[$attributeSetId][$id]
310  ) ? $this->_attributeGroupsById[$attributeSetId][$id] : false;
311  }
$id
Definition: fieldset.phtml:14
getAttributeSetId($entityTypeId, $name=null)
Definition: Config.php:254

◆ getAttributeSetId()

getAttributeSetId (   $entityTypeId,
  $name = null 
)
Parameters
string | int | float$entityTypeId
string | null$name
Returns
false|string|int

Definition at line 254 of file Config.php.

255  {
256  if (is_numeric($name)) {
257  return $name;
258  }
259  $this->loadAttributeSets();
260 
261  if (!is_numeric($entityTypeId)) {
262  $entityTypeId = $this->getEntityType($entityTypeId)->getId();
263  }
264  $name = strtolower($name);
265  return isset(
266  $this->_attributeSetsByName[$entityTypeId][$name]
267  ) ? $this->_attributeSetsByName[$entityTypeId][$name] : false;
268  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getAttributeSetName()

getAttributeSetName (   $entityTypeId,
  $id 
)
Parameters
string | int | float$entityTypeId
float | int$id
Returns
false|string

Definition at line 234 of file Config.php.

235  {
236  if (!is_numeric($id)) {
237  return $id;
238  }
239  $this->loadAttributeSets();
240 
241  if (!is_numeric($entityTypeId)) {
242  $entityTypeId = $this->getEntityType($entityTypeId)->getId();
243  }
244  return isset(
245  $this->_attributeSetsById[$entityTypeId][$id]
246  ) ? $this->_attributeSetsById[$entityTypeId][$id] : false;
247  }
$id
Definition: fieldset.phtml:14

◆ getAttributesUsedForSortBy()

getAttributesUsedForSortBy ( )

Retrieve Attributes array used for sort by

Returns
array

Definition at line 453 of file Config.php.

454  {
455  if ($this->_usedForSortBy === null) {
456  $this->_usedForSortBy = [];
458  $attributesData = $this->_getResource()->getAttributesUsedForSortBy();
459  $this->_eavConfig->importAttributesData($entityType, $attributesData);
460  foreach ($attributesData as $attributeData) {
461  $attributeCode = $attributeData['attribute_code'];
462  $this->_usedForSortBy[$attributeCode] = $this->_eavConfig->getAttribute($entityType, $attributeCode);
463  }
464  }
465  return $this->_usedForSortBy;
466  }
$attributesData
$attributeCode
Definition: extend.phtml:12

◆ getAttributesUsedInProductListing()

getAttributesUsedInProductListing ( )

Retrieve Attributes used in product listing

Returns
array

Definition at line 430 of file Config.php.

431  {
432  if ($this->_usedInProductListing === null) {
433  $this->_usedInProductListing = [];
435  $attributesData = $this->_getResource()->setStoreId($this->getStoreId())->getAttributesUsedInListing();
436  $this->_eavConfig->importAttributesData($entityType, $attributesData);
437  foreach ($attributesData as $attributeData) {
438  $attributeCode = $attributeData['attribute_code'];
439  $this->_usedInProductListing[$attributeCode] = $this->_eavConfig->getAttribute(
440  $entityType,
442  );
443  }
444  }
446  }
$attributesData
$attributeCode
Definition: extend.phtml:12

◆ getAttributeUsedForSortByArray()

getAttributeUsedForSortByArray ( )

Retrieve Attributes Used for Sort by as array key = code, value = name

Returns
array

Definition at line 474 of file Config.php.

475  {
476  $options = ['position' => __('Position')];
477  foreach ($this->getAttributesUsedForSortBy() as $attribute) {
478  /* @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
479  $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
480  }
481 
482  return $options;
483  }
__()
Definition: __.php:13

◆ getProductAttributes()

getProductAttributes ( )

Load Product attributes

Returns
array

Definition at line 407 of file Config.php.

408  {
409  if ($this->_productAttributes === null) {
410  $this->_productAttributes = array_keys($this->getAttributesUsedInProductListing());
411  }
413  }

◆ getProductListDefaultSortBy()

getProductListDefaultSortBy (   $store = null)

Retrieve Product List Default Sort By

Parameters
mixed$store
Returns
string

Definition at line 491 of file Config.php.

492  {
493  return $this->_scopeConfig->getValue(
494  self::XML_PATH_LIST_DEFAULT_SORT_BY,
495  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
496  $store
497  );
498  }

◆ getProductTypeId()

getProductTypeId (   $name)
Parameters
string$name
Returns
false|string

Definition at line 360 of file Config.php.

361  {
362  if (is_numeric($name)) {
363  return $name;
364  }
365 
366  $this->loadProductTypes();
367 
368  $name = strtolower($name);
369  return isset($this->_productTypesByName[$name]) ? $this->_productTypesByName[$name] : false;
370  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getProductTypeName()

getProductTypeName (   $id)
Parameters
float | int | string$id
Returns
false|string

Definition at line 376 of file Config.php.

377  {
378  if (!is_numeric($id)) {
379  return $id;
380  }
381 
382  $this->loadProductTypes();
383 
384  return $this->_productTypesById[$id] ?? false;
385  }
$id
Definition: fieldset.phtml:14

◆ getSourceOptionId()

getSourceOptionId (   $source,
  $value 
)
Parameters
\Magento\Framework\DataObject$source
string$value
Returns
null|mixed

Definition at line 392 of file Config.php.

393  {
394  foreach ($source->getAllOptions() as $option) {
395  if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
396  return $option['value'];
397  }
398  }
399  return null;
400  }
$source
Definition: source.php:23
$value
Definition: gender.phtml:16

◆ getStoreId()

getStoreId ( )

Return store id, if is not set return current app store

Returns
integer

Definition at line 199 of file Config.php.

200  {
201  if ($this->_storeId === null) {
202  return $this->_storeManager->getStore()->getId();
203  }
204  return $this->_storeId;
205  }

◆ loadAttributeGroups()

loadAttributeGroups ( )
Returns
$this

Definition at line 273 of file Config.php.

274  {
275  if ($this->_attributeGroupsById) {
276  return $this;
277  }
278 
279  $attributeSetCollection = $this->_groupCollectionFactory->create()->load();
280 
281  $this->_attributeGroupsById = [];
282  $this->_attributeGroupsByName = [];
284  $attributeSetId = $attributeGroup->getAttributeSetId();
285  $name = $attributeGroup->getAttributeGroupName();
286  $this->_attributeGroupsById[$attributeSetId][$id] = $name;
287  $this->_attributeGroupsByName[$attributeSetId][strtolower($name)] = $id;
288  }
289  return $this;
290  }
$id
Definition: fieldset.phtml:14
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ loadAttributeSets()

loadAttributeSets ( )
Returns
$this

Definition at line 210 of file Config.php.

211  {
212  if ($this->_attributeSetsById) {
213  return $this;
214  }
215 
216  $attributeSetCollection = $this->_setCollectionFactory->create()->load();
217 
218  $this->_attributeSetsById = [];
219  $this->_attributeSetsByName = [];
220  foreach ($attributeSetCollection as $id => $attributeSet) {
221  $entityTypeId = $attributeSet->getEntityTypeId();
222  $name = $attributeSet->getAttributeSetName();
223  $this->_attributeSetsById[$entityTypeId][$id] = $name;
224  $this->_attributeSetsByName[$entityTypeId][strtolower($name)] = $id;
225  }
226  return $this;
227  }
$id
Definition: fieldset.phtml:14
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ loadProductTypes()

loadProductTypes ( )
Returns
$this

Definition at line 338 of file Config.php.

339  {
340  if ($this->_productTypesById) {
341  return $this;
342  }
343 
344  $productTypeCollection = $this->_productTypeFactory->create()->getOptionArray();
345 
346  $this->_productTypesById = [];
347  $this->_productTypesByName = [];
348  foreach ($productTypeCollection as $id => $type) {
349  $name = $type;
350  $this->_productTypesById[$id] = $name;
351  $this->_productTypesByName[strtolower($name)] = $id;
352  }
353  return $this;
354  }
$id
Definition: fieldset.phtml:14
$type
Definition: item.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setStoreId()

setStoreId (   $storeId)

Set store id

Parameters
integer$storeId
Returns
\Magento\Catalog\Model\Config

Definition at line 188 of file Config.php.

189  {
190  $this->_storeId = $storeId;
191  return $this;
192  }

Field Documentation

◆ $_attributeGroupsById

$_attributeGroupsById
protected

Definition at line 33 of file Config.php.

◆ $_attributeGroupsByName

$_attributeGroupsByName
protected

Definition at line 38 of file Config.php.

◆ $_attributeSetsById

$_attributeSetsById
protected

Definition at line 23 of file Config.php.

◆ $_attributeSetsByName

$_attributeSetsByName
protected

Definition at line 28 of file Config.php.

◆ $_configFactory

$_configFactory
protected

Definition at line 118 of file Config.php.

◆ $_eavConfig

$_eavConfig
protected

Definition at line 83 of file Config.php.

◆ $_groupCollectionFactory

$_groupCollectionFactory
protected

Definition at line 104 of file Config.php.

◆ $_productAttributes

$_productAttributes
protected

Definition at line 50 of file Config.php.

◆ $_productTypeFactory

$_productTypeFactory
protected

Definition at line 111 of file Config.php.

◆ $_productTypesById

$_productTypesById
protected

Definition at line 43 of file Config.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 76 of file Config.php.

◆ $_setCollectionFactory

$_setCollectionFactory
protected

Definition at line 97 of file Config.php.

◆ $_storeId

$_storeId = null
protected

Definition at line 69 of file Config.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 90 of file Config.php.

◆ $_usedForSortBy

$_usedForSortBy
protected

Definition at line 64 of file Config.php.

◆ $_usedInProductListing

$_usedInProductListing
protected

Definition at line 57 of file Config.php.

◆ XML_PATH_LIST_DEFAULT_SORT_BY

const XML_PATH_LIST_DEFAULT_SORT_BY = 'catalog/frontend/default_sort_by'

Definition at line 18 of file Config.php.


The documentation for this class was generated from the following file: