Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
SwatchAttributeCodes Class Reference

Public Member Functions

 __construct (CacheInterface $cache, ResourceConnection $resourceConnection, $cacheKey, array $cacheTags)
 
 getCodes ()
 

Detailed Description

Class SwatchAttributeCodes for getting codes of swatch attributes.

Definition at line 15 of file SwatchAttributeCodes.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( CacheInterface  $cache,
ResourceConnection  $resourceConnection,
  $cacheKey,
array  $cacheTags 
)

SwatchAttributeList constructor.

Parameters
CacheInterface$cache
ResourceConnection$resourceConnection
string$cacheKey
array$cacheTags

Definition at line 52 of file SwatchAttributeCodes.php.

57  {
58  $this->cache = $cache;
59  $this->resourceConnection = $resourceConnection;
60  $this->cacheKey = $cacheKey;
61  $this->cacheTags = $cacheTags;
62  }

Member Function Documentation

◆ getCodes()

getCodes ( )

Returns list of known swatch attribute codes. Check cache and database. Key is attribute_id, value is attribute_code

Returns
array

Definition at line 70 of file SwatchAttributeCodes.php.

71  {
72  if ($this->swatchAttributeCodes === null) {
73  $swatchAttributeCodesCache = $this->cache->load($this->cacheKey);
74  if (false === $swatchAttributeCodesCache) {
75  $swatchAttributeCodes = $this->getSwatchAttributeCodes();
76  $this->cache->save(json_encode($swatchAttributeCodes), $this->cacheKey, $this->cacheTags);
77  } else {
78  $swatchAttributeCodes = json_decode($swatchAttributeCodesCache, true);
79  }
80  $this->swatchAttributeCodes = $swatchAttributeCodes;
81  }
82 
83  return $this->swatchAttributeCodes;
84  }

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