/** * Get list of all available countries * * @return array */ public function getAllOptions() { $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { $options = unserialize($cache); } else { $collection = $this->_countryFactory->create()->getResourceCollection()->loadByStore(); $options = $collection->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheKey); } return $options; }
/** * Return integrations loaded from cache if enabled or from files merged previously * * @return array * @api */ public function getIntegrations() { if (null === $this->_integrations) { $integrations = $this->_configCacheType->load(self::CACHE_ID); if ($integrations && is_string($integrations)) { $this->_integrations = unserialize($integrations); } else { $this->_integrations = $this->_configReader->read(); $this->_configCacheType->save(serialize($this->_integrations), self::CACHE_ID, [Type::CACHE_TAG]); } } return $this->_integrations; }
/** * Retrieve regions data json * * @return string */ public function getRegionJson() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); if (!$this->_regionJson) { $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE' . $this->_storeManager->getStore()->getId(); $json = $this->_configCacheType->load($cacheKey); if (empty($json)) { $countryIds = []; foreach ($this->getCountryCollection() as $country) { $countryIds[] = $country->getCountryId(); } $collection = $this->_regCollectionFactory->create(); $collection->addCountryFilter($countryIds)->load(); $regions = ['config' => ['show_all_regions' => $this->isShowNonRequiredState(), 'regions_required' => $this->getCountriesWithStatesRequired()]]; foreach ($collection as $region) { /** @var $region \Magento\Directory\Model\Region */ if (!$region->getRegionId()) { continue; } $regions[$region->getCountryId()][$region->getRegionId()] = ['code' => $region->getCode(), 'name' => (string) __($region->getName())]; } $json = $this->jsonHelper->jsonEncode($regions); if ($json === false) { $json = 'false'; } $this->_configCacheType->save($json, $cacheKey); } $this->_regionJson = $json; } \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__); return $this->_regionJson; }
/** * @param \Magento\Framework\App\Config\Initial\Reader $reader * @param \Magento\Framework\App\Cache\Type\Config $cache */ public function __construct(\Magento\Framework\App\Config\Initial\Reader $reader, \Magento\Framework\App\Cache\Type\Config $cache) { $data = $cache->load(self::CACHE_ID); if (!$data) { $data = $reader->read(); $cache->save(serialize($data), self::CACHE_ID); } else { $data = unserialize($data); } $this->_data = $data['data']; $this->_metadata = $data['metadata']; }
/** * @return mixed */ public function getCountryOptions() { $options = false; $cacheId = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($optionsCache = $this->_configCacheType->load($cacheId)) { $options = unserialize($optionsCache); } if ($options == false) { $options = $this->getCountryCollection()->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheId); } return $options; }
/** * Initialize menu object * * @return void */ protected function _initMenu() { if (!$this->_menu) { $this->_menu = $this->_menuFactory->create(); $cache = $this->_configCacheType->load(self::CACHE_MENU_OBJECT); if ($cache) { $this->_menu->unserialize($cache); return; } $this->_director->direct($this->_configReader->read($this->_appState->getAreaCode()), $this->_menuBuilder, $this->_logger); $this->_menu = $this->_menuBuilder->getResult($this->_menu); $this->_configCacheType->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT); } }
/** * @return string */ public function getRegionHtmlSelect() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . $this->_storeManager->getStore()->getId(); $cache = $this->_configCacheType->load($cacheKey); if ($cache) { $options = unserialize($cache); } else { $options = $this->getRegionCollection()->toOptionArray(); $this->_configCacheType->save(serialize($options), $cacheKey); } $html = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName('region')->setTitle(__('State/Province'))->setId('state')->setClass('required-entry validate-state')->setValue(intval($this->getRegionId()))->setOptions($options)->getHtml(); \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); return $html; }
/** * Class constructor * * @param \Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\Reader\Initial $reader The reader * @param \Magento\Framework\App\Cache\Type\Config $cache Cache instance */ public function __construct(Reader $reader, \Magento\Framework\App\Cache\Type\Config $cache) { $data = $cache->load(self::CACHE_ID); if (!$data) { $data = serialize($reader->read()); $cache->save($data, self::CACHE_ID); } $data = unserialize($data); if (isset($data['data'])) { $this->data = $data['data']; } if (isset($data['metadata'])) { $this->metadata = $data['metadata']; } }
/** * Initialize collectors array. * Collectors array is array of total models ordered based on configuration settings * * @return $this */ protected function _initCollectors() { $sortedCodes = []; $cachedData = $this->_configCacheType->load($this->_collectorsCacheKey); if ($cachedData) { $sortedCodes = unserialize($cachedData); } if (!$sortedCodes) { $sortedCodes = $this->_getSortedCollectorCodes($this->_modelsConfig); $this->_configCacheType->save(serialize($sortedCodes), $this->_collectorsCacheKey); } foreach ($sortedCodes as $code) { $this->_collectors[$code] = $this->_models[$code]; } return $this; }
/** * Retrieve regions data json * * @return string */ public function getRegionJson() { \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]); if (!$this->_regionJson) { $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE' . $this->_storeManager->getStore()->getId(); $json = $this->_configCacheType->load($cacheKey); if (empty($json)) { $regions = $this->getRegionData(); $json = $this->jsonHelper->jsonEncode($regions); if ($json === false) { $json = 'false'; } $this->_configCacheType->save($json, $cacheKey); } $this->_regionJson = $json; } \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__); return $this->_regionJson; }
/** * Checkout with PayPal image URL getter * Spares API calls of getting "pal" variable, by putting it into cache per store view * * @return string */ public function getCheckoutShortcutImageUrl() { // get "pal" thing from cache or lookup it via API $pal = null; if ($this->_config->areButtonsDynamic()) { $cacheId = self::PAL_CACHE_ID . $this->_storeManager->getStore()->getId(); $pal = $this->_configCacheType->load($cacheId); if (self::PAL_CACHE_ID == $pal) { $pal = null; } elseif (!$pal) { $pal = null; $this->_getApi(); try { $this->_api->callGetPalDetails(); $pal = $this->_api->getPal(); $this->_configCacheType->save($pal, $cacheId); } catch (\Exception $e) { $this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId); $this->_logger->critical($e); } } } return $this->_config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale(), $this->_quote->getBaseGrandTotal(), $pal); }
/** * Load services from cache * * @return string|bool */ protected function _loadFromCache() { return $this->_configCacheType->load(self::CACHE_ID); }