/** * Prepare component configuration * * @return void */ public function prepare() { parent::prepare(); if ($this->storeManager->isSingleStoreMode()) { $this->_data['config']['componentDisabled'] = true; } }
/** * Retrieve configuration metadata * * @return array */ public function getData() { $scope = $this->request->getParam('scope'); $scopeId = $this->request->getParam('scope_id'); $data = []; if ($scope) { $showFallbackReset = false; list($fallbackScope, $fallbackScopeId) = $this->scopeFallbackResolver->getFallbackScope($scope, $scopeId); if ($fallbackScope && !$this->storeManager->isSingleStoreMode()) { $scope = $fallbackScope; $scopeId = $fallbackScopeId; $showFallbackReset = true; } $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId); $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData(); foreach ($fieldsData as $fieldData) { $element =& $data; foreach (explode('/', $fieldData->getFieldConfig()['fieldset']) as $fieldset) { if (!isset($element[$fieldset]['children'])) { $element[$fieldset]['children'] = []; } $element =& $element[$fieldset]['children']; } $fieldName = $fieldData->getFieldConfig()['field']; $element[$fieldName]['arguments']['data']['config']['default'] = $fieldData->getValue(); $element[$fieldName]['arguments']['data']['config']['showFallbackReset'] = $showFallbackReset; } } return $data; }
/** * Set store ids to run the upgrade on * * @return $this */ public function setStoreIds(array $ids) { if ($this->storeManager->isSingleStoreMode()) { $ids = [\Magento\Store\Model\Store::DEFAULT_STORE_ID]; } $this->storeIds = $ids; return $this; }
/** * {@inheritdoc} */ protected function _prepareColumns() { $this->addColumn('term', ['header' => __('Stopword'), 'type' => 'text', 'index' => 'term']); if (!$this->storeManager->isSingleStoreMode()) { $this->addColumn('store_id', ['header' => __('Store'), 'type' => 'store', 'index' => 'store_id']); } return parent::_prepareColumns(); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function modifyMeta(array $meta) { $samplesPath = Composite::CHILDREN_PATH . '/' . Composite::CONTAINER_SAMPLES; $samplesContainer['arguments']['data']['config'] = ['additionalClasses' => 'admin__fieldset-section', 'componentType' => Form\Fieldset::NAME, 'label' => __('Samples'), 'dataScope' => '', 'visible' => $this->locator->getProduct()->getTypeId() === Type::TYPE_DOWNLOADABLE, 'sortOrder' => 40]; $samplesTitle['arguments']['data']['config'] = ['componentType' => Form\Field::NAME, 'formElement' => Form\Element\Input::NAME, 'dataType' => Form\Element\DataType\Text::NAME, 'label' => __('Title'), 'dataScope' => 'product.samples_title', 'scopeLabel' => $this->storeManager->isSingleStoreMode() ? '' : '[STORE VIEW]']; // @codingStandardsIgnoreStart $informationSamples['arguments']['data']['config'] = ['componentType' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/html', 'additionalClasses' => 'admin__fieldset-note', 'content' => __('Alphanumeric, dash and underscore characters are recommended for filenames. Improper characters are replaced with \'_\'.')]; // @codingStandardsIgnoreEnd $samplesContainer = $this->arrayManager->set('children', $samplesContainer, ['samples_title' => $samplesTitle, 'sample' => $this->getDynamicRows(), 'information_samples' => $informationSamples]); return $this->arrayManager->set($samplesPath, $meta, $samplesContainer); }
/** * Check a configuration element visibility * * @param \Magento\Config\Model\Config\Structure\AbstractElement $element The config composite element * @param string $scope The element scope * * @return bool */ public function isVisible(\Magento\Config\Model\Config\Structure\AbstractElement $element, $scope) { if ($element->getAttribute('if_module_enabled') && !$this->moduleManager->isOutputEnabled($element->getAttribute('if_module_enabled'))) { return false; } $showInScope = [ContainerScopeInterface::SCOPE_DEFAULT => $element->getAttribute('showInDefault'), ContainerScopeInterface::SCOPE_CONTAINERS => $element->getAttribute('showInContainer'), ContainerScopeInterface::SCOPE_STORE_CONTAINERS => $element->getAttribute('showInStore')]; if ($this->storeManager->isSingleStoreMode()) { $result = !$element->getAttribute('hide_in_single_store_mode') && array_sum($showInScope); return $result; } return !empty($showInScope[$scope]); }
/** * Get data * * @return array */ public function getData() { if ($this->storeManager->isSingleStoreMode()) { $websites = $this->storeManager->getWebsites(); $singleStoreWebsite = array_shift($websites); $this->addFilter($this->filterBuilder->setField('store_website_id')->setValue($singleStoreWebsite->getId())->create()); $this->addFilter($this->filterBuilder->setField('store_group_id')->setConditionType('null')->create()); } $data = parent::getData(); foreach ($data['items'] as &$item) { $item += ['default' => __('Global')]; } return $data; }
/** * Assign theme to the stores * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param array $stores * @param string $scope * @return $this */ public function assignToStore($theme, array $stores = [], $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES) { $isReassigned = false; $this->_unassignThemeFromStores($theme->getId(), $stores, $scope, $isReassigned); if ($this->_storeManager->isSingleStoreMode()) { $this->_assignThemeToDefaultScope($theme->getId(), $isReassigned); } else { $this->_assignThemeToStores($theme->getId(), $stores, $scope, $isReassigned); } if ($isReassigned) { $this->_configCache->clean(); $this->_layoutCache->clean(); } $this->_eventManager->dispatch('assign_theme_to_stores_after', ['stores' => $stores, 'scope' => $scope, 'theme' => $theme]); return $this; }
/** * {@inheritdoc} */ public function modifyMeta(array $meta) { if (!$this->storeManager->isSingleStoreMode()) { $meta = array_replace_recursive($meta, ['websites' => ['arguments' => ['data' => ['config' => ['additionalClasses' => 'admin__fieldset-product-websites', 'label' => __('Product in Websites'), 'collapsible' => true, 'componentType' => Form\Fieldset::NAME, 'dataScope' => self::DATA_SCOPE_PRODUCT, 'sortOrder' => $this->getNextGroupSortOrder($meta, 'search-engine-optimization', self::SORT_ORDER)]]], 'children' => $this->getFieldsForFieldset()]]); } return $meta; }
/** * {@inheritdoc} */ protected function _prepareForm() { $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]); $fieldset = $form->addFieldset('base_fieldset', []); $fieldset->addField('file', 'select', ['name' => 'file', 'label' => __('Dictionary'), 'required' => true, 'values' => $this->getFiles()]); if (!$this->storeManager->isSingleStoreMode()) { $field = $fieldset->addField('store_id', 'select', ['label' => __('Store'), 'title' => __('Store'), 'values' => $this->systemStore->getStoreValuesForForm(), 'name' => 'store_id', 'required' => true]); $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'); $field->setRenderer($renderer); } else { $fieldset->addField('store_id', 'hidden', ['name' => 'store_id', 'value' => $this->storeManager->getStore(true)->getId()]); } $form->setAction($this->getUrl('*/*/doImport')); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); }
/** * Check whether element should be displayed * * @return bool */ public function isVisible() { $showInScope = [\Magento\Store\Model\ScopeInterface::SCOPE_STORE => $this->_hasVisibilityValue('showInStore'), \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE => $this->_hasVisibilityValue('showInWebsite'), \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT => $this->_hasVisibilityValue('showInDefault')]; if ($this->_storeManager->isSingleStoreMode()) { $result = !$this->_hasVisibilityValue('hide_in_single_store_mode') && array_sum($showInScope); return $result; } return !empty($showInScope[$this->_scope]); }
/** * Returns the currently selected store. * If it is single store setup, then just return the default store. * If it is a multi store setup, the expect a store id to passed in the * request params and return that store as the current one. * * @return Store|null the store or null if not found. */ protected function getSelectedStore() { if ($this->_storeManager->isSingleStoreMode()) { return $this->_storeManager->getStore(true); } elseif ($storeId = $this->_storeManager->getStore()->getId()) { return $this->_storeManager->getStore($storeId); } else { return null; } }
/** * Add stores data to collection * * @return $this */ public function addStoreData() { if (!$this->_storeManager->isSingleStoreMode()) { if (!$this->_isCollectionLoaded) { $this->_addStoreDataFlag = true; } elseif (!$this->_addStoreDataFlag) { $this->_addStoreData(); } } return $this; }
/** * Retrieve correct scope corresponding single store mode configuration * * @param string $scope * @param string $scopeId * @return array */ protected function getCorrectScope($scope, $scopeId) { $isSingleStoreMode = $this->storeManager->isSingleStoreMode(); if ($isSingleStoreMode) { $websites = $this->storeManager->getWebsites(); $singleStoreWebsite = array_shift($websites); $scope = ScopeInterface::SCOPE_WEBSITES; $scopeId = $singleStoreWebsite->getId(); } return ['scope' => $scope, 'scopeId' => $scopeId]; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function modifyMeta(array $meta) { $linksPath = Composite::CHILDREN_PATH . '/' . Composite::CONTAINER_LINKS; $linksContainer['arguments']['data']['config'] = ['componentType' => Form\Fieldset::NAME, 'additionalClasses' => 'admin__fieldset-section', 'label' => __('Links'), 'dataScope' => '', 'visible' => $this->locator->getProduct()->getTypeId() === Type::TYPE_DOWNLOADABLE, 'sortOrder' => 30]; $linksTitle['arguments']['data']['config'] = ['componentType' => Form\Field::NAME, 'formElement' => Form\Element\Input::NAME, 'dataType' => Form\Element\DataType\Text::NAME, 'label' => __('Title'), 'dataScope' => 'product.links_title', 'scopeLabel' => $this->storeManager->isSingleStoreMode() ? '' : '[STORE VIEW]']; $linksPurchasedSeparately['arguments']['data']['config'] = ['componentType' => Form\Field::NAME, 'formElement' => Form\Element\Checkbox::NAME, 'dataType' => Form\Element\DataType\Number::NAME, 'description' => __('Links can be purchased separately'), 'label' => ' ', 'dataScope' => 'product.links_purchased_separately', 'scopeLabel' => $this->storeManager->isSingleStoreMode() ? '' : '[GLOBAL]', 'valueMap' => ['false' => '0', 'true' => '1']]; // @codingStandardsIgnoreStart $informationLinks['arguments']['data']['config'] = ['componentType' => Container::NAME, 'component' => 'Magento_Ui/js/form/components/html', 'additionalClasses' => 'admin__fieldset-note', 'content' => __('Alphanumeric, dash and underscore characters are recommended for filenames. Improper characters are replaced with \'_\'.')]; // @codingStandardsIgnoreEnd $linksContainer = $this->arrayManager->set('children', $linksContainer, ['links_title' => $linksTitle, 'links_purchased_separately' => $linksPurchasedSeparately, 'link' => $this->getDynamicRows(), 'information_links' => $informationLinks]); return $this->arrayManager->set($linksPath, $meta, $linksContainer); }
/** * Check whether element should be displayed * * @return bool */ public function isVisible() { if (isset($this->_data['if_module_enabled']) && !$this->moduleManager->isOutputEnabled($this->_data['if_module_enabled'])) { return false; } $showInScope = [\Magento\Store\Model\ScopeInterface::SCOPE_STORE => $this->_hasVisibilityValue('showInStore'), \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE => $this->_hasVisibilityValue('showInWebsite'), ScopeConfigInterface::SCOPE_TYPE_DEFAULT => $this->_hasVisibilityValue('showInDefault')]; if ($this->_storeManager->isSingleStoreMode()) { $result = !$this->_hasVisibilityValue('hide_in_single_store_mode') && array_sum($showInScope); return $result; } return !empty($showInScope[$this->_scope]); }
/** * {@inheritdoc} */ protected function _prepareForm() { $model = $this->registry->registry('current_model'); $form = $this->formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]); $fieldset = $form->addFieldset('base_fieldset', []); if ($model->getId()) { $fieldset->addField('synonym_id', 'hidden', ['name' => 'id']); } $fieldset->addField('term', 'text', ['name' => 'term', 'label' => __('Term'), 'required' => true]); $fieldset->addField('synonyms', 'textarea', ['name' => 'synonyms', 'label' => __('Synonyms'), 'required' => true, 'note' => __('Use comma as separator')]); if (!$this->storeManager->isSingleStoreMode()) { $field = $fieldset->addField('store_id', 'select', ['label' => __('Store'), 'title' => __('Store'), 'values' => $this->systemStore->getStoreValuesForForm(), 'name' => 'store_id', 'required' => true]); $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'); $field->setRenderer($renderer); } else { $fieldset->addField('store_id', 'hidden', ['name' => 'store_id', 'value' => $this->storeManager->getStore(true)->getId()]); } $form->setValues($model->getData()); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); }
/** * Retrieve scope label * * @param ProductAttributeInterface $attribute * @return \Magento\Framework\Phrase|string */ private function getScopeLabel(ProductAttributeInterface $attribute) { if ($this->storeManager->isSingleStoreMode() || $attribute->getFrontendInput() === AttributeInterface::FRONTEND_INPUT) { return ''; } switch ($attribute->getScope()) { case ProductAttributeInterface::SCOPE_GLOBAL_TEXT: return __('[GLOBAL]'); case ProductAttributeInterface::SCOPE_WEBSITE_TEXT: return __('[WEBSITE]'); case ProductAttributeInterface::SCOPE_STORE_TEXT: return __('[STORE VIEW]'); } return ''; }
/** * Retrieve label of attribute scope * * GLOBAL | WEBSITE | STORE * * @param EavAttribute $attribute * @return string */ public function getScopeLabel(EavAttribute $attribute) { $html = ''; if (!$attribute || $this->storeManager->isSingleStoreMode() || $attribute->getFrontendInput() === AttributeInterface::FRONTEND_INPUT) { return $html; } if ($attribute->isScopeGlobal()) { $html .= __('[GLOBAL]'); } elseif ($attribute->isScopeWebsite()) { $html .= __('[WEBSITE]'); } elseif ($attribute->isScopeStore()) { $html .= __('[STORE VIEW]'); } return $html; }
/** * Get default theme which declared in configuration * * Write default theme to core_config_data * * @param string|null $area * @param array $params * @return string|int */ public function getConfigurationDesignTheme($area = null, array $params = array()) { if (!$area) { $area = $this->getArea(); } $theme = null; $store = isset($params['store']) ? $params['store'] : null; if ($this->_isThemePerStoveView($area)) { $theme = $this->_storeManager->isSingleStoreMode() ? $this->_scopeConfig->getValue(self::XML_PATH_THEME_ID, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) : (string) $this->_scopeConfig->getValue(self::XML_PATH_THEME_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); } if (!$theme && isset($this->_themes[$area])) { $theme = $this->_themes[$area]; } return $theme; }
/** * Set correct scope if isSingleStoreMode = true * * @param \Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig * @param \Magento\Framework\App\Config\ValueInterface $dataObject * @return void */ protected function _checkSingleStoreMode(\Magento\Backend\Model\Config\Structure\Element\Field $fieldConfig, $dataObject) { $isSingleStoreMode = $this->_storeManager->isSingleStoreMode(); if (!$isSingleStoreMode) { return; } if (!$fieldConfig->showInDefault()) { $websites = $this->_storeManager->getWebsites(); $singleStoreWebsite = array_shift($websites); $dataObject->setScope('websites'); $dataObject->setWebsiteCode($singleStoreWebsite->getCode()); $dataObject->setScopeCode($singleStoreWebsite->getCode()); $dataObject->setScopeId($singleStoreWebsite->getId()); } }
/** * Retrieve label of attribute scope * * GLOBAL | WEBSITE | STORE * * @param Attribute $attribute * @return string */ public function getScopeLabel($attribute) { $html = ''; if ($this->_storeManager->isSingleStoreMode()) { return $html; } if ($attribute->isScopeGlobal()) { $html .= '<br/>' . __('[GLOBAL]'); } elseif ($attribute->isScopeWebsite()) { $html .= '<br/>' . __('[WEBSITE]'); } elseif ($attribute->isScopeStore()) { $html .= '<br/>' . __('[STORE VIEW]'); } return $html; }
/** * Get default theme which declared in configuration * * Write default theme to core_config_data * * @param string|null $area * @param array $params * @return string|int */ public function getConfigurationDesignTheme($area = null, array $params = []) { if (!$area) { $area = $this->getArea(); } $theme = null; $store = isset($params['store']) ? $params['store'] : null; if ($this->_isThemePerStoreView($area)) { if ($this->_storeManager->isSingleStoreMode()) { $theme = $this->_scopeConfig->getValue(self::XML_PATH_THEME_ID, ScopeInterface::SCOPE_WEBSITES); } else { $theme = (string) $this->_scopeConfig->getValue(self::XML_PATH_THEME_ID, ScopeInterface::SCOPE_STORE, $store); } } if (!$theme && isset($this->_themes[$area])) { $theme = $this->_themes[$area]; } return $theme; }
/** * Add rating info to select * * @param int $storeId * @return $this */ public function addRatingInfo($storeId = null) { $connection = $this->getConnection(); $ratingCodeCond = $connection->getIfNullSql('title.value', 'rating.rating_code'); $this->getSelect()->join(['rating' => $this->getTable('rating')], 'rating.rating_id = main_table.rating_id', ['rating_code'])->joinLeft(['title' => $this->getTable('rating_title')], $connection->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?', (int) $this->_storeManager->getStore()->getId()), ['rating_code' => $ratingCodeCond]); if (!$this->_storeManager->isSingleStoreMode()) { if ($storeId == null) { $storeId = $this->_storeManager->getStore()->getId(); } if (is_array($storeId)) { $condition = $connection->prepareSqlCondition('store.store_id', ['in' => $storeId]); } else { $condition = $connection->quoteInto('store.store_id = ?', $storeId); } $this->getSelect()->join(['store' => $this->getTable('rating_store')], 'main_table.rating_id = store.rating_id AND ' . $condition); } $connection->fetchAll($this->getSelect()); return $this; }
/** * Review summary * * @param \Magento\Review\Model\Rating $object * @param boolean $onlyForCurrentStore * @return array */ public function getReviewSummary($object, $onlyForCurrentStore = true) { $adapter = $this->_getReadAdapter(); $sumColumn = new \Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})"); $countColumn = new \Zend_Db_Expr('COUNT(*)'); $select = $adapter->select()->from(['rating_vote' => $this->getTable('rating_option_vote')], ['sum' => $sumColumn, 'count' => $countColumn])->joinLeft(['review_store' => $this->getTable('review_store')], 'rating_vote.review_id = review_store.review_id', ['review_store.store_id']); if (!$this->_storeManager->isSingleStoreMode()) { $select->join(['rating_store' => $this->getTable('rating_store')], 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', []); } $select->where('rating_vote.review_id = :review_id')->group('rating_vote.review_id')->group('review_store.store_id'); $data = $adapter->fetchAll($select, [':review_id' => $object->getReviewId()]); if ($onlyForCurrentStore) { foreach ($data as $row) { if ($row['store_id'] == $this->_storeManager->getStore()->getId()) { $object->addData($row); } } return $object; } $result = []; $stores = $this->_storeManager->getStore()->getResourceCollection()->load(); 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); }
/** * Show website column and switcher for group price table * * @return bool */ protected function isMultiWebsites() { return !$this->storeManager->isSingleStoreMode(); }
/** * Check if Single Store Mode is enabled * * @return bool */ public function isSingleStoreMode() { return $this->_storeManager->isSingleStoreMode(); }
/** * Prepare component configuration * @return void */ public function prepare() { if (!$this->storeManager->isSingleStoreMode()) { parent::prepare(); } }