/** * @return bool|int */ public function getId() { if (null === $this->defaultWebsiteId && $this->storeSwitcher->isInitialized()) { try { $storeId = $this->storeSwitcher->getStoreId(); if ($storeId) { $store = $this->storeRepository->getById($storeId); $this->defaultWebsiteId = $store->getWebsiteId(); } else { $this->defaultWebsiteId = false; } } catch (\Exception $e) { $this->defaultWebsiteId = false; } } return $this->defaultWebsiteId ?: false; }
/** * Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual * * @param \Magento\Framework\App\PageCache\Identifier $identifier * @param string $result * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetValue(\Magento\Framework\App\PageCache\Identifier $identifier, $result) { if ($this->generalConfig->isAvailable() && $this->storeSwitcher->getStoreId()) { $result .= $this->storeSwitcher->getStoreId(); } return $result; }
/** * Change scope */ protected function switchScope() { $storeId = $this->storeSwitcher->getStoreId(); if ($storeId) { $this->runMode = ScopeInterface::SCOPE_STORE; $this->scopeCode = $this->storeRepository->getById($storeId)->getCode(); } }
/** * @param \Magento\Store\Model\Group $subject * @param \Magento\Store\Model\Store $store * @return \Magento\Store\Model\Store */ public function afterGetDefaultStore(Group $subject, Store $store) { if ($this->generalConfig->isAvailable() && $this->storeSwitcher->isInitialized()) { $storeId = $this->storeSwitcher->getStoreId(); if ($store->getId() != $storeId && in_array($storeId, $subject->getStoreIds())) { $store = $this->storeRepository->getById($storeId); } } return $store; }
public function testGetStoreIdWithPermanentRuleException() { $countryCode = 'UA'; $storeId = 2; $ex = new \Exception('Permanent Rule Exception'); $this->country->expects($this->once())->method('getCountryCode')->willReturn($countryCode); $this->rule->expects($this->once())->method('getStoreId')->with($countryCode)->willReturn($storeId); $this->permanentRule->expects($this->once())->method('updateStoreId')->with($storeId, $countryCode)->willThrowException($ex); $this->logger->expects($this->once())->method('critical')->with($ex); $this->assertFalse($this->switcher->isInitialized()); $this->assertEquals($storeId, $this->switcher->getStoreId()); $this->assertTrue($this->switcher->isInitialized()); }