Example #1
0
 /**
  * Retrieve component names and configs from remote satis repository
  *
  * @return \Traversable
  */
 public function getComponentsInfo()
 {
     try {
         if (!($responseBody = $this->cache->load(self::RESPONSE_CACHE_KEY))) {
             $responseBody = $this->fetch($this->getFeedUrl());
             $this->cache->save($responseBody, self::RESPONSE_CACHE_KEY, [], 86400);
         }
         $response = $this->jsonHelper->jsonDecode($responseBody);
     } catch (\Exception $e) {
         $response = [];
         // Swissup_Subscription will be added below - used by
         // subscription activation module
     }
     if (!is_array($response)) {
         $response = [];
     }
     if (!empty($response['packages'])) {
         $modules = [];
         foreach ($response['packages'] as $packageName => $info) {
             $versions = array_keys($info);
             $latestVersion = array_reduce($versions, function ($carry, $item) {
                 if (version_compare($carry, $item) === -1) {
                     $carry = $item;
                 }
                 return $carry;
             });
             if (!empty($info[$latestVersion]['type']) && $info[$latestVersion]['type'] === 'metapackage') {
                 continue;
             }
             (yield [$packageName, $info[$latestVersion]]);
         }
     }
     (yield ['swissup/subscription', ['name' => 'swissup/subscription', 'type' => 'subscription-plan', 'description' => 'SwissUpLabs Modules Subscription', 'version' => '', 'extra' => ['swissup' => ['links' => ['store' => 'https://swissuplabs.com', 'download' => 'https://swissuplabs.com/subscription/customer/products/', 'identity_key' => 'https://swissuplabs.com/license/customer/identity/']]]]]);
 }
 /**
  * Cache validated response
  *
  * @param ValidateRequest $validateRequest
  * @param $storeId
  * @return ValidateResult
  * @throws \SoapFault
  */
 public function validate(ValidateRequest $validateRequest, $storeId)
 {
     $addressCacheKey = $this->getCacheKey($validateRequest->getAddress()) . $storeId;
     $validateResult = @unserialize($this->cache->load($addressCacheKey));
     if ($validateResult instanceof ValidateResult) {
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\ValidateResult from cache.', ['request' => var_export($validateRequest, true), 'result' => var_export($validateResult, true), 'cache_key' => $addressCacheKey]);
         return $validateResult;
     }
     try {
         $addressService = $this->interactionAddress->getAddressService($this->type, $storeId);
         $validateResult = $addressService->validate($validateRequest);
         $serializedValidateResult = serialize($validateResult);
         $this->cache->save($serializedValidateResult, $addressCacheKey, [Config::AVATAX_CACHE_TAG]);
         $validAddress = isset($validateResult->getValidAddresses()[0]) ? $validateResult->getValidAddresses()[0] : null;
         $validAddressCacheKey = $this->getCacheKey($validAddress);
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\ValidateResult from SOAP.', ['request' => var_export($validateRequest, true), 'result' => var_export($validateResult, true)]);
         $this->cache->save($serializedValidateResult, $validAddressCacheKey, [Config::AVATAX_CACHE_TAG]);
     } catch (LocalizedException $e) {
         $this->avaTaxLogger->addDebug('\\AvaTax\\ValidateResult no valid address found from SOAP.', ['result' => var_export($validateResult, true)]);
     } catch (\SoapFault $e) {
         $this->avaTaxLogger->error("Exception: \n" . $e->getMessage() . "\n" . $e->faultstring, ['request' => var_export($addressService->__getLastRequest(), true), 'result' => var_export($addressService->__getLastResponse(), true)]);
         throw $e;
     }
     return $validateResult;
 }
 /**
  * Creates a currency instance.
  *
  * @param CacheInterface $appCache
  * @param string|array $options Options array or currency short name when string is given
  * @param string $locale Locale name
  */
 public function __construct(CacheInterface $appCache, $options = null, $locale = null)
 {
     // set Zend cache to low level frontend app cache
     $lowLevelFrontendCache = $appCache->getFrontend()->getLowLevelFrontend();
     \Zend_Currency::setCache($lowLevelFrontendCache);
     parent::__construct($options, $locale);
 }
Example #4
0
 /**
  * @dataProvider checkUpdateDataProvider
  * @param bool $callInbox
  * @param string $curlRequest
  */
 public function testCheckUpdate($callInbox, $curlRequest)
 {
     $mockName = 'Test Product Name';
     $mockVersion = '0.0.0';
     $mockEdition = 'Test Edition';
     $mockUrl = 'http://test-url';
     $this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName);
     $this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion);
     $this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition);
     $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl);
     $configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl];
     $lastUpdate = 0;
     $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate));
     $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl));
     $this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
     $this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest));
     $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1'));
     $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false));
     $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com'));
     $this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
     if ($callInbox) {
         $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel));
         $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf());
     } else {
         $this->inboxFactory->expects($this->never())->method('create');
         $this->inboxModel->expects($this->never())->method('parse');
     }
     $this->feed->checkUpdate();
 }
Example #5
0
 /**
  * Test afterUpdateMview
  *
  * @return void
  */
 public function testAfterUpdateMview()
 {
     $tags = ['tag_name1', 'tag_name2'];
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock]));
     $this->contextMock->expects($this->atLeastOnce())->method('getIdentities')->willReturn($tags);
     $this->cacheMock->expects($this->once())->method('clean')->with($tags);
     $this->plugin->afterUpdateMview($this->subjectMock);
 }
Example #6
0
 public function testCleanType()
 {
     $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will($this->returnValue(serialize($this->_typesArray)));
     $this->_config->expects($this->once())->method('getType')->with(self::TYPE_KEY)->will($this->returnValue(['instance' => self::CACHE_TYPE]));
     unset($this->_typesArray[self::TYPE_KEY]);
     $this->_cache->expects($this->once())->method('save')->with(serialize($this->_typesArray), TypeList::INVALIDATED_TYPES);
     $this->_typeList->cleanType(self::TYPE_KEY);
 }
 public function testGetStoreLabelsByAttributeIdWithCacheSave()
 {
     $attributeId = 1;
     $cacheId = \Magento\Eav\Plugin\Model\ResourceModel\Entity\Attribute::STORE_LABEL_ATTRIBUTE . $attributeId;
     $this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false);
     $this->cache->expects($this->any())->method('save')->with(serialize([$attributeId]), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     $this->assertEquals([$attributeId], $this->getAttribute(true)->aroundGetStoreLabelsByAttributeId($this->subject, $this->mockPluginProceed([$attributeId]), $attributeId));
 }
Example #8
0
 /**
  * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
  * @param \Magento\Framework\App\CacheInterface $cache
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param string $connectionName
  */
 public function __construct(
     \Magento\Framework\Model\ResourceModel\Db\Context $context,
     \Magento\Framework\App\CacheInterface $cache,
     \Magento\Framework\Stdlib\DateTime $dateTime,
     $connectionName = null
 ) {
     $this->dateTime = $dateTime;
     parent::__construct($context, $connectionName);
     $this->_cache = $cache->getFrontend();
 }
 /**
  * @param  array  $configs
  *
  * @return void
  */
 public function changeConfigs(array $configs)
 {
     foreach ($configs as $config) {
         $config = array_merge($this->defaultConfig, $config);
         if ($this->isValidConfig($config)) {
             $this->changeConfig($config['path'], $config['value'], $config['scope_type'], $config['scope_code']);
         }
     }
     $this->cache->clean();
 }
Example #10
0
 public function testGetFeedsWithCache()
 {
     $dataProvider = $this->getMock('Magento\\Framework\\App\\Rss\\DataProviderInterface');
     $dataProvider->expects($this->any())->method('getCacheKey')->will($this->returnValue('cache_key'));
     $dataProvider->expects($this->any())->method('getCacheLifetime')->will($this->returnValue(100));
     $dataProvider->expects($this->never())->method('getRssData');
     $this->rss->setDataProvider($dataProvider);
     $this->cacheInterface->expects($this->once())->method('load')->will($this->returnValue(serialize($this->feedData)));
     $this->cacheInterface->expects($this->never())->method('save');
     $this->assertEquals($this->feedData, $this->rss->getFeeds());
 }
Example #11
0
 public function testExecuteRandom()
 {
     $newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
     $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
     $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
     $this->managerMock->expects($this->once())->method('addSuccessMessage');
     $this->managerMock->expects($this->once())->method('addNoticeMessage');
     $this->cacheMock->expects($this->once())->method('clean');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->model->execute();
 }
Example #12
0
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Config $config
  * @param callable $proceed
  * @return array
  */
 public function aroundGetAttributesUsedForSortBy(\Magento\Catalog\Model\ResourceModel\Config $config, \Closure $proceed)
 {
     $cacheId = self::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_' . $config->getStoreId();
     if ($this->isCacheEnabled && ($attributes = $this->cache->load($cacheId))) {
         return unserialize($attributes);
     }
     $attributes = $proceed();
     if ($this->isCacheEnabled) {
         $this->cache->save(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $attributes;
 }
Example #13
0
 public function testGetAttributesUsedForSortByWithCacheSave()
 {
     $entityTypeId = 'type';
     $storeId = 'store';
     $attributes = ['attributes'];
     $this->subject->expects($this->any())->method('getEntityTypeId')->willReturn($entityTypeId);
     $this->subject->expects($this->any())->method('getStoreId')->willReturn($storeId);
     $cacheId = \Magento\Catalog\Plugin\Model\ResourceModel\Config::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $entityTypeId . '_' . $storeId;
     $this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false);
     $this->cache->expects($this->any())->method('save')->with(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     $this->assertEquals($attributes, $this->getConfig(true)->aroundGetAttributesUsedForSortBy($this->subject, $this->mockPluginProceed($attributes)));
 }
Example #14
0
 /**
  * Check verification result and return true if system must to show notification message
  *
  * @return bool
  */
 private function _canShowNotification()
 {
     if ($this->_cache->load(self::VERIFICATION_RESULT_CACHE_KEY)) {
         return false;
     }
     if ($this->_isFileAccessible()) {
         return true;
     }
     $adminSessionLifetime = (int) $this->_backendConfig->getValue('admin/security/session_lifetime');
     $this->_cache->save(true, self::VERIFICATION_RESULT_CACHE_KEY, [], $adminSessionLifetime);
     return false;
 }
Example #15
0
 /**
  * @param \Magento\Eav\Model\Resource\Entity\Attribute $subject
  * @param callable $proceed
  * @param int $attributeId
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetStoreLabelsByAttributeId(\Magento\Eav\Model\Resource\Entity\Attribute $subject, \Closure $proceed, $attributeId)
 {
     $cacheId = self::STORE_LABEL_ATTRIBUTE . $attributeId;
     if ($this->isCacheEnabled && ($storeLabels = $this->cache->load($cacheId))) {
         return unserialize($storeLabels);
     }
     $storeLabels = $proceed($attributeId);
     if ($this->isCacheEnabled) {
         $this->cache->save(serialize($storeLabels), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $storeLabels;
 }
Example #16
0
 public function testFinish()
 {
     $cacheTypeListArray = array('one', 'two');
     $this->_cache->expects($this->once())->method('clean');
     $this->_config->expects($this->once())->method('reinit');
     $this->_cacheState->expects($this->once())->method('persist');
     $this->_cacheState->expects($this->exactly(count($cacheTypeListArray)))->method('setEnabled');
     $this->_cacheTypeList->expects($this->once())->method('getTypes')->will($this->returnValue($cacheTypeListArray));
     $this->_appState->expects($this->once())->method('setInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->_installerConfig->expects($this->once())->method('replaceTmpInstallDate')->with($this->greaterThanOrEqual(date('r')));
     $this->assertSame($this->_model, $this->_model->finish());
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function getThemeById($themeId)
 {
     $theme = $this->cache->load('theme-by-id-' . $themeId);
     if ($theme) {
         return unserialize($theme);
     }
     /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
     $themeModel = $this->themeFactory->create();
     $themeModel->load($themeId);
     if ($themeModel->getId()) {
         $this->cache->save(serialize($themeModel), 'theme-by-id-' . $themeId);
     }
     return $themeModel;
 }
 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage, $itemId)
 {
     $quote = $this->quoteRepository->get($cartId);
     /** @var CartItemInterface $item */
     $item = $this->getQuoteItem($cartId, $itemId);
     if ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $itemId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage)
 {
     /** @var CartInterface $quote */
     $quote = $this->quoteRepository->get($cartId);
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Gift Messages is not applicable for empty cart'));
     }
     if ($quote->getIsVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $cartId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
 /**
  * Run test toHtml method
  *
  * @param bool $customerId
  * @return void
  *
  * @dataProvider dataProviderToHtml
  */
 public function testToHtml($customerId)
 {
     $cacheData = false;
     $idQueryParam = 'id-query-param';
     $sessionId = 'session-id';
     $this->additional->setData('cache_lifetime', 789);
     $this->additional->setData('cache_key', 'cache-key');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false);
     // get cache
     $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true);
     // save cache
     $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false);
     $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData);
     $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam);
     $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId);
     // call protected _toHtml method
     $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false);
     $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock);
     $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     if ($customerId) {
         $this->assertEquals('<span><a  >Not you?</a></span>', $this->additional->toHtml());
     } else {
         $this->assertEquals('', $this->additional->toHtml());
     }
 }
Example #21
0
 /**
  * Clean existed jobs
  *
  * @param string $groupId
  * @return $this
  */
 protected function _cleanup($groupId)
 {
     // check if history cleanup is needed
     $lastCleanup = (int) $this->_cache->load(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId);
     $historyCleanUp = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($lastCleanup > time() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
         return $this;
     }
     /**
      * @var \Magento\Cron\Model\Resource\Schedule\Collection $history
      */
     $history = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter('status', array('in' => array(Schedule::STATUS_SUCCESS, Schedule::STATUS_MISSED, Schedule::STATUS_ERROR)))->load();
     $historySuccess = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_SUCCESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyFailure = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_FAILURE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyLifetimes = array(Schedule::STATUS_SUCCESS => $historySuccess * self::SECONDS_IN_MINUTE, Schedule::STATUS_MISSED => $historyFailure * self::SECONDS_IN_MINUTE, Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE);
     $now = time();
     /** @var Schedule $record */
     foreach ($history as $record) {
         if (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) {
             $record->delete();
         }
     }
     // save time history cleanup was ran with no expiration
     $this->_cache->save(time(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId, array('crontab'), null);
     return $this;
 }
 /**
  * Clean existed jobs
  *
  * @param string $groupId
  * @return $this
  */
 protected function _cleanup($groupId)
 {
     // check if history cleanup is needed
     $lastCleanup = (int) $this->_cache->load(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId);
     $historyCleanUp = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($lastCleanup > $this->timezone->scopeTimeStamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
         return $this;
     }
     // check how long the record should stay unprocessed before marked as MISSED
     $scheduleLifetime = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
     /**
      * @var \Magento\Cron\Model\ResourceModel\Schedule\Collection $history
      */
     $history = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter('status', ['in' => [Schedule::STATUS_SUCCESS, Schedule::STATUS_MISSED, Schedule::STATUS_ERROR]])->load();
     $historySuccess = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_SUCCESS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyFailure = (int) $this->_scopeConfig->getValue('system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_FAILURE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $historyLifetimes = [Schedule::STATUS_SUCCESS => $historySuccess * self::SECONDS_IN_MINUTE, Schedule::STATUS_MISSED => $historyFailure * self::SECONDS_IN_MINUTE, Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE];
     $now = $this->timezone->scopeTimeStamp();
     /** @var Schedule $record */
     foreach ($history as $record) {
         $checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) : strtotime($record->getScheduledAt()) + $scheduleLifetime;
         if ($checkTime < $now - $historyLifetimes[$record->getStatus()]) {
             $record->delete();
         }
     }
     // save time history cleanup was ran with no expiration
     $this->_cache->save($this->timezone->scopeTimeStamp(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId, ['crontab'], null);
     return $this;
 }
Example #23
0
 /**
  * Get codes of all entity type attributes
  *
  * @param  mixed $entityType
  * @param  \Magento\Framework\DataObject $object
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getEntityAttributeCodes($entityType, $object = null)
 {
     $entityType = $this->getEntityType($entityType);
     $attributeSetId = 0;
     $storeId = 0;
     if ($object instanceof \Magento\Framework\DataObject) {
         $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId;
         $storeId = $object->getStoreId() ?: $storeId;
     }
     $cacheKey = self::ATTRIBUTES_CODES_CACHE_ID . $entityType->getId() . '-' . $storeId . '-' . $attributeSetId;
     if (isset($this->_attributeCodes[$cacheKey])) {
         return $this->_attributeCodes[$cacheKey];
     }
     if ($this->isCacheEnabled() && ($attributes = $this->_cache->load($cacheKey))) {
         $this->_attributeCodes[$cacheKey] = unserialize($attributes);
         return $this->_attributeCodes[$cacheKey];
     }
     if ($attributeSetId) {
         $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setAttributeSetFilter($attributeSetId)->addStoreLabel($storeId)->getData();
         $attributes = [];
         foreach ($attributesInfo as $attributeData) {
             $attributes[] = $attributeData['attribute_code'];
             $this->_createAttribute($entityType, $attributeData);
         }
     } else {
         $this->_initAttributes($entityType);
         $attributes = array_keys($this->_attributeData[$entityType->getEntityTypeCode()]);
     }
     $this->_attributeCodes[$cacheKey] = $attributes;
     if ($this->isCacheEnabled()) {
         $this->_cache->save(serialize($attributes), $cacheKey, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $attributes;
 }
Example #24
0
 /**
  * Clear attributes cache
  *
  * @return bool
  */
 public function clear()
 {
     unset($this->attributeInstances);
     if ($this->isAttributeCacheEnabled()) {
         $this->cache->clean([\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return true;
 }
 /**
  * Cache validated response
  *
  * @param GetTaxRequest $getTaxRequest
  * @param $storeId
  * @param bool $useCache
  * @return GetTaxResult
  * @throws LocalizedException
  */
 public function getTax(GetTaxRequest $getTaxRequest, $storeId, $useCache = false)
 {
     $cacheKey = $this->getCacheKey($getTaxRequest) . $storeId;
     $getTaxResult = @unserialize($this->cache->load($cacheKey));
     if ($getTaxResult instanceof GetTaxResult && $useCache) {
         $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\GetTaxResult from cache.', ['result' => var_export($getTaxResult, true), 'cache_key' => $cacheKey]);
         return $getTaxResult;
     }
     $getTaxResult = $this->taxInteraction->getTaxService($this->type, $storeId)->getTax($getTaxRequest);
     $this->avaTaxLogger->addDebug('Loaded \\AvaTax\\GetTaxResult from SOAP.', ['request' => var_export($getTaxRequest, true), 'result' => var_export($getTaxResult, true)]);
     // Only cache successful requests
     if ($useCache && $getTaxResult->getResultCode() == \AvaTax\SeverityLevel::$Success) {
         $serializedGetTaxResult = serialize($getTaxResult);
         $this->cache->save($serializedGetTaxResult, $cacheKey, [Config::AVATAX_CACHE_TAG], self::CACHE_LIFETIME);
     }
     return $getTaxResult;
 }
Example #26
0
 /**
  * @return array
  */
 public function getFeeds()
 {
     if ($this->dataProvider === null) {
         return [];
     }
     $cache = false;
     if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
         $cache = $this->cache->load($this->dataProvider->getCacheKey());
     }
     if ($cache) {
         return unserialize($cache);
     }
     $data = $this->dataProvider->getRssData();
     if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
         $this->cache->save(serialize($data), $this->dataProvider->getCacheKey(), ['rss'], $this->dataProvider->getCacheLifetime());
     }
     return $data;
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function getLocale()
 {
     if (!$this->_locale) {
         \Zend_Locale_Data::setCache($this->_cache->getFrontend()->getLowLevelFrontend());
         $this->_locale = $this->_localeFactory->create(array('locale' => $this->getLocaleCode()));
     } elseif ($this->_locale->__toString() != $this->_localeCode) {
         $this->setLocale($this->_localeCode);
     }
     return $this->_locale;
 }
Example #28
0
 /**
  * @dataProvider checkUpdateDataProvider
  * @param bool $callInbox
  * @param string $curlRequest
  */
 public function testCheckUpdate($callInbox, $curlRequest)
 {
     $lastUpdate = 1410121748;
     $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl));
     $this->curl->expects($this->any())->method('read')->will($this->returnValue($curlRequest));
     $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1'));
     $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false));
     $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com'));
     $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate));
     $this->deploymentConfig->expects($this->once())->method('get')->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
     if ($callInbox) {
         $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel));
         $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf());
     } else {
         $this->inboxFactory->expects($this->never())->method('create');
         $this->inboxModel->expects($this->never())->method('parse');
     }
     $this->feed->checkUpdate();
 }
Example #29
0
 /**
  * @test
  * @return void
  * @covers \Magento\Theme\Model\Design::loadChange
  * @covers \Magento\Theme\Model\Design::__construct
  * @covers \Magento\Theme\Model\Design::_construct
  */
 public function testLoadChangeFromCache()
 {
     $storeId = 1;
     $localDate = '2\\28\\2000';
     $date = '28-02-2000';
     $cacheId = 'design_change_' . md5($storeId . $date);
     $this->localeDate->expects($this->once())->method('scopeTimeStamp')->with($storeId)->willReturn($localDate);
     $this->dateTime->expects($this->once())->method('formatDate')->with($localDate, false)->willReturn($date);
     $this->cacheManager->expects($this->once())->method('load')->with($cacheId)->willReturn(serialize(['test' => 'data']));
     $this->assertInstanceOf(get_class($this->model), $this->model->loadChange($storeId));
 }
 public function testSave()
 {
     $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock);
     $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(1);
     $this->quoteMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $this->messageMock->expects($this->any())->method('setCustomerId');
     $this->messageMock->expects($this->any())->method('setGiftMessageId');
     $this->cacheMock->expects($this->once())->method('save');
     $this->assertTrue($this->cartRepository->save($this->cartId, $this->messageMock));
 }