예제 #1
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;
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getGroups($withDefault = false)
 {
     $groups = $this->groupRepository->getList();
     return $withDefault ? $groups : array_filter($groups, function ($item) {
         return $item->getId() != 0;
     });
 }
예제 #4
0
 /**
  * Retrieve group model
  *
  * @return Group|bool
  */
 public function getGroup()
 {
     if (null === $this->getGroupId()) {
         return false;
     }
     return $this->groupRepository->get($this->getGroupId());
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreId($scopeCode)
 {
     $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
     return $this->groupRepository->get($website->getDefaultGroupId())->getDefaultStoreId();
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultStoreId($scopeCode)
 {
     return $this->groupRepository->get($scopeCode)->getDefaultStoreId();
 }