Пример #1
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->assignedWebsites = [self::SECOND_WEBSITE_ID];
     $this->websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->secondWebsiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->websiteRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\WebsiteRepositoryInterface')->setMethods(['getList', 'getDefault'])->getMockForAbstractClass();
     $this->websiteRepositoryMock->expects($this->any())->method('getDefault')->willReturn($this->websiteMock);
     $this->websiteRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
     $this->groupRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\GroupRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->storeRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\StoreRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->locatorMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Locator\\LocatorInterface')->setMethods(['getProduct', 'getWebsiteIds'])->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getWebsiteIds')->willReturn($this->assignedWebsites);
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['isSingleStoreMode'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('isSingleStoreMode')->willReturn(false);
     $this->groupMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Group\\Collection')->setMethods(['getId', 'getName', 'getWebsiteId'])->disableOriginalConstructor()->getMock();
     $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn(self::WEBSITE_ID);
     $this->groupMock->expects($this->any())->method('getId')->willReturn(self::GROUP_ID);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->groupMock]);
     $this->storeViewMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getName', 'getId', 'getStoreGroupId'])->disableOriginalConstructor()->getMock();
     $this->storeViewMock->expects($this->any())->method('getName')->willReturn(self::STORE_VIEW_NAME);
     $this->storeViewMock->expects($this->any())->method('getStoreGroupId')->willReturn(self::GROUP_ID);
     $this->storeViewMock->expects($this->any())->method('getId')->willReturn(self::STORE_VIEW_ID);
     $this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->storeViewMock]);
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->secondWebsiteMock->expects($this->any())->method('getId')->willReturn($this->assignedWebsites[0]);
     $this->websiteMock->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
 }
 /**
  * @param int|bool $storeId
  * @return \Magento\Store\Model\Website
  */
 protected function getWebsite($storeId)
 {
     if ($storeId) {
         $websiteId = $this->storeRepository->getById($storeId)->getWebsiteId();
         $website = $this->websiteRepository->getById($websiteId);
     } else {
         $website = $this->websiteRepository->getDefault();
     }
     return $website;
 }
Пример #3
0
 /**
  * Prepares websites list with groups and stores as array
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function getWebsitesList()
 {
     if (!empty($this->websitesList)) {
         return $this->websitesList;
     }
     $this->websitesList = [];
     $groupList = $this->groupRepository->getList();
     $storesList = $this->storeRepository->getList();
     foreach ($this->websiteRepository->getList() as $website) {
         $websiteId = $website->getId();
         if (!$websiteId) {
             continue;
         }
         $websiteRow = ['id' => $websiteId, 'name' => $website->getName(), 'storesCount' => 0, 'groups' => []];
         foreach ($groupList as $group) {
             $groupId = $group->getId();
             if (!$groupId || $group->getWebsiteId() != $websiteId) {
                 continue;
             }
             $groupRow = ['id' => $groupId, 'name' => $group->getName(), 'stores' => []];
             foreach ($storesList as $store) {
                 $storeId = $store->getId();
                 if (!$storeId || $store->getStoreGroupId() != $groupId) {
                     continue;
                 }
                 $websiteRow['storesCount']++;
                 $groupRow['stores'][] = ['id' => $storeId, 'name' => $store->getName()];
             }
             $websiteRow['groups'][] = $groupRow;
         }
         $this->websitesList[] = $websiteRow;
     }
     return $this->websitesList;
 }
 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));
 }
Пример #5
0
 /**
  * Retrieve store website
  *
  * @return Website|bool
  */
 public function getWebsite()
 {
     if ($this->getWebsiteId() === null) {
         return false;
     }
     return $this->websiteRepository->getById($this->getWebsiteId());
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreId($scopeCode)
 {
     $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
     return $this->groupRepository->get($website->getDefaultGroupId())->getDefaultStoreId();
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreView()
 {
     $defaultWebsite = $this->websiteRepository->getDefault();
     $defaultStore = $this->getGroup($defaultWebsite->getDefaultGroupId())->getDefaultStore();
     return $defaultStore ?: null;
 }