/** * {@inheritdoc} */ public function getCount() { $stores = $this->storesFactory->create(); /** @var \Magento\Store\Model\ResourceModel\Store\Collection $stores */ $stores->setWithoutDefaultFilter(); return $stores->getSize(); }
/** * Retrieve Full Option values array * * @return array */ public function getAllOptions() { if ($this->_options === null) { $this->_options = $this->_storeCollectionFactory->create()->load()->toOptionArray(); } return $this->_options; }
/** * @return array */ public function toOptionArray() { if (!$this->_options) { /** @var $stores \Magento\Store\Model\ResourceModel\Store\Collection */ $stores = $this->_storesFactory->create(); $this->_options = $stores->load()->toOptionArray(); } return $this->_options; }
/** * @param string[] $storeCodes list of stores by store codes, will return all if storeCodes is not set * @return \Magento\Store\Api\Data\StoreConfigInterface[] */ public function getStoreConfigs(array $storeCodes = null) { $storeConfigs = []; $storeCollection = $this->storeCollectionFactory->create(); if ($storeCodes != null) { $storeCollection->addFieldToFilter('code', ['in' => $storeCodes]); } foreach ($storeCollection->load() as $item) { $storeConfigs[] = $this->getStoreConfig($item); } return $storeConfigs; }
/** * 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 = []; foreach ($data as $v) { $storeObject = new \Magento\Framework\DataObject($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; }
/** * {@inheritdoc} */ public function getList() { if (!$this->allLoaded) { /** @var $storeCollection \Magento\Store\Model\ResourceModel\Store\Collection */ $storeCollection = $this->storeCollectionFactory->create(); $storeCollection->setLoadDefault(true); foreach ($storeCollection as $item) { $this->entities[$item->getCode()] = $item; $this->entitiesById[$item->getId()] = $item; } $this->allLoaded = true; } return $this->entities; }
/** * Retrieve new (not loaded) Store collection object with website filter * * @return \Magento\Store\Model\ResourceModel\Store\Collection */ public function getStoreCollection() { return $this->storeListFactory->create()->addWebsiteFilter($this->getId())->setLoadDefault(true); }
/** * @return \Magento\Store\Model\ResourceModel\Store\Collection */ protected function _createStoresCollection() { return $this->_storesFactory->create(); }
/** * 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; }