示例#1
0
 protected function prepareMockForReinit()
 {
     $websiteId = 1;
     $websiteCode = 'website_code';
     $groupId = 1;
     $storeId = 1;
     $storeCode = 'store_code';
     $websiteCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Website\\Collection', [], [], '', false, false);
     $websiteCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($websiteCollection, [$this->_websiteMock]);
     $this->_websiteFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_websiteMock));
     $this->_websiteMock->expects($this->any())->method('getCollection')->will($this->returnValue($websiteCollection));
     $groupCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Group\\Collection', [], [], '', false, false);
     $groupCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($groupCollection, [$this->_groupMock]);
     $this->_groupFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_groupMock));
     $this->_groupMock->expects($this->any())->method('getCollection')->will($this->returnValue($groupCollection));
     $storeCollection = $this->getMock('\\Magento\\Store\\Model\\Resource\\Store\\Collection', [], [], '', false, false);
     $storeCollection->expects($this->any())->method('setLoadDefault')->with(true);
     $this->mockIterator($storeCollection, [$this->_storeMock]);
     $storeCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->_storeMock])));
     $storeCollection->expects($this->any())->method('getLastItem')->will($this->returnValue($this->_storeMock));
     $this->_storeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_storeMock));
     $this->_storeMock->expects($this->any())->method('getCollection')->will($this->returnValue($storeCollection));
     $this->_websiteCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($websiteCollection));
     $this->_groupCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($groupCollection));
     $this->_storeCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($storeCollection));
     $this->_storeMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->_storeMock->expects($this->any())->method('getGroupId')->will($this->returnValue($groupId));
     $this->_storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId));
     $this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue($storeCode));
     $websiteCollection->expects($this->any())->method('getItemById')->will($this->returnValue($this->_websiteMock));
     $groupCollection->expects($this->any())->method('getItemById')->will($this->returnValue($this->_groupMock));
     $this->_groupMock->expects($this->any())->method('getWebsiteId')->will($this->returnValue($websiteId));
     $this->_groupMock->expects($this->any())->method('getId')->will($this->returnValue($groupId));
     $this->_websiteMock->expects($this->any())->method('getId')->will($this->returnValue($websiteId));
     $this->_websiteMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode));
     $this->_websiteMock->expects($this->at(3))->method('__call')->will($this->returnValue(true));
 }
示例#2
0
文件: Db.php 项目: opexsw/magento2
 /**
  * Init store, group and website collections
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _initStores()
 {
     $this->_store = null;
     $this->_stores = [];
     $this->_groups = [];
     $this->_websites = [];
     $this->_website = null;
     /** @var $websiteCollection \Magento\Store\Model\Resource\Website\Collection */
     $websiteCollection = $this->_websiteCollectionFactory->create();
     $websiteCollection->setLoadDefault(true);
     /** @var $groupCollection \Magento\Store\Model\Resource\Group\Collection */
     $groupCollection = $this->_groupCollectionFactory->create();
     $groupCollection->setLoadDefault(true);
     /** @var $storeCollection \Magento\Store\Model\Resource\Store\Collection */
     $storeCollection = $this->_storeCollectionFactory->create();
     $storeCollection->setLoadDefault(true);
     $this->_hasSingleStore = false;
     if ($this->_isSingleStoreAllowed && $storeCollection->count() < 3) {
         $this->_hasSingleStore = true;
         $this->_store = $storeCollection->getLastItem();
     }
     $websiteStores = [];
     $websiteGroups = [];
     $groupStores = [];
     foreach ($storeCollection as $store) {
         /** @var $store Store */
         $this->_stores[$store->getId()] = $store;
         $this->_stores[$store->getCode()] = $store;
         $websiteStores[$store->getWebsiteId()][$store->getId()] = $store;
         $groupStores[$store->getGroupId()][$store->getId()] = $store;
     }
     foreach ($groupCollection as $group) {
         /* @var $group Group */
         if (!isset($groupStores[$group->getId()])) {
             $groupStores[$group->getId()] = [];
         }
         $group->setStores($groupStores[$group->getId()]);
         $websiteGroups[$group->getWebsiteId()][$group->getId()] = $group;
         $this->_groups[$group->getId()] = $group;
     }
     foreach ($websiteCollection as $website) {
         /* @var $website Website */
         if (!isset($websiteGroups[$website->getId()])) {
             $websiteGroups[$website->getId()] = [];
         }
         if (!isset($websiteStores[$website->getId()])) {
             $websiteStores[$website->getId()] = [];
         }
         if ($website->getIsDefault()) {
             $this->_website = $website;
         }
         $website->setGroups($websiteGroups[$website->getId()]);
         $website->setStores($websiteStores[$website->getId()]);
         $this->_websites[$website->getId()] = $website;
         $this->_websites[$website->getCode()] = $website;
     }
 }