/** * {@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; }
public function testGetCount() { $storesMock = $this->getMock('\\Magento\\Store\\Model\\ResourceModel\\Store\\Collection', [], [], '', false); $this->storesFactoryMock->expects($this->once())->method('create')->willReturn($storesMock); $storesMock->expects($this->once())->method('setWithoutDefaultFilter')->willReturnSelf(); $storesMock->expects($this->once())->method('getSize')->willReturn('expected'); $this->assertEquals('expected', $this->model->getCount()); }
/** * @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; }
public function testGetStoreConfigs() { $id = 1; $code = 'default'; $websiteId = 1; $baseUrl = 'http://magento/base_url'; $secureBaseUrl = 'https://magento/base_url'; $baseLinkUrl = 'http://magento/base_url/links'; $secureBaseLinkUrl = 'https://magento/base_url/links'; $baseStaticUrl = 'http://magento/base_url/pub/static'; $secureBaseStaticUrl = 'https://magento/base_url/static'; $baseMediaUrl = 'http://magento/base_url/pub/media'; $secureBaseMediaUrl = 'https://magento/base_url/pub/media'; $locale = 'en_US'; $timeZone = 'America/Los_Angeles'; $baseCurrencyCode = 'USD'; $defaultDisplayCurrencyCode = 'GBP'; $weightUnit = 'lbs'; $storeMocks = []; $storeConfigs = ['id' => $id, 'code' => $code, 'website_id' => $websiteId, 'base_url' => $baseUrl, 'secure_base_url' => $secureBaseUrl, 'base_link_url' => $baseLinkUrl, 'secure_base_link_url' => $secureBaseLinkUrl, 'base_static_url' => $baseStaticUrl, 'secure_base_static_url' => $secureBaseStaticUrl, 'base_media_url' => $baseMediaUrl, 'secure_base_media_url' => $secureBaseMediaUrl]; $storeMocks[] = $this->getStoreMock($storeConfigs); $storeCollectionMock = $this->getMockBuilder('\\Magento\\Store\\Model\\ResourceModel\\Store\\Collection')->disableOriginalConstructor()->getMock(); $storeCollectionMock->expects($this->once())->method('addFieldToFilter')->with('code', ['in' => [$code]])->willReturnSelf(); $storeCollectionMock->expects($this->once())->method('load')->willReturn($storeMocks); $this->storeCollectionFactoryMock->expects($this->once())->method('create')->willReturn($storeCollectionMock); $storeConfigDataObject = $this->createStoreConfigDataObject(); $this->storeConfigFactoryMock->expects($this->once())->method('create')->willReturn($storeConfigDataObject); $configValues = [['general/locale/code', ScopeInterface::SCOPE_STORES, $code, $locale], ['currency/options/base', ScopeInterface::SCOPE_STORES, $code, $baseCurrencyCode], ['currency/options/default', ScopeInterface::SCOPE_STORES, $code, $defaultDisplayCurrencyCode], ['general/locale/timezone', ScopeInterface::SCOPE_STORES, $code, $timeZone], [\Magento\Directory\Helper\Data::XML_PATH_WEIGHT_UNIT, ScopeInterface::SCOPE_STORES, $code, $weightUnit]]; $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturnMap($configValues); $result = $this->model->getStoreConfigs([$code]); $this->assertEquals(1, count($result)); $this->assertEquals($id, $result[0]->getId()); $this->assertEquals($code, $result[0]->getCode()); $this->assertEquals($weightUnit, $result[0]->getWeightUnit()); $this->assertEquals($baseUrl, $result[0]->getBaseUrl()); $this->assertEquals($secureBaseUrl, $result[0]->getSecureBaseUrl()); $this->assertEquals($baseLinkUrl, $result[0]->getBaseLinkUrl()); $this->assertEquals($secureBaseLinkUrl, $result[0]->getSecureBaseLinkUrl()); $this->assertEquals($baseStaticUrl, $result[0]->getBaseStaticUrl()); $this->assertEquals($secureBaseStaticUrl, $result[0]->getSecureBaseStaticUrl()); $this->assertEquals($baseMediaUrl, $result[0]->getBaseMediaUrl()); $this->assertEquals($secureBaseMediaUrl, $result[0]->getSecureBaseMediaUrl()); $this->assertEquals($timeZone, $result[0]->getTimezone()); $this->assertEquals($locale, $result[0]->getLocale()); $this->assertEquals($baseCurrencyCode, $result[0]->getBaseCurrencyCode()); $this->assertEquals($defaultDisplayCurrencyCode, $result[0]->getDefaultDisplayCurrencyCode()); }
/** * {@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; }