Example #1
0
 public function testSave()
 {
     $expectedResult = new \stdClass();
     $this->frontendMock->expects($this->once())->method('save')->with('test_value', 'test_id', ['test_tag_one', 'test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG], 111)->will($this->returnValue($expectedResult));
     $actualResult = $this->model->save('test_value', 'test_id', ['test_tag_one', 'test_tag_two'], 111);
     $this->assertSame($expectedResult, $actualResult);
 }
Example #2
0
 /**
  * @return void
  */
 protected function tearDown()
 {
     $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
     $reflection = new \ReflectionClass('Magento\\Framework\\Component\\ComponentRegistrar');
     $paths = $reflection->getProperty('paths');
     $paths->setAccessible(true);
     $paths->setValue($this->backupRegistrar);
     $paths->setAccessible(false);
 }
 /**
  * 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;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * @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;
 }
Example #8
0
 /**
  * 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);
     }
 }
Example #9
0
 /**
  * @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;
 }
Example #10
0
 /**
  * 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'];
     }
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 /**
  * 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);
 }
Example #14
0
 /**
  * Save services into the cache
  *
  * @param string $data serialized version of the webapi registry
  * @return $this
  */
 protected function _saveToCache($data)
 {
     $this->_configCacheType->save($data, self::CACHE_ID, array(\Magento\Webapi\Model\Cache\Type::CACHE_TAG));
     return $this;
 }
Example #15
0
 /**
  * @return void
  */
 protected function tearDown()
 {
     $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
 }