/** * 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()); } }
/** * Perform operations after collection load * * @param string $tableName * @param string $columnName * @return void */ protected function performAfterLoad($tableName, $columnName) { $items = $this->getColumnValues($columnName); if (count($items)) { $connection = $this->getConnection(); $select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)])->where('cms_entity_store.' . $columnName . ' IN (?)', $items); $result = $connection->fetchPairs($select); if ($result) { foreach ($this as $item) { $entityId = $item->getData($columnName); if (!isset($result[$entityId])) { continue; } if ($result[$entityId] == 0) { $stores = $this->storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getData($columnName)]; $storeCode = $this->storeManager->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); $item->setData('store_id', [$result[$entityId]]); } } } }
/** * Perform operations after collection load * * @param string $tableName * @param string|null $linkField * @return void */ protected function performAfterLoad($tableName, $linkField) { $linkedIds = $this->getColumnValues($linkField); if (count($linkedIds)) { $connection = $this->getConnection(); $select = $connection->select()->from(['cms_entity_store' => $this->getTable($tableName)])->where('cms_entity_store.' . $linkField . ' IN (?)', $linkedIds); $result = $connection->fetchAll($select); if ($result) { $storesData = []; foreach ($result as $storeData) { $storesData[$storeData[$linkField]][] = $storeData['store_id']; } foreach ($this as $item) { $linkedId = $item->getData($linkField); if (!isset($storesData[$linkedId])) { continue; } $storeIdKey = array_search(Store::DEFAULT_STORE_ID, $storesData[$linkedId], true); if ($storeIdKey !== false) { $stores = $this->storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = current($storesData[$linkedId]); $storeCode = $this->storeManager->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); $item->setData('store_id', $storesData[$linkedId]); } } } }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int|void */ protected function execute(InputInterface $input, OutputInterface $output) { foreach ($this->storeManager->getStores() as $store) { $table[$store->getId()] = array($store->getId(), $store->getCode()); } ksort($table); $this->getHelper('table')->setHeaders(array('id', 'code'))->renderByFormat($output, $table, $input->getOption('format')); }
/** * {@inheritDoc} */ public function executeFull() { $storeIds = array_keys($this->storeManager->getStores()); foreach ($storeIds as $storeId) { $synonyms = $this->resourceModel->getSynonyms($storeId); $expansions = $this->resourceModel->getExpansions($storeId); $this->indexHandler->reindex($storeId, $synonyms, $expansions); } }
/** * Retrieves a unique list of locales that are used by store views * * @return array */ public function retrieveLocales() { $stores = $this->storeManager->getStores(); $locales = []; /** @var \Magento\Store\Api\Data\StoreInterface $store */ foreach ($stores as $store) { $locales[] = $this->scopeConfig->getValue(Data::XML_PATH_DEFAULT_LOCALE, ScopeInterface::SCOPE_STORE, $store->getCode()); } return $this->removeDuplicates($locales); }
/** * 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 ', ["main_table.tax_calculation_rate_id = {$tableAlias}.tax_calculation_rate_id", $this->getConnection()->quoteInto($tableAlias . '.store_id = ?', $store->getId())]); $this->_select->joinLeft([$tableAlias => $this->getTable('tax_calculation_rate_title')], $joinCondition, [$tableAlias => 'value']); } return $this; }
/** * Generate list of urls per store * * @param int[] $storeIds * @return \Magento\UrlRewrite\Service\V1\Data\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; }
/** * 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 = [$productId]; } if (null === $storeId) { foreach ($this->storeManager->getStores() as $store) { $this->connection->delete($this->productIndexerHelper->getFlatTableName($store->getId()), ['entity_id IN(?)' => $productId]); } } else { $this->connection->delete($this->productIndexerHelper->getFlatTableName((int) $storeId), ['entity_id IN(?)' => $productId]); } }
/** * Return stores grouped by assigned themes * * @return array */ public function getStoresByThemes() { $storesByThemes = []; $stores = $this->_storeManager->getStores(); /** @var $store \Magento\Store\Model\Store */ foreach ($stores as $store) { $themeId = $this->_getConfigurationThemeId($store); if (!isset($storesByThemes[$themeId])) { $storesByThemes[$themeId] = []; } $storesByThemes[$themeId][] = $store; } return $storesByThemes; }
/** * 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; }
/** * Edit category page * * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { $storeId = (int) $this->getRequest()->getParam('store'); $categoryId = (int) $this->getRequest()->getParam('id'); if (!$categoryId) { if ($storeId) { $categoryId = (int) $this->storeManager->getStore($storeId)->getRootCategoryId(); } else { $defaultStoreView = $this->storeManager->getDefaultStoreView(); if ($defaultStoreView) { $categoryId = (int) $defaultStoreView->getRootCategoryId(); } else { $stores = $this->storeManager->getStores(); if (count($stores)) { $store = reset($stores); $categoryId = (int) $store->getRootCategoryId(); } } } $this->getRequest()->setParam('id', $categoryId); } $category = $this->_initCategory(true); if (!$category || $categoryId != $category->getId() || !$category->getId()) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]); } /** * Check if we have data in session (if during category save was exception) */ $data = $this->_getSession()->getCategoryData(true); if (isset($data['general'])) { $category->addData($data['general']); } /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); if ($this->getRequest()->getQuery('isAjax')) { return $this->ajaxRequestResponse($category, $resultPage); } $resultPage->setActiveMenu('Magento_Catalog::catalog_categories'); $resultPage->getConfig()->getTitle()->prepend(__('Categories')); $resultPage->getConfig()->getTitle()->prepend($categoryId ? $category->getName() : __('Categories')); $resultPage->addBreadcrumb(__('Manage Catalog Categories'), __('Manage Categories')); $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { $block->setStoreId($storeId); } return $resultPage; }
/** * 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(); }
/** * 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 * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getSftpCredentials($automaticMode = false) { $configs = []; $uniques = []; 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 = ['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; }
/** * 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; }
/** * Perform operations after collection load * * @return $this */ protected function _afterLoad() { $items = $this->getColumnValues('category_id'); if (count($items)) { $connection = $this->getConnection(); $select = $connection->select()->from(['cps' => $this->getTable('magefan_blog_category_store')])->where('cps.category_id IN (?)', $items); $result = $connection->fetchPairs($select); if ($result) { foreach ($this as $item) { $categoryId = $item->getData('category_id'); if (!isset($result[$categoryId])) { continue; } if ($result[$categoryId] == 0) { $stores = $this->_storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getData('category_id')]; $storeCode = $this->_storeManager->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); $item->setData('store_id', [$result[$categoryId]]); } } } $this->_previewFlag = false; return parent::_afterLoad(); }
/** * Perform operations after collection load * * @return void */ protected function afterLoad() { if ($this->getSearchCriteria()->getPart('first_store_flag')) { $items = $this->searchResultProcessor->getColumnValues($this->linkFieldName); $connection = $this->getQuery()->getConnection(); $resource = $this->getQuery()->getResource(); if (count($items)) { $select = $connection->select()->from(['cps' => $resource->getTable($this->storeTableName)])->where("cps.{$this->linkFieldName} IN (?)", $items); $result = $connection->fetchPairs($select); if ($result) { foreach ($this->getItems() as $item) { /** @var BlockInterface $item */ if (!isset($result[$item->getId()])) { continue; } if ($result[$item->getId()] == 0) { $stores = $this->storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getId()]; $storeCode = $this->storeManager->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); $item->setData('store_id', [$result[$item->getId()]]); } } } } 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 = []; /** @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; }
/** * 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 = []; 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 void */ private function loadStores() { $itemIds = array_keys($this->_items); if (count($itemIds)) { $connection = $this->getConnection(); $select = $connection->select()->from(['thesaurus_entity_store' => $this->getTable(ThesaurusInterface::STORE_TABLE_NAME)])->where('thesaurus_entity_store.' . ThesaurusInterface::THESAURUS_ID . ' IN (?)', $itemIds); $result = $connection->fetchPairs($select); if ($result) { foreach ($this as $item) { $entityId = $item->getData(ThesaurusInterface::THESAURUS_ID); if (!isset($result[$entityId])) { continue; } $storeId = $result[$item->getData(ThesaurusInterface::THESAURUS_ID)]; $storeCode = $this->storeManager->getStore($storeId)->getCode(); if ($result[$entityId] == 0) { $stores = $this->storeManager->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); $item->setData('store_id', [$result[$entityId]]); } } } }
/** * Add products to changes list with price which depends on date * * @return void */ public function execute() { $connection = $this->_getConnection(); 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('H', $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 the entities for the given scope * * @param string $scope Scope * @return \Magento\Store\Api\Data\WebsiteInterface[]|\Magento\Store\Api\Data\StoreInterface[] */ private function getEntityStore($scope) { if (isset($this->entityStore[$scope])) { return $this->entityStore[$scope]; } switch ($scope) { case self::SCOPE_STORES: $this->entityStore[$scope] = $this->storeManager->getStores(true, true); break; case self::SCOPE_WEBSITES: $this->entityStore[$scope] = $this->storeManager->getWebsites(true, true); break; default: throw new ScopeConvertException(sprintf('Unknown scope "%s"', $scope)); } return $this->entityStore[$scope]; }
/** * 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; }
/** * 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; }
/** * Get store views as id => name associative array * * @param bool $withDefault * @param string $attribute * @return array */ public function getStoreOptionHash($withDefault = false, $attribute = 'name') { $options = []; foreach ($this->_storeManager->getStores((bool) $withDefault && $this->_isAdminScopeAllowed) as $store) { $options[$store->getId()] = $store->getDataUsingMethod($attribute); } return $options; }
/** * Execute full indexation * * @return void */ public function executeFull() { $storeIds = array_keys($this->storeManager->getStores()); foreach ($storeIds as $storeId) { $dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]); $this->indexerHandler->cleanIndex([$dimension]); $this->indexerHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId)); } }
public function getAllStores() { $allStores = $this->_storeManager->getStores(); $stores = array(); foreach ($allStores as $_eachStoreId => $val) { $stores[] = $this->_storeManager->getStore($_eachStoreId)->getId(); } return $stores; }
/** * 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; }
public function __construct(StoreManagerInterface $storeManager, ConfigHelper $configHelper, LoggerInterface $logger) { $this->config = $configHelper; $this->enabled = $this->config->isLoggingEnabled(); foreach ($storeManager->getStores() as $store) { $this->stores[$store->getId()] = $store->getName(); } $this->logger = $logger; }
/** * @param ResultCollection $results * @param $checkGroupClass * @param $check */ private function checkStores(ResultCollection $results, $checkGroupClass, $check) { if (!($stores = $this->storeManager->getStores())) { $this->_markCheckWarning($results, 'stores', $checkGroupClass); } foreach ($stores as $store) { $check->check($results, $store); } }