Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Countryofmanufacture.php
Go to the documentation of this file.
1 <?php
13 
16 
18 {
22  protected $_configCacheType;
23 
29  protected $_storeManager;
30 
36  protected $_countryFactory;
37 
41  private $serializer;
42 
50  public function __construct(
51  \Magento\Directory\Model\CountryFactory $countryFactory,
53  \Magento\Framework\App\Cache\Type\Config $configCacheType
54  ) {
55  $this->_countryFactory = $countryFactory;
56  $this->_storeManager = $storeManager;
57  $this->_configCacheType = $configCacheType;
58  }
59 
65  public function getAllOptions()
66  {
67  $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
68  if ($cache = $this->_configCacheType->load($cacheKey)) {
69  $options = $this->getSerializer()->unserialize($cache);
70  } else {
72  $country = $this->_countryFactory->create();
74  $collection = $country->getResourceCollection();
75  $options = $collection->load()->toOptionArray();
76  $this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
77  }
78  return $options;
79  }
80 
87  private function getSerializer()
88  {
89  if ($this->serializer === null) {
91  ->get(\Magento\Framework\Serialize\SerializerInterface::class);
92  }
93  return $this->serializer;
94  }
95 }
$storeManager
serialize($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
Definition: DataObject.php:446
__construct(\Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Cache\Type\Config $configCacheType)