11
11
*/
12
12
namespace Magento \Catalog \Model \Product \Attribute \Source ;
13
13
14
+ use Magento \Directory \Model \CountryFactory ;
14
15
use Magento \Eav \Model \Entity \Attribute \Source \AbstractSource ;
16
+ use Magento \Framework \App \Cache \Type \Config ;
15
17
use Magento \Framework \Data \OptionSourceInterface ;
18
+ use Magento \Framework \Locale \ResolverInterface ;
19
+ use Magento \Framework \Serialize \SerializerInterface ;
20
+ use Magento \Store \Model \StoreManagerInterface ;
16
21
17
22
class Countryofmanufacture extends AbstractSource implements OptionSourceInterface
18
23
{
19
24
/**
20
- * @var \Magento\Framework\App\Cache\Type\ Config
25
+ * @var Config
21
26
*/
22
27
protected $ _configCacheType ;
23
28
24
29
/**
25
- * Store manager
26
- *
27
- * @var \Magento\Store\Model\StoreManagerInterface
30
+ * @var StoreManagerInterface
28
31
*/
29
32
protected $ _storeManager ;
30
33
31
34
/**
32
- * Country factory
33
- *
34
- * @var \Magento\Directory\Model\CountryFactory
35
+ * @var CountryFactory
35
36
*/
36
37
protected $ _countryFactory ;
37
38
38
39
/**
39
- * @var \Magento\Framework\Serialize\ SerializerInterface
40
+ * @var SerializerInterface
40
41
*/
41
42
private $ serializer ;
42
43
44
+ /**
45
+ * @var ResolverInterface
46
+ */
47
+ private $ localeResolver ;
48
+
43
49
/**
44
50
* Construct
45
51
*
46
- * @param \Magento\Directory\Model\CountryFactory $countryFactory
47
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
48
- * @param \Magento\Framework\App\Cache\Type\Config $configCacheType
52
+ * @param CountryFactory $countryFactory
53
+ * @param StoreManagerInterface $storeManager
54
+ * @param Config $configCacheType
55
+ * @param ResolverInterface $localeResolver
56
+ * @param SerializerInterface $serializer
49
57
*/
50
58
public function __construct (
51
- \Magento \Directory \Model \CountryFactory $ countryFactory ,
52
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
53
- \Magento \Framework \App \Cache \Type \Config $ configCacheType
59
+ CountryFactory $ countryFactory ,
60
+ StoreManagerInterface $ storeManager ,
61
+ Config $ configCacheType ,
62
+ ResolverInterface $ localeResolver ,
63
+ SerializerInterface $ serializer
54
64
) {
55
65
$ this ->_countryFactory = $ countryFactory ;
56
66
$ this ->_storeManager = $ storeManager ;
57
67
$ this ->_configCacheType = $ configCacheType ;
68
+ $ this ->localeResolver = $ localeResolver ;
69
+ $ this ->serializer = $ serializer ;
58
70
}
59
71
60
72
/**
@@ -64,32 +76,20 @@ public function __construct(
64
76
*/
65
77
public function getAllOptions ()
66
78
{
67
- $ cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_ ' . $ this ->_storeManager ->getStore ()->getCode ();
79
+ $ storeCode = $ this ->_storeManager ->getStore ()->getCode ();
80
+ $ locale = $ this ->localeResolver ->getLocale ();
81
+
82
+ $ cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_ ' . $ storeCode . '_LOCALE_ ' . $ locale ;
68
83
if ($ cache = $ this ->_configCacheType ->load ($ cacheKey )) {
69
- $ options = $ this ->getSerializer () ->unserialize ($ cache );
84
+ $ options = $ this ->serializer ->unserialize ($ cache );
70
85
} else {
71
86
/** @var \Magento\Directory\Model\Country $country */
72
87
$ country = $ this ->_countryFactory ->create ();
73
88
/** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */
74
89
$ collection = $ country ->getResourceCollection ();
75
90
$ options = $ collection ->load ()->toOptionArray ();
76
- $ this ->_configCacheType ->save ($ this ->getSerializer () ->serialize ($ options ), $ cacheKey );
91
+ $ this ->_configCacheType ->save ($ this ->serializer ->serialize ($ options ), $ cacheKey );
77
92
}
78
93
return $ options ;
79
94
}
80
-
81
- /**
82
- * Get serializer
83
- *
84
- * @return \Magento\Framework\Serialize\SerializerInterface
85
- * @deprecated 102.0.0
86
- */
87
- private function getSerializer ()
88
- {
89
- if ($ this ->serializer === null ) {
90
- $ this ->serializer = \Magento \Framework \App \ObjectManager::getInstance ()
91
- ->get (\Magento \Framework \Serialize \SerializerInterface::class);
92
- }
93
- return $ this ->serializer ;
94
- }
95
95
}
0 commit comments