Esempio n. 1
0
 /**
  * Retrieve Full Option values array
  *
  * @return array
  */
 public function getAllOptions()
 {
     if ($this->_options === null) {
         $this->_options = $this->_storeCollectionFactory->create()->load()->toOptionArray();
     }
     return $this->_options;
 }
Esempio n. 2
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         /** @var $stores \Magento\Store\Model\Resource\Store\Collection */
         $stores = $this->_storesFactory->create();
         $this->_options = $stores->load()->toOptionArray();
     }
     return $this->_options;
 }
Esempio n. 3
0
 /**
  * Load data
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  */
 public function load($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     $this->_beforeLoad();
     $this->_renderFilters()->_renderOrders()->_renderLimit();
     $this->printLogQuery($printQuery, $logQuery);
     $data = $this->getData();
     $this->resetData();
     $stores = $this->_storeCollectionFactory->create()->setWithoutDefaultFilter()->load()->toOptionHash();
     $this->_items = array();
     foreach ($data as $v) {
         $storeObject = new \Magento\Framework\Object($v);
         $storeId = $v['store_id'];
         $storeName = isset($stores[$storeId]) ? $stores[$storeId] : null;
         $storeObject->setStoreName($storeName)->setWebsiteId($this->_storeManager->getStore($storeId)->getWebsiteId())->setAvgNormalized($v['avgsale'] * $v['num_orders']);
         $this->_items[$storeId] = $storeObject;
         foreach (array_keys($this->_totals) as $key) {
             $this->_totals[$key] += $storeObject->getData($key);
         }
     }
     if ($this->_totals['num_orders']) {
         $this->_totals['avgsale'] = $this->_totals['base_lifetime'] / $this->_totals['num_orders'];
     }
     $this->_setIsLoaded();
     $this->_afterLoad();
     return $this;
 }
Esempio n. 4
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));
 }
Esempio n. 5
0
 /**
  * Retrieve array of store ids for category
  *
  * @return array
  */
 public function getStoreIds()
 {
     if ($this->getInitialSetupFlag()) {
         return [];
     }
     $storeIds = $this->getData('store_ids');
     if ($storeIds) {
         return $storeIds;
     }
     if (!$this->getId()) {
         return [];
     }
     $nodes = [];
     foreach ($this->getPathIds() as $id) {
         $nodes[] = $id;
     }
     $storeIds = [];
     $storeCollection = $this->_storeCollectionFactory->create()->loadByCategoryIds($nodes);
     foreach ($storeCollection as $store) {
         $storeIds[$store->getId()] = $store->getId();
     }
     $entityStoreId = $this->getStoreId();
     if (!in_array($entityStoreId, $storeIds)) {
         array_unshift($storeIds, $entityStoreId);
     }
     if (!in_array(0, $storeIds)) {
         array_unshift($storeIds, 0);
     }
     $this->setData('store_ids', $storeIds);
     return $storeIds;
 }
Esempio n. 6
0
 /**
  * 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;
     }
 }
Esempio n. 7
0
 /**
  * @return \Magento\Store\Model\Resource\Store\Collection
  */
 protected function _createStoresCollection()
 {
     return $this->_storesFactory->create();
 }