/**
  * 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;
 }
 public function testGetStoreId()
 {
     $countryCode = 'UA';
     $configDefaultStore = 2;
     $this->generalConfig->expects($this->once())->method('getDefaultStore')->willReturn($configDefaultStore);
     $this->assertEquals($configDefaultStore, $this->defaultStore->getStoreId($countryCode));
 }
 public function testGetStoreIdNotInList()
 {
     $countryCode = 'UA';
     $countryList = ['US', 'UK'];
     $this->generalConfig->expects($this->once())->method('getCountryList')->willReturn($countryList);
     $this->generalConfig->expects($this->never())->method('getCountryStore');
     $this->assertFalse($this->country->getStoreId($countryCode));
 }
 /**
  * {@inheritdoc}
  */
 public function getCurrentStoreId()
 {
     $store = $this->getDefaultStoreById(parent::getCurrentStoreId());
     $this->generalConfig->setOriginStore($store);
     if ($this->generalConfig->isAvailable() && !$this->isSwitched) {
         $this->switchScope();
         $this->isSwitched = true;
     }
     return parent::getCurrentStoreId();
 }
 /**
  * @param string $countryCode
  * @return bool|int
  */
 protected function getGroup($countryCode)
 {
     $groupCount = $this->generalConfig->getGroupCount();
     for ($group = 1; $group <= $groupCount; $group++) {
         if (in_array($countryCode, $this->generalConfig->getGroupCountryList($group))) {
             return $group;
         }
     }
     return false;
 }
 /**
  * @param int|bool $storeId
  * @param string $countryCode
  * @return int
  */
 public function updateStoreId($storeId, $countryCode)
 {
     if (!$this->generalConfig->isMappingSore()) {
         return $storeId;
     }
     $countryStoreCode = strtolower($countryCode);
     if (in_array($countryStoreCode, $this->getWebsite($storeId)->getStoreCodes())) {
         $storeId = $this->storeRepository->get($countryStoreCode)->getId();
     }
     return $storeId;
 }
 public function testGetStoreIdNoGroup()
 {
     $countryCode = 'UA';
     $groupCount = 2;
     $group1 = 1;
     $groupCountryList1 = ['US', 'UK'];
     $group2 = 2;
     $groupCountryList2 = ['DE', 'FR'];
     $this->generalConfig->expects($this->once())->method('getGroupCount')->willReturn($groupCount);
     $this->generalConfig->expects($this->exactly(2))->method('getGroupCountryList')->willReturnMap([[$group1, $groupCountryList1], [$group2, $groupCountryList2]]);
     $this->generalConfig->expects($this->never())->method('getGroupStore');
     $this->assertFalse($this->groupCountry->getStoreId($countryCode));
 }
 public function testGetGroupStore()
 {
     $group = 2;
     $countryStore = 12;
     $this->scopeConfig->expects($this->once())->method('getWebsiteValue')->with("tobai_geo_store_switcher/group_{$group}/store")->willReturn($countryStore);
     $this->assertEquals($countryStore, $this->configGeneral->getGroupStore($group));
 }
 protected function setGeneralConfigIsAvailable($isAvailable)
 {
     if (null === $isAvailable) {
         $this->generalConfig->expects($this->never())->method('isAvailable');
     } else {
         $this->generalConfig->expects($this->once())->method('isAvailable')->willReturn($isAvailable);
     }
     return $this->generalConfig;
 }
 public function testAfterGetDefaultStoreNotInWebsite()
 {
     $storeId = 1;
     $websiteStoreIds = [1, 3];
     $geoStoreId = 2;
     $this->generalConfig->expects($this->once())->method('isAvailable')->willReturn(true);
     $this->storeSwitcher->expects($this->once())->method('isInitialized')->willReturn(true);
     $this->storeSwitcher->expects($this->once())->method('getStoreId')->willReturn($geoStoreId);
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->once())->method('getStoreIds')->willReturn($websiteStoreIds);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($storeId);
     $this->assertSame($store, $this->geoWebsite->afterGetDefaultStore($website, $store));
 }
 public function testUpdateStoreIdNotFoundCountryStore()
 {
     $countryCode = 'UA';
     $storeId = 2;
     $websiteStoreCodes = ['us', 'uk'];
     $websiteId = 11;
     $this->generalConfig->expects($this->once())->method('isMappingSore')->willReturn(true);
     $store = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
     $this->storeRepository->expects($this->once())->method('getById')->willReturn($store);
     $this->storeRepository->expects($this->never())->method('get');
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->once())->method('getStoreCodes')->willReturn($websiteStoreCodes);
     $this->websiteRepository->expects($this->once())->method('getById')->with($websiteId)->willReturn($website);
     $this->websiteRepository->expects($this->never())->method('getDefault');
     $this->assertEquals($storeId, $this->countryStoreMapping->updateStoreId($storeId, $countryCode));
 }
 /**
  * @param string $countryCode
  * @return bool
  */
 protected function isRuleForCountry($countryCode)
 {
     return in_array($countryCode, $this->generalConfig->getCountryList());
 }
 /**
  * @return bool
  */
 protected function isNeededProcess()
 {
     return $this->storeSwitcher->isInitialized() && $this->generalConfig->isAvailable() && $this->geoWebsite->getId() !== false;
 }
 /**
  * @param string $countryCode
  * @return int|bool
  */
 public function getStoreId($countryCode)
 {
     return $this->generalConfig->getDefaultStore();
 }
 /**
  * @param int|bool $storeId
  * @param string $identifierValue
  * @param string $geoIdentifierValue
  * @dataProvider afterGetValueDataProvider
  */
 public function testAfterGetValue($storeId, $identifierValue, $geoIdentifierValue)
 {
     $this->generalConfig->expects($this->once())->method('isAvailable')->willReturn(true);
     $this->storeSwitcher->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     /** @var \Magento\Framework\App\PageCache\Identifier $identifier */
     $identifier = $this->getMockBuilder('Magento\\Framework\\App\\PageCache\\Identifier')->disableOriginalConstructor()->getMock();
     $this->assertEquals($geoIdentifierValue, $this->geoIdentifier->afterGetValue($identifier, $identifierValue));
 }
 /**
  * @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;
 }