private function saveCfgForRussian($path, $value) { $entity = Cfg::ENTITY_MAGE_CORE_CONFIG_DATA; $stoerViewId = $this->storeRussianRu->getId(); $bind = [Cfg::E_CONFIG_A_SCOPE => Cfg::SCOPE_CFG_STORES, Cfg::E_CONFIG_A_SCOPE_ID => $stoerViewId, Cfg::E_CONFIG_A_PATH => $path, Cfg::E_CONFIG_A_VALUE => $value]; $this->repoGeneric->replaceEntity($entity, $bind); }
/** * @inheritdoc */ protected function getCollection(Store $store) { /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $collection */ $collection = $this->_orderCollectionFactory->create(); $collection->addAttributeToFilter('store_id', ['eq' => $store->getId()]); return $collection; }
/** * Get logo image * * @param \Magento\Store\Model\Store $store * @return string|null */ public function getLogoImage($store) { $image = null; if (null !== $store) { $image = basename($this->_scopeConfig->getValue('design/header/logo_src', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store->getId())); } return $image; }
/** * Set redirect url for store view based on request path info * * @param \Magento\Store\Block\Switcher $switcher * @param \Magento\Store\Model\Store $store * @param array $data * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeGetTargetStorePostData(\Magento\Store\Block\Switcher $switcher, \Magento\Store\Model\Store $store, $data = []) { $urlRewrite = $this->urlFinder->findOneByData([UrlRewrite::TARGET_PATH => $this->trimSlashInPath($this->request->getPathInfo()), UrlRewrite::STORE_ID => $store->getId()]); if ($urlRewrite) { $data[ActionInterface::PARAM_NAME_URL_ENCODED] = $this->urlHelper->getEncodedUrl($this->trimSlashInPath($this->urlBuilder->getUrl($urlRewrite->getRequestPath()))); } return [$store, $data]; }
/** * @param \Magento\Store\Model\Store $store * @return void */ private function clearIndex(\Magento\Store\Model\Store $store) { $dimensions = [$this->dimensionFactory->create(['name' => 'scope', 'value' => $store->getId()])]; $configData = $this->indexerConfig->getIndexer(FulltextIndexer::INDEXER_ID); /** @var \Magento\CatalogSearch\Model\Indexer\IndexerHandler $indexHandler */ $indexHandler = $this->indexerHandlerFactory->create(['data' => $configData]); $indexHandler->cleanIndex($dimensions); }
/** * Invalidate design config grid indexer on store creation * * @param StoreStore $subject * @param \Closure $proceed * @return StoreStore * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundSave(StoreStore $subject, \Closure $proceed) { $isObjectNew = $subject->getId() == 0; $result = $proceed(); if ($isObjectNew) { $this->indexerRegistry->get(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->invalidate(); } return $result; }
/** * @inheritdoc */ protected function getCollection(Store $store) { /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ $collection = $this->_productCollectionFactory->create(); $collection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); $collection->addAttributeToFilter('status', ['eq' => '1']); $collection->addStoreFilter($store->getId()); return $collection; }
/** * Retrieve layout updates by handle * * @param string $handle * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param \Magento\Store\Model\Store $store * @return string */ public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Store\Model\Store $store) { $bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()]; $result = ''; $readAdapter = $this->_getReadAdapter(); if ($readAdapter) { $select = $this->_getFetchUpdatesByHandleSelect(); $result = join('', $readAdapter->fetchCol($select, $bind)); } return $result; }
/** * Retrieve request_path using id_path and current store's id. * * @param string $idPath * @param int|\Magento\Store\Model\Store $store * @return string */ public function getRequestPathByIdPath($idPath, $store) { if ($store instanceof \Magento\Store\Model\Store) { $storeId = (int) $store->getId(); } else { $storeId = (int) $store; } $select = $this->_getReadAdapter()->select(); /** @var $select \Magento\Framework\DB\Select */ $select->from(array('main_table' => $this->getMainTable()), 'request_path')->where('main_table.store_id = :store_id')->where('main_table.id_path = :id_path')->limit(1); $bind = array('store_id' => $storeId, 'id_path' => $idPath); return $this->_getReadAdapter()->fetchOne($select, $bind); }
/** * @param \Magento\Store\Model\Store $store * @return \Magento\Store\Api\Data\StoreConfigInterface */ protected function getStoreConfig($store) { /** @var \Magento\Store\Model\Data\StoreConfig $storeConfig */ $storeConfig = $this->storeConfigFactory->create(); $storeConfig->setId($store->getId())->setCode($store->getCode())->setWebsiteId($store->getWebsiteId()); foreach ($this->configPaths as $methodName => $configPath) { $configValue = $this->scopeConfig->getValue($configPath, \Magento\Store\Model\ScopeInterface::SCOPE_STORES, $store->getCode()); $storeConfig->{$methodName}($configValue); } $storeConfig->setBaseUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, false)); $storeConfig->setSecureBaseUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true)); $storeConfig->setBaseLinkUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, false)); $storeConfig->setSecureBaseLinkUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true)); $storeConfig->setBaseStaticUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC, false)); $storeConfig->setSecureBaseStaticUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_STATIC, true)); $storeConfig->setBaseMediaUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA, false)); $storeConfig->setSecureBaseMediaUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA, true)); return $storeConfig; }
/** * Add store filter to collection * @param array|int|\Magento\Store\Model\Store $store * @param boolean $withAdmin * @return $this */ public function addStoreFilter($store, $withAdmin = true) { if ($store === null) { return $this; } if (!$this->getFlag('store_filter_added')) { if ($store instanceof \Magento\Store\Model\Store) { $this->_storeId = $store->getId(); $store = [$store->getId()]; } if (!is_array($store)) { $this->_storeId = $store; $store = [$store]; } if (in_array(\Magento\Store\Model\Store::DEFAULT_STORE_ID, $store)) { return $this; } if ($withAdmin) { $store[] = \Magento\Store\Model\Store::DEFAULT_STORE_ID; } $this->addFilter('store', ['in' => $store], 'public'); } return $this; }
/** * {@inheritdoc} */ public function getId() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getId'); if (!$pluginInfo) { return parent::getId(); } else { return $this->___callPlugins('getId', func_get_args(), $pluginInfo); } }
/** * Get HTML of store chooser * * @param \Magento\Store\Model\Store $storeTo * @return string */ public function getChooseFromStoreHtml($storeTo) { if (!$this->_storeFromHtml) { $this->_storeFromHtml = '<select ' . 'class="admin__control-select" ' . 'name="copy_to_stores[__store_identifier__]" ' . 'disabled="disabled">'; $this->_storeFromHtml .= '<option value="0">' . __('Default Values') . '</option>'; foreach ($this->getWebsiteCollection() as $_website) { if (!$this->hasWebsite($_website->getId())) { continue; } $optGroupLabel = $this->escapeHtml($_website->getName()); $this->_storeFromHtml .= '<optgroup label="' . $optGroupLabel . '"></optgroup>'; foreach ($this->getGroupCollection($_website) as $_group) { $optGroupName = $this->escapeHtml($_group->getName()); $this->_storeFromHtml .= '<optgroup label=" ' . $optGroupName . '">'; foreach ($this->getStoreCollection($_group) as $_store) { $this->_storeFromHtml .= '<option value="' . $_store->getId() . '"> '; $this->_storeFromHtml .= $this->escapeHtml($_store->getName()) . '</option>'; } } $this->_storeFromHtml .= '</optgroup>'; } $this->_storeFromHtml .= '</select>'; } return str_replace('__store_identifier__', $storeTo->getId(), $this->_storeFromHtml); }
/** * Return index table name * * @param \Magento\Store\Model\Store $store * @param bool $useTempTable * @return string */ protected function getTableNameByStore(\Magento\Store\Model\Store $store, $useTempTable) { $tableName = $this->getMainStoreTable($store->getId()); return $useTempTable ? $this->addTemporaryTableSuffix($tableName) : $tableName; }
/** * @param \Magento\Store\Model\Store $store * @return bool */ public function isStoreSelected(\Magento\Store\Model\Store $store) { return $this->getStoreId() !== null && (int) $this->getStoreId() === (int) $store->getId(); }
/** * Loads default store view and returns its id * * @return int */ public function getStoreId() { $this->loadStore(); return $this->store->getId(); }
/** * Get select for all products * * @param \Magento\Store\Model\Store $store * @return \Magento\Framework\DB\Select */ protected function getAllProducts(\Magento\Store\Model\Store $store) { if (!isset($this->productsSelects[$store->getId()])) { $statusAttributeId = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId(); $visibilityAttributeId = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'visibility')->getId(); $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $linkField = $metadata->getLinkField(); $select = $this->connection->select()->from(['cp' => $this->getTable('catalog_product_entity')], [])->joinInner(['cpw' => $this->getTable('catalog_product_website')], 'cpw.product_id = cp.entity_id', [])->joinInner(['cpsd' => $this->getTable('catalog_product_entity_int')], 'cpsd.' . $linkField . ' = cp.' . $linkField . ' AND cpsd.store_id = 0' . ' AND cpsd.attribute_id = ' . $statusAttributeId, [])->joinLeft(['cpss' => $this->getTable('catalog_product_entity_int')], 'cpss.' . $linkField . ' = cp.' . $linkField . ' AND cpss.attribute_id = cpsd.attribute_id' . ' AND cpss.store_id = ' . $store->getId(), [])->joinInner(['cpvd' => $this->getTable('catalog_product_entity_int')], 'cpvd.' . $linkField . ' = cp.' . $linkField . ' AND cpvd.store_id = 0' . ' AND cpvd.attribute_id = ' . $visibilityAttributeId, [])->joinLeft(['cpvs' => $this->getTable('catalog_product_entity_int')], 'cpvs.' . $linkField . ' = cp.' . $linkField . ' AND cpvs.attribute_id = cpvd.attribute_id ' . ' AND cpvs.store_id = ' . $store->getId(), [])->joinLeft(['ccp' => $this->getTable('catalog_category_product')], 'ccp.product_id = cp.entity_id', [])->where('cpw.website_id = ?', $store->getWebsiteId())->where($this->connection->getIfNullSql('cpss.value', 'cpsd.value') . ' = ?', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->where($this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)', [\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH])->group('cp.entity_id')->columns(['category_id' => new \Zend_Db_Expr($store->getRootCategoryId()), 'product_id' => 'cp.entity_id', 'position' => new \Zend_Db_Expr($this->connection->getCheckSql('ccp.product_id IS NOT NULL', 'ccp.position', '0')), 'is_parent' => new \Zend_Db_Expr($this->connection->getCheckSql('ccp.product_id IS NOT NULL', '1', '0')), 'store_id' => new \Zend_Db_Expr($store->getId()), 'visibility' => new \Zend_Db_Expr($this->connection->getIfNullSql('cpvs.value', 'cpvd.value'))]); $this->productsSelects[$store->getId()] = $select; } return $this->productsSelects[$store->getId()]; }
/** * @param $loadId * @param $expectedId * @dataProvider loadDataProvider */ public function testLoad($loadId, $expectedId) { $this->model->load($loadId); $this->assertEquals($expectedId, $this->model->getId()); }
/** * Check whether we need to create new customer (for another website) during order creation * * @param \Magento\Store\Model\Store $store * @return bool */ protected function _customerIsInStore($store) { $customerId = (int) $this->getSession()->getCustomerId(); $customerData = $this->_customerAccountService->getCustomer($customerId); return $customerData->getWebsiteId() == $store->getWebsiteId() || $this->_customerAccountService->isCustomerInStore($customerData->getWebsiteId(), $store->getId()); }
/** * Retrieve cache identifier taking into account current area/package/theme/store * * @param string $suffix * @return string */ protected function _getCacheId($suffix = '') { return "LAYOUT_{$this->_theme->getArea()}_STORE{$this->_store->getId()}_{$this->_theme->getId()}{$suffix}"; }
/** * Declare quote store model * * @param \Magento\Store\Model\Store $store * @return $this */ public function setStore(\Magento\Store\Model\Store $store) { $this->setStoreId($store->getId()); return $this; }
/** * Prepare group id field in the fieldset * * @param \Magento\Framework\Data\Form $form * @param \Magento\Store\Model\Store $storeModel * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset * @return \Magento\Framework\Data\Form\Element\Fieldset */ private function prepareGroupIdField(\Magento\Framework\Data\Form $form, \Magento\Store\Model\Store $storeModel, \Magento\Framework\Data\Form\Element\Fieldset $fieldset) { if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) { if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) { $form->getElement('store_group_id')->setDisabled(true); $fieldset->addField('store_hidden_group_id', 'hidden', ['name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]); } else { $fieldset->addField('store_original_group_id', 'hidden', ['name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]); } } return $fieldset; }
/** * Gets the absolute preview URL to a given store's product page. * The product is the first one found in the database for the store. * The preview url includes "nostodebug=true" parameter. * * @param Store $store the store to get the url for. * * @return string the url. */ public function getPreviewUrlProduct(Store $store) { /** @noinspection PhpUndefinedNamespaceInspection */ /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection = $this->_productCollectionFactory->create(); $collection->addStoreFilter($store->getId()); $collection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); $collection->addAttributeToFilter('status', ['eq' => '1']); $collection->setCurPage(1); $collection->setPageSize(1); $collection->load(); $url = ''; foreach ($collection->getItems() as $product) { /** @var \Magento\Catalog\Model\Product $product */ $url = $product->getUrlInStore(['_nosid' => true, '_scope_to_url' => true, '_scope' => $store->getCode()]); $url = $this->addNostoDebugParamToUrl($url); } return $url; }
/** * Check whether we need to create new customer (for another website) during order creation * * @param \Magento\Store\Model\Store $store * @return bool */ protected function _customerIsInStore($store) { $customerId = (int) $this->getSession()->getCustomerId(); $customer = $this->customerRepository->getById($customerId); return $customer->getWebsiteId() == $store->getWebsiteId() || $this->accountManagement->isCustomerInStore($customer->getWebsiteId(), $store->getId()); }
/** * Removes an account with associated api tokens for the store. * * @param \NostoAccount $account the account to remove. * @param Store $store the store. * * @return bool true on success, false otherwise. */ public function deleteAccount(\NostoAccount $account, Store $store) { if ((int) $store->getId() < 1) { return false; } $this->_config->delete(self::XML_PATH_ACCOUNT, ScopeInterface::SCOPE_STORES, $store->getId()); $this->_config->delete(self::XML_PATH_TOKENS, ScopeInterface::SCOPE_STORES, $store->getId()); try { // Notify Nosto that the account was deleted. $service = new \NostoServiceAccount(); $service->delete($account); } catch (\NostoException $e) { // Failures are logged but not shown to the user. $this->_logger->error($e, ['exception' => $e]); } $store->resetConfig(); return true; }
/** * @param \Magento\Store\Model\Group $subject * @param \Magento\Store\Model\Store $store * @return \Magento\Store\Model\Store */ public function afterGetDefaultStore(Group $subject, Store $store) { if ($this->generalConfig->isAvailable() && $this->storeSwitcher->isInitialized()) { $storeId = $this->storeSwitcher->getStoreId(); if ($store->getId() != $storeId && in_array($storeId, $subject->getStoreIds())) { $store = $this->storeRepository->getById($storeId); } } return $store; }