13
13
14
14
use Magento \Framework \App \CacheInterface ;
15
15
use Magento \Store \Api \StoreResolverInterface ;
16
+ use Magento \Store \Model \StoreManagerInterface ;
16
17
use Magento \Framework \App \ObjectManager ;
17
18
use Magento \Eav \Model \Cache \Type as CacheType ;
18
19
use Magento \Eav \Model \Entity \Attribute ;
19
20
20
21
abstract class AbstractFrontend implements \Magento \Eav \Model \Entity \Attribute \Frontend \FrontendInterface
21
22
{
23
+ /**
24
+ * Default cache tags values
25
+ * will be used if no values in the constructor provided
26
+ * @var array
27
+ */
28
+ private static $ defaultCacheTags = [CacheType::CACHE_TAG , Attribute::CACHE_TAG ];
29
+
22
30
/**
23
31
* @var CacheInterface
24
32
*/
25
33
private $ cache ;
26
34
27
35
/**
28
- * @var StoreResolverInterface
36
+ * @var StoreManagerInterface
29
37
*/
30
- private $ storeResolver ;
38
+ private $ storeManager ;
31
39
32
40
/**
33
41
* @var array
@@ -51,21 +59,21 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
51
59
* @param CacheInterface $cache
52
60
* @param StoreResolverInterface $storeResolver
53
61
* @param array $cacheTags
62
+ * @param StoreManagerInterface $storeManager
54
63
* @codeCoverageIgnore
64
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
55
65
*/
56
66
public function __construct (
57
67
\Magento \Eav \Model \Entity \Attribute \Source \BooleanFactory $ attrBooleanFactory ,
58
68
CacheInterface $ cache = null ,
59
69
StoreResolverInterface $ storeResolver = null ,
60
- array $ cacheTags = [
61
- CacheType::CACHE_TAG ,
62
- Attribute::CACHE_TAG ,
63
- ]
70
+ array $ cacheTags = null ,
71
+ StoreManagerInterface $ storeManager = null
64
72
) {
65
73
$ this ->_attrBooleanFactory = $ attrBooleanFactory ;
66
74
$ this ->cache = $ cache ?: ObjectManager::getInstance ()->get (CacheInterface::class);
67
- $ this ->storeResolver = $ storeResolver ?: ObjectManager:: getInstance ()-> get (StoreResolverInterface::class) ;
68
- $ this ->cacheTags = $ cacheTags ;
75
+ $ this ->cacheTags = $ cacheTags ?: self :: $ defaultCacheTags ;
76
+ $ this ->storeManager = $ storeManager ?: ObjectManager:: getInstance ()-> get (StoreManagerInterface::class) ;
69
77
}
70
78
71
79
/**
@@ -252,7 +260,7 @@ public function getSelectOptions()
252
260
{
253
261
$ cacheKey = 'attribute-navigation-option- ' .
254
262
$ this ->getAttribute ()->getAttributeCode () . '- ' .
255
- $ this ->storeResolver -> getCurrentStoreId ();
263
+ $ this ->storeManager -> getStore ()-> getId ();
256
264
$ optionString = $ this ->cache ->load ($ cacheKey );
257
265
if (false === $ optionString ) {
258
266
$ options = $ this ->getAttribute ()->getSource ()->getAllOptions ();
0 commit comments