/** * Run action * * @return void */ public function run() { $this->_lastRecord = $this->_timestamp($this->_round($this->getLastRecordDate())); foreach ($this->_storeManager->getStores(false) as $store) { $this->_process($store->getId()); } }
/** * Delete products from flat table(s) * * @param int|array $productId * @param null|int $storeId * @return void */ public function deleteProductsFromStore($productId, $storeId = null) { if (!is_array($productId)) { $productId = array($productId); } if (null === $storeId) { foreach ($this->storeManager->getStores() as $store) { $this->connection->delete($this->productIndexerHelper->getFlatTableName($store->getId()), array('entity_id IN(?)' => $productId)); } } else { $this->connection->delete($this->productIndexerHelper->getFlatTableName((int) $storeId), array('entity_id IN(?)' => $productId)); } }
/** * Process path info * * @param string $pathInfo * @return string * @throws NoSuchEntityException */ public function process($pathInfo) { $pathParts = $this->stripPathBeforeStorecode($pathInfo); $storeCode = $pathParts[0]; $stores = $this->storeManager->getStores(false, true); if (isset($stores[$storeCode])) { $this->storeManager->setCurrentStore($storeCode); $path = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); } else { $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::DEFAULT_CODE); $path = '/' . implode('/', $pathParts); } return $path; }
/** * Obtain all current store ids, depending on configuration * * @param null|array $predefinedStoreIds * @return array */ public function getCurrentStoreIds(array $predefinedStoreIds = null) { $stores = array(); // get all or specified stores if ($this->_storeManager->getStore()->getId() == 0) { if (null !== $predefinedStoreIds) { $stores = $predefinedStoreIds; } else { foreach ($this->_storeManager->getStores() as $store) { $stores[] = $store->getId(); } } } else { // get all stores, required by configuration in current store scope $productsScope = $this->_scopeConfig->getValue('catalog/recently_products/scope', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); switch ($productsScope) { case 'website': $resourceStore = $this->_storeManager->getStore()->getWebsite()->getStores(); break; case 'group': $resourceStore = $this->_storeManager->getStore()->getGroup()->getStores(); break; default: $resourceStore = array($this->_storeManager->getStore()); break; } foreach ($resourceStore as $store) { $stores[] = $store->getId(); } } foreach ($stores as $key => $store) { $stores[$key] = (int) $store; } return $stores; }
/** * Return array of rating summary * * @param \Magento\Review\Model\Rating $object * @param boolean $onlyForCurrentStore * @return array */ public function getEntitySummary($object, $onlyForCurrentStore = true) { $data = $this->_getEntitySummaryData($object); if ($onlyForCurrentStore) { foreach ($data as $row) { if ($row['store_id'] == $this->_storeManager->getStore()->getId()) { $object->addData($row); } } return $object; } $stores = $this->_storeManager->getStores(); $result = array(); foreach ($data as $row) { $clone = clone $object; $clone->addData($row); $result[$clone->getStoreId()] = $clone; } $usedStoresId = array_keys($result); foreach ($stores as $store) { if (!in_array($store->getId(), $usedStoresId)) { $clone = clone $object; $clone->setCount(0); $clone->setSum(0); $clone->setStoreId($store->getId()); $result[$store->getId()] = $clone; } } return array_values($result); }
/** * Perform operations after collection load * * @return $this */ protected function _afterLoad() { if ($this->_previewFlag) { $items = $this->getColumnValues('page_id'); $connection = $this->getConnection(); if (count($items)) { $select = $connection->select()->from(array('cps' => $this->getTable('cms_page_store')))->where('cps.page_id IN (?)', $items); if ($result = $connection->fetchPairs($select)) { foreach ($this as $item) { if (!isset($result[$item->getData('page_id')])) { continue; } if ($result[$item->getData('page_id')] == 0) { $stores = $this->_storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getData('page_id')]; $storeCode = $this->_storeManager->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); } } } } return parent::_afterLoad(); }
/** * Retrieve store Ids for $path with checking * * return array($storeId => $pathValue) * * @param string $path * @return array */ public function getStoresConfigByPath($path) { $stores = $this->_storeManager->getStores(true); $storeValues = array(); /** @var $store \Magento\Store\Model\Store */ foreach ($stores as $store) { try { $value = $this->_config->getValue($path, ScopeInterface::SCOPE_STORE, $store->getCode()); $storeValues[$store->getId()] = $value; } catch (NoSuchEntityException $e) { // Store doesn't really exist, so move on. continue; } } return $storeValues; }
/** * Iterate through website configurations and collect all SFTP configurations * Filter config values if necessary * * @param bool $automaticMode Whether to skip settings with disabled Automatic Fetching or not * @return array */ public function getSftpCredentials($automaticMode = false) { $configs = array(); $uniques = array(); foreach ($this->_storeManager->getStores() as $store) { /*@var $store \Magento\Store\Model\Store */ $active = $this->_scopeConfig->isSetFlag('paypal/fetch_reports/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); if (!$active && $automaticMode) { continue; } $cfg = array('hostname' => $this->_scopeConfig->getValue('paypal/fetch_reports/ftp_ip', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store), 'path' => $this->_scopeConfig->getValue('paypal/fetch_reports/ftp_path', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store), 'username' => $this->_scopeConfig->getValue('paypal/fetch_reports/ftp_login', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store), 'password' => $this->_scopeConfig->getValue('paypal/fetch_reports/ftp_password', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store), 'sandbox' => $this->_scopeConfig->getValue('paypal/fetch_reports/ftp_sandbox', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store)); if (empty($cfg['username']) || empty($cfg['password'])) { continue; } if (empty($cfg['hostname']) || $cfg['sandbox']) { $cfg['hostname'] = $cfg['sandbox'] ? self::SANDBOX_REPORTS_HOSTNAME : self::REPORTS_HOSTNAME; } if (empty($cfg['path']) || $cfg['sandbox']) { $cfg['path'] = self::REPORTS_PATH; } // avoid duplicates if (in_array(serialize($cfg), $uniques)) { continue; } $uniques[] = serialize($cfg); $configs[] = $cfg; } return $configs; }
/** * Initialize stores data * * @param bool $withDefault * @return $this */ protected function _initStores($withDefault = false) { /** @var $store \Magento\Store\Model\Store */ foreach ($this->_storeManager->getStores($withDefault) as $store) { $this->_storeCodeToId[$store->getCode()] = $store->getId(); } return $this; }
/** * Get store views as id => name associative array * * @param bool $withDefault * @param string $attribute * @return array */ public function getStoreOptionHash($withDefault = false, $attribute = 'name') { $options = array(); foreach ($this->_storeManager->getStores((bool) $withDefault && $this->_isAdminScopeAllowed) as $store) { $options[$store->getId()] = $store->getDataUsingMethod($attribute); } return $options; }
/** * Process path info * * @param \Magento\Framework\App\RequestInterface $request * @param string $pathInfo * @return string */ public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo) { $pathParts = explode('/', ltrim($pathInfo, '/'), 2); $storeCode = $pathParts[0]; $stores = $this->_storeManager->getStores(false, true); if (isset($stores[$storeCode]) && $stores[$storeCode]->isUseStoreInUrl()) { if (!$request->isDirectAccessFrontendName($storeCode)) { $this->_storeManager->setCurrentStore($storeCode); $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); return $pathInfo; } elseif (!empty($storeCode)) { $request->setActionName('noroute'); return $pathInfo; } return $pathInfo; } return $pathInfo; }
/** * Initialize stores hash * * @return $this */ protected function _initStores() { /** @var $store \Magento\Store\Model\Store */ foreach ($this->_storeManager->getStores(true) as $store) { $this->_storeIdToCode[$store->getId()] = $store->getCode(); } ksort($this->_storeIdToCode); // to ensure that 'admin' store (ID is zero) goes first return $this; }
/** * Generate list of urls for default store * * @return \Magento\UrlRedirect\Service\V1\Data\UrlRewrite[] */ protected function generateForDefaultStore() { $urls = []; foreach ($this->storeManager->getStores() as $store) { if ($this->catalogUrlRewriteHelper->isNeedCreateUrlRewrite($store->getStoreId(), $this->product->getId())) { $urls = array_merge($urls, $this->generateForStore($store->getStoreId())); } } return $urls; }
/** * Joins store titles for rates * * @return $this */ public function joinStoreTitles() { $storeCollection = $this->_storeManager->getStores(true); foreach ($storeCollection as $store) { $tableAlias = sprintf('title_table_%s', $store->getId()); $joinCondition = implode(' AND ', array("main_table.tax_calculation_rate_id = {$tableAlias}.tax_calculation_rate_id", $this->getConnection()->quoteInto($tableAlias . '.store_id = ?', $store->getId()))); $this->_select->joinLeft(array($tableAlias => $this->getTable('tax_calculation_rate_title')), $joinCondition, array($tableAlias => 'value')); } return $this; }
/** * Run reindexation * * @return void */ protected function reindex() { foreach ($this->storeManager->getStores() as $store) { if ($this->getPathFromCategoryId($store->getRootCategoryId())) { $this->reindexRootCategory($store); $this->reindexAnchorCategories($store); $this->reindexNonAnchorCategories($store); } } }
/** * Generate list of urls per store * * @param int[] $storeIds * @return UrlRewrite[] */ protected function generateForSpecificStores($storeIds) { $urls = []; $existingStores = $this->storeManager->getStores(); foreach ($storeIds as $storeId) { if (!isset($existingStores[$storeId])) { continue; } $urls[] = $this->createUrlRewrite($storeId); } return $urls; }
/** * Return list of store names where tax discount settings are compatible. * Return true if settings are wrong for default store. * * @return array */ public function getStoresWithWrongDiscountSettings() { $storeNames = array(); $storeCollection = $this->storeManager->getStores(true); foreach ($storeCollection as $store) { if (!$this->checkDiscountSettings($store)) { $website = $store->getWebsite(); $storeNames[] = $website->getName() . '(' . $store->getName() . ')'; } } return $storeNames; }
/** * Save option values records per store * * @param int $optionId * @param array $values * @return void */ protected function _updateAttributeOptionValues($optionId, $values) { $adapter = $this->_getWriteAdapter(); $table = $this->getTable('eav_attribute_option_value'); $adapter->delete($table, array('option_id = ?' => $optionId)); $stores = $this->_storeManager->getStores(true); foreach ($stores as $store) { $storeId = $store->getId(); if (!empty($values[$storeId]) || isset($values[$storeId]) && $values[$storeId] == '0') { $data = array('option_id' => $optionId, 'store_id' => $storeId, 'value' => $values[$storeId]); $adapter->insert($table, $data); } } }
/** * Return stores grouped by assigned themes * * @return array */ public function getStoresByThemes() { $storesByThemes = array(); $stores = $this->_storeManager->getStores(); /** @var $store \Magento\Store\Model\Store */ foreach ($stores as $store) { $themeId = $this->_getConfigurationThemeId($store); if (!isset($storesByThemes[$themeId])) { $storesByThemes[$themeId] = array(); } $storesByThemes[$themeId][] = $store; } return $storesByThemes; }
/** * Retrieve allowed currencies according to config * * @return array */ public function getConfigAllowCurrencies() { $allowedCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_ALLOW); $appBaseCurrencyCode = $this->_directoryHelper->getBaseCurrencyCode(); if (!in_array($appBaseCurrencyCode, $allowedCurrencies)) { $allowedCurrencies[] = $appBaseCurrencyCode; } foreach ($this->_storeManager->getStores() as $store) { $code = $store->getBaseCurrencyCode(); if (!in_array($code, $allowedCurrencies)) { $allowedCurrencies[] = $code; } } return $allowedCurrencies; }
/** * Add products to changes list with price which depends on date * * @return void */ public function refreshSpecialPrices() { $connection = $this->_getWriteConnection(); foreach ($this->_storeManager->getStores(true) as $store) { $timestamp = $this->_localeDate->scopeTimeStamp($store); $currDate = $this->_dateTime->formatDate($timestamp, false); $currDateExpr = $connection->quote($currDate); // timestamp is locale based if (date(\Zend_Date::HOUR_SHORT, $timestamp) == '00') { $format = '%Y-%m-%d %H:%i:%s'; $this->_refreshSpecialPriceByStore($store->getId(), 'special_from_date', $connection->getDateFormatSql($currDateExpr, $format)); $dateTo = $connection->getDateAddSql($currDateExpr, -1, \Magento\Framework\DB\Adapter\AdapterInterface::INTERVAL_DAY); $this->_refreshSpecialPriceByStore($store->getId(), 'special_to_date', $connection->getDateFormatSql($dateTo, $format)); } } }
/** * Retrieve stores array or store model * * @param int $storeId * @return \Magento\Store\Model\Store|\Magento\Store\Model\Store[] */ public function getStores($storeId = null) { if ($this->_stores === null) { $this->_stores = $this->_prepareStoreRootCategories($this->_storeManager->getStores()); } if ($storeId && isset($this->_stores[$storeId])) { return $this->_stores[$storeId]; } return $this->_stores; }
/** * Retrieve shared store ids for current website or all stores if $current is false * * @return array */ public function getSharedStoreIds() { if (is_null($this->_storeIds) || !is_array($this->_storeIds)) { if ($this->_useCurrentWebsite) { $this->_storeIds = $this->getStore()->getWebsite()->getStoreIds(); } else { $_storeIds = array(); $stores = $this->_storeManager->getStores(); foreach ($stores as $store) { $_storeIds[] = $store->getId(); } $this->_storeIds = $_storeIds; } } return $this->_storeIds; }
/** * Regenerate search index for store(s) * * @param int|array|null $productIds * @return void */ protected function rebuildIndex($productIds = null) { $storeIds = array_keys($this->storeManager->getStores()); foreach ($storeIds as $storeId) { $this->rebuildStoreIndex($storeId, $productIds); } }
/** * {@inheritDoc} */ public function isCustomerInStore($customerWebsiteId, $storeId) { $ids = []; if ((bool) $this->configShare->isWebsiteScope()) { $ids = $this->storeManager->getWebsite($customerWebsiteId)->getStoreIds(); } else { foreach ($this->storeManager->getStores() as $store) { $ids[] = $store->getId(); } } return in_array($storeId, $ids); }
/** * Delete all product flat tables for not existing stores * * @return void */ public function deleteAbandonedStoreFlatTables() { $connection = $this->_resource->getConnection('write'); $existentTables = $connection->getTables($connection->getTableName('catalog_product_flat_%')); $this->_changelog->setViewId('catalog_product_flat'); foreach ($existentTables as $key => $tableName) { if ($this->_changelog->getName() == $tableName) { unset($existentTables[$key]); } } $actualStoreTables = array(); foreach ($this->_storeManager->getStores() as $store) { $actualStoreTables[] = $this->getFlatTableName($store->getId()); } $tablesToDelete = array_diff($existentTables, $actualStoreTables); foreach ($tablesToDelete as $table) { $connection->dropTable($table); } }
/** * Retrieve Select For Flat Attribute update * * @param int $store * @return \Magento\Framework\DB\Select */ public function getFlatUpdateSelect($store = null) { if ($store === null) { foreach ($this->_storeManager->getStores() as $store) { $this->getFlatUpdateSelect($store->getId()); } return $this; } if ($this->getBackendType() == self::TYPE_STATIC) { return null; } if ($this->usesSource()) { return $this->getSource()->getFlatUpdateSelect($store); } return $this->_getResource()->getFlatUpdateSelect($this, $store); }
/** * Initialize stores hash. * * @return $this */ protected function _initStores() { foreach ($this->_storeManager->getStores() as $store) { $this->_storeCodeToId[$store->getCode()] = $store->getId(); $this->_storeIdToWebsiteStoreIds[$store->getId()] = $store->getWebsite()->getStoreIds(); } return $this; }
/** * {@inheritdoc} */ public function getScopes() { return $this->_storeManager->getStores(); }
/** * Get active store by code * * @param StoreManagerInterface $storage * @param string $scopeCode * @return bool|Store */ protected function getActiveStoreByCode(\Magento\Framework\StoreManagerInterface $storage, $scopeCode) { $stores = $storage->getStores(true, true); if ($scopeCode && isset($stores[$scopeCode]) && $stores[$scopeCode]->getId() && $stores[$scopeCode]->getIsActive()) { return $stores[$scopeCode]; } return false; }