/**
  * @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;
 }
 /**
  * @return bool
  */
 protected function isNeededProcess()
 {
     return $this->storeSwitcher->isInitialized() && $this->generalConfig->isAvailable() && $this->geoWebsite->getId() !== false;
 }
 /**
  * @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());
 }