/** * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $this->httpContext->setValue(HttpContext::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode()); $this->httpContext->setValue(StoreManagerInterface::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode()); return $proceed($request); }
/** * Get url for config settings where base url option can be changed * * @return string */ protected function _getConfigUrl() { $output = ''; $defaultUnsecure = $this->_config->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default'); $defaultSecure = $this->_config->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default'); if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER || $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER) { $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web']); } else { /** @var $dataCollection \Magento\Config\Model\Resource\Config\Data\Collection */ $dataCollection = $this->_configValueFactory->create()->getCollection(); $dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER); /** @var $data \Magento\Framework\App\Config\ValueInterface */ foreach ($dataCollection as $data) { if ($data->getScope() == 'stores') { $code = $this->_storeManager->getStore($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web', 'store' => $code]); break; } elseif ($data->getScope() == 'websites') { $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web', 'website' => $code]); break; } } } return $output; }
/** * Execute method. * * @param \Magento\Framework\Event\Observer $observer * * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getEvent()->getOrder(); $email = $order->getCustomerEmail(); $website = $this->storeManager->getWebsite($order->getWebsiteId()); $storeName = $this->storeManager->getStore($order->getStoreId())->getName(); //if api is not enabled if (!$this->helper->isEnabled($website)) { return $this; } //automation enrolment for order if ($order->getCustomerIsGuest()) { // guest to automation mapped $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER'; $automationType = \Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_GUEST_ORDER; } else { // customer to automation mapped $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER'; $automationType = \Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_ORDER; } $programId = $this->helper->getAutomationIdByType($programType, $order->getWebsiteId()); //the program is not mapped if (!$programId) { return $this; } try { $this->automationFactory->create()->setEmail($email)->setAutomationType($automationType)->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)->setTypeId($order->getId())->setWebsiteId($website->getId())->setStoreName($storeName)->setProgramId($programId)->save(); } catch (\Exception $e) { $this->helper->debug((string) $e, []); } return $this; }
/** * @param DesignConfigRepository $subject * @param DesignConfigInterface $designConfig * @return DesignConfigInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDelete(DesignConfigRepository $subject, DesignConfigInterface $designConfig) { $website = in_array($designConfig->getScope(), [ScopeInterface::SCOPE_WEBSITE, ScopeInterface::SCOPE_WEBSITES]) ? $this->storeManager->getWebsite($designConfig->getScopeId()) : ''; $store = in_array($designConfig->getScope(), [ScopeInterface::SCOPE_STORE, ScopeInterface::SCOPE_STORES]) ? $this->storeManager->getStore($designConfig->getScopeId()) : ''; $this->eventManager->dispatch('admin_system_config_changed_section_design', ['website' => $website, 'store' => $store]); return $designConfig; }
/** * Get options. * * @return array */ public function toOptionArray() { $fields = []; $fields[] = ['value' => '0', 'label' => '-- Disabled --']; $websiteName = $this->request->getParam('website', false); $website = $websiteName ? $this->storeManager->getWebsite($websiteName) : 0; if ($this->helper->isEnabled($website)) { $savedPrograms = $this->registry->registry('programs'); //get saved datafileds from registry if (is_array($savedPrograms)) { $programs = $savedPrograms; } else { //grab the datafields request and save to register $client = $this->helper->getWebsiteApiClient($website); $programs = $client->getPrograms(); $this->registry->unregister('programs'); $this->registry->register('programs', $programs); } //set the api error message for the first option if (isset($programs->message)) { //message $fields[] = ['value' => 0, 'label' => $programs->message]; } elseif (!empty($programs)) { //loop for all programs option foreach ($programs as $program) { if (isset($program->id) && $program->status == 'Active') { //@codingStandardsIgnoreStart $fields[] = ['value' => $program->id, 'label' => addslashes($program->name)]; //@codingStandardsIgnoreEnd } } } } return $fields; }
/** * Set new customer group to all his quotes * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function dispatch(\Magento\Framework\Event\Observer $observer) { /** @var CustomerData $customerDataObject */ $customerDataObject = $observer->getEvent()->getCustomerDataObject(); /** @var CustomerData $origCustomerDataObject */ $origCustomerDataObject = $observer->getEvent()->getOrigCustomerDataObject(); if ($customerDataObject->getGroupId() !== $origCustomerDataObject->getGroupId()) { /** * It is needed to process customer's quotes for all websites * if customer accounts are shared between all of them */ /** @var $websites \Magento\Store\Model\Website[] */ $websites = $this->_config->isWebsiteScope() ? array($this->_storeManager->getWebsite($customerDataObject->getWebsiteId())) : $this->_storeManager->getWebsites(); foreach ($websites as $website) { $quote = $this->_quoteFactory->create(); $quote->setWebsite($website); $quote->loadByCustomer($customerDataObject->getId()); if ($quote->getId()) { $quote->setCustomerGroupId($customerDataObject->getGroupId()); $quote->collectTotals(); $quote->save(); } } } }
/** * Set new customer group to all his quotes * * @param Observer $observer * @return void */ public function dispatch(Observer $observer) { /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $observer->getEvent()->getCustomerDataObject(); /** @var \Magento\Customer\Api\Data\CustomerInterface $origCustomer */ $origCustomer = $observer->getEvent()->getOrigCustomerDataObject(); if ($customer->getGroupId() !== $origCustomer->getGroupId()) { /** * It is needed to process customer's quotes for all websites * if customer accounts are shared between all of them */ /** @var $websites \Magento\Store\Model\Website[] */ $websites = $this->config->isWebsiteScope() ? [$this->storeManager->getWebsite($customer->getWebsiteId())] : $this->storeManager->getWebsites(); foreach ($websites as $website) { try { $quote = $this->quoteRepository->getForCustomer($customer->getId()); $quote->setWebsite($website); $quote->setCustomerGroupId($customer->getGroupId()); $quote->collectTotals(); $this->quoteRepository->save($quote); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { } } } }
/** * @param \Magento\Framework\App\ActionInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundExecute( \Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request ) { /** @var \Magento\Store\Model\Store $defaultStore */ $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $requestedStoreCode = $this->httpRequest->getParam( StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); /** @var \Magento\Store\Model\Store $currentStore */ $currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore; $this->httpContext->setValue( StoreManagerInterface::CONTEXT_STORE, $currentStore->getCode(), $this->storeManager->getDefaultStoreView()->getCode() ); $this->httpContext->setValue( HttpContext::CONTEXT_CURRENCY, $this->session->getCurrencyCode() ?: $currentStore->getDefaultCurrencyCode(), $defaultStore->getDefaultCurrencyCode() ); return $proceed($request); }
/** * Get data * * @param array $item * @return string */ protected function prepareItem(array $item) { if ($item['website_id'] == Website\Options::ALL_WEBSITES) { return __('All Websites'); } return $this->storeManager->getWebsite($item['website_id'])->getName(); }
/** * {@inheritdoc} */ public function getScope($scopeId = null) { $scope = $this->_storeManager->getWebsite($scopeId); if (!$scope instanceof \Magento\Framework\App\ScopeInterface) { throw new \Magento\Store\Model\Exception('Invalid scope object'); } return $scope; }
/** * Get options for grid filter * * @return null|array */ public function getCondition() { $id = $this->getValue(); if (!$id) { return null; } $website = $this->_storeManager->getWebsite($id); return ['in' => $website->getStoresIds(true)]; }
/** * Build index query * * @param RequestInterface $request * @return Select */ public function build(RequestInterface $request) { $select = $this->getSelect()->from(['search_index' => $this->resource->getTableName($request->getIndex())], ['entity_id' => 'search_index.product_id'])->joinLeft(['category_index' => $this->resource->getTableName('catalog_category_product_index')], 'search_index.product_id = category_index.product_id' . ' AND search_index.store_id = category_index.store_id', []); $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE); if ($isShowOutOfStock === false) { $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.product_id = stock_index.product_id' . $this->getReadConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), [])->where('stock_index.stock_status = ?', 1); } return $select; }
/** * @param string $email * @return bool|\Magento\Customer\Model\Customer */ public function getCustomerByEmail($email) { /** @var \Magento\Customer\Model\Customer $customer */ $customer = $this->customerFactory->create(); $customer->setWebsiteId($this->storeManager->getWebsite()->getId()); $customer->loadByEmail($email); if ($customer->getId()) { return $customer; } return false; }
/** * Adds New Relic custom parameters per request for store, website, and logged in user if applicable * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName()); $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName()); if ($this->customerSession->isLoggedIn()) { $customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId()); $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname()); } } }
/** * Substitute empty value with Default country. * * @return void */ protected function _afterLoad() { $value = (string) $this->getValue(); if (empty($value)) { if ($this->getWebsite()) { $defaultCountry = $this->_storeManager->getWebsite($this->getWebsite())->getConfig(\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY); } else { $defaultCountry = $this->directoryHelper->getDefaultCountry($this->getStore()); } $this->setValue($defaultCountry); } }
/** * Build index query * * @param RequestInterface $request * @return Select */ public function build(RequestInterface $request) { $searchIndexTable = $this->scopeResolver->resolve($request->getIndex(), $request->getDimensions()); $select = $this->resource->getConnection()->select()->from(['search_index' => $searchIndexTable], ['entity_id' => 'entity_id'])->joinLeft(['cea' => $this->resource->getTableName('catalog_eav_attribute')], 'search_index.attribute_id = cea.attribute_id', []); $select = $this->tableMapper->addTables($select, $request); $select = $this->processDimensions($request, $select); $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE); if ($isShowOutOfStock === false) { $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.entity_id = stock_index.product_id' . $this->resource->getConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), []); $select->where('stock_index.stock_status = ?', 1); } return $select; }
/** * Processing object after delete data * * @return \Magento\Framework\Model\AbstractModel */ public function afterDelete() { $result = parent::afterDelete(); if ($this->getScope() == \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES) { $attribute = $this->_eavConfig->getAttribute('customer_address', 'street'); $website = $this->_storeManager->getWebsite($this->getScopeCode()); $attribute->setWebsite($website); $attribute->load($attribute->getId()); $attribute->setData('scope_multiline_count', null); $attribute->save(); } return $result; }
/** * Execute method. */ public function execute() { if ($this->getRequest()->getParams()) { try { $ruleModel = $this->ruleFactory->create(); $data = $this->getRequest()->getParams(); $id = $this->getRequest()->getParam('id'); if ($data['website_ids']) { foreach ($data['website_ids'] as $websiteId) { $result = $ruleModel->checkWebsiteBeforeSave($websiteId, $data['type'], $id); if (!$result) { $websiteName = $this->storeManager->getWebsite($websiteId)->getName(); $this->messageManager->addErrorMessage(__('Rule already exist for website ' . $websiteName . '. You can only have one rule per website.')); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); return; } } } $ruleModel->getResource()->load($ruleModel, $id); if ($id != $ruleModel->getId()) { throw new \Magento\Framework\Exception\LocalizedException(__('Wrong rule specified.')); } foreach ($data as $key => $value) { if ($key != 'form_key') { if ($key == 'condition') { if (is_array($value)) { unset($value['__empty']); } } $ruleModel->setData($key, $value); } } $this->_getSession()->setPageData($ruleModel->getData()); $ruleModel->getResource()->save($ruleModel); $this->messageManager->addSuccessMessage(__('The rule has been saved.')); $this->_getSession()->setPageData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', ['id' => $ruleModel->getId()]); return; } $this->_redirect('*/*/'); return; } catch (\Exception $e) { $this->messageManager->addErrorMessage(__('An error occurred while saving the rule data. Please review the log and try again.')); $this->_getSession()->setPageData($data); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); return; } } $this->_redirect('*/*/'); }
/** * Reports concurrent users to the database reporting_users table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->customerSession->isLoggedIn()) { $customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()]; $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)]; /** @var \Magento\NewRelicReporting\Model\Users $usersModel */ $usersModel = $this->usersFactory->create(); $usersModel->setData($modelData); $usersModel->save(); } } }
/** * Export shipping table rates in csv format * * @return ResponseInterface */ public function execute() { $fileName = 'tablerates.csv'; /** @var $gridBlock \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid */ $gridBlock = $this->_view->getLayout()->createBlock('Magento\\OfflineShipping\\Block\\Adminhtml\\Carrier\\Tablerate\\Grid'); $website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website')); if ($this->getRequest()->getParam('conditionName')) { $conditionName = $this->getRequest()->getParam('conditionName'); } else { $conditionName = $website->getConfig('carriers/tablerate/condition_name'); } $gridBlock->setWebsiteId($website->getId())->setConditionName($conditionName); $content = $gridBlock->getCsvFile(); return $this->_fileFactory->create($fileName, $content, \Magento\Framework\App\Filesystem::VAR_DIR); }
/** * Export shipping table rates in csv format * * @return ResponseInterface */ public function execute() { $fileName = 'matrixrates.csv'; /** @var $gridBlock \WebShopApps\MatrixRate\Block\Adminhtml\Carrier\Matrixrate\Grid */ $gridBlock = $this->_view->getLayout()->createBlock('WebShopApps\\MatrixRate\\Block\\Adminhtml\\Carrier\\Matrixrate\\Grid'); $website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website')); if ($this->getRequest()->getParam('conditionName')) { $conditionName = $this->getRequest()->getParam('conditionName'); } else { $conditionName = $website->getConfig('carriers/matrixrate/condition_name'); } $gridBlock->setWebsiteId($website->getId())->setConditionName($conditionName); $content = $gridBlock->getCsvFile(); return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR); }
/** * @param array $orderData * @return void */ public function createOrder($orderData) { $this->setPhraseRenderer(); if (!empty($orderData)) { $orderCreateModel = $this->processQuote($orderData); if (!empty($orderData['payment'])) { $orderCreateModel->setPaymentData($orderData['payment']); $orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']); } $customer = $this->customerRepository->get($orderData['order']['account']['email'], $this->storeManager->getWebsite()->getId()); $orderCreateModel->getQuote()->setCustomer($customer); $orderCreateModel->getSession()->setCustomerId($customer->getId()); $order = $orderCreateModel->importPostData($orderData['order'])->createOrder(); $orderItem = $this->getOrderItemForTransaction($order); $this->invoiceOrder($orderItem); $this->shipOrder($orderItem); if ($orderData['refund'] === "yes") { $this->refundOrder($orderItem); } $registryItems = ['rule_data', 'currently_saved_addresses', 'current_invoice', 'current_shipment']; $this->unsetRegistryData($registryItems); $this->currentSession->unsQuoteId(); $this->currentSession->unsStoreId(); $this->currentSession->unsCustomerId(); } }
/** * Get Product Weee attributes for price renderer * * @param \Magento\Catalog\Model\Product $product * @param null|false|\Magento\Framework\DataObject $shipping Shipping Address * @param null|false|\Magento\Framework\DataObject $billing Billing Address * @param null|Website $website * @param bool $calculateTaxes * @return \Magento\Framework\DataObject[] */ public function getProductWeeeAttributesForRenderer( $product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false ) { /** @var \Magento\Store\Model\Store $store */ if ($website) { $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore(); } else { $store = $product->getStore(); } if ($this->isEnabled($store)) { return $this->getProductWeeeAttributes( $product, $shipping, $billing, $website, $calculateTaxes ? $calculateTaxes : $this->typeOfDisplay(1) ); } return []; }
/** * Prepare website current dates table * * @return \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction */ protected function _prepareWebsiteDateTable() { $baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE); $select = $this->_connection->select()->from(['cw' => $this->_defaultIndexerResource->getTable('store_website')], ['website_id'])->join(['csg' => $this->_defaultIndexerResource->getTable('store_group')], 'cw.default_group_id = csg.group_id', ['store_id' => 'default_store_id'])->where('cw.website_id != 0'); $data = []; foreach ($this->_connection->fetchAll($select) as $item) { /** @var $website \Magento\Store\Model\Website */ $website = $this->_storeManager->getWebsite($item['website_id']); if ($website->getBaseCurrencyCode() != $baseCurrency) { $rate = $this->_currencyFactory->create()->load($baseCurrency)->getRate($website->getBaseCurrencyCode()); if (!$rate) { $rate = 1; } } else { $rate = 1; } /** @var $store \Magento\Store\Model\Store */ $store = $this->_storeManager->getStore($item['store_id']); if ($store) { $timestamp = $this->_localeDate->scopeTimeStamp($store); $data[] = ['website_id' => $website->getId(), 'website_date' => $this->_dateTime->formatDate($timestamp, false), 'rate' => $rate]; } } $table = $this->_defaultIndexerResource->getTable('catalog_product_index_website'); $this->_emptyTable($table); if ($data) { foreach ($data as $row) { $this->_connection->insertOnDuplicate($table, $row, array_keys($row)); } } return $this; }
/** * {@inheritdoc} */ public function install(array $fixtures) { /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ $adapter = $this->resource->getConnection('core_write'); $regions = $this->loadDirectoryRegions(); foreach ($fixtures as $fileName) { $fileName = $this->fixtureManager->getFixture($fileName); if (!file_exists($fileName)) { continue; } $rows = $this->csvReader->getData($fileName); $header = array_shift($rows); foreach ($rows as $row) { $data = []; foreach ($row as $key => $value) { $data[$header[$key]] = $value; } $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0; try { $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsite()->getId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]); } catch (\Zend_Db_Statement_Exception $e) { if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) { // In case if Sample data was already installed we just skip duplicated records installation continue; } else { throw $e; } } } } $this->configWriter->save('carriers/tablerate/active', 1); $this->configWriter->save('carriers/tablerate/condition_name', 'package_value'); $this->cacheTypeList->cleanType('config'); }
/** * @return array */ protected function getDefaultCustomerProfile() { if (!$this->customerDataProfile) { $this->customerDataProfile = ['website_id' => $this->storeManager->getWebsite()->getId(), 'group_id' => $this->storeManager->getGroup()->getId(), 'disable_auto_group_change' => '0', 'prefix', 'firstname' => '', 'middlename' => '', 'lastname' => '', 'suffix' => '', 'email' => '', 'dob' => '', 'taxvat' => '', 'gender' => '', 'confirmation' => false, 'sendemail' => false]; } return $this->customerDataProfile; }
/** * @param \Magento\Customer\Model\Config\Share $configShare * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param string $namespace * @param array $data */ public function __construct(\Magento\Customer\Model\Config\Share $configShare, \Magento\Store\Model\StoreManagerInterface $storeManager, $namespace = 'customer', array $data = []) { if ($configShare->isWebsiteScope()) { $namespace .= '_' . $storeManager->getWebsite()->getCode(); } parent::__construct($namespace, $data); }
/** * Get HTML output for override hint UI * * @param \Magento\Config\Block\System\Config\Form $form * @param array $overridden * @return string */ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form $form, array $overridden) { $title = __('This setting is overridden at a more specific scope. Click for details.'); $formatted = '<a class="overridden-hint-list-toggle" title="' . $title . '" href="#"><span>' . $title . '</span></a>' . '<ul class="overridden-hint-list">'; foreach ($overridden as $overriddenScope) { $scope = $overriddenScope['scope']; $scopeId = $overriddenScope['scope_id']; $scopeLabel = $scopeId; $url = '#'; $section = $form->getSectionCode(); switch ($scope) { case 'website': $url = $this->urlBuilder->getUrl('*/*/*', array('section' => $section, 'website' => $scopeId)); $scopeLabel = sprintf('website <a href="%s">%s</a>', $url, $this->storeManager->getWebsite($scopeId)->getName()); break; case 'store': $store = $this->storeManager->getStore($scopeId); $website = $store->getWebsite(); $url = $this->urlBuilder->getUrl('*/*/*', array('section' => $section, 'store' => $store->getId())); $scopeLabel = sprintf('store view <a href="%s">%s</a>', $url, $website->getName() . ' / ' . $store->getName()); break; } $formatted .= "<li class='{$scope}'>Overridden on {$scopeLabel}</li>"; } $formatted .= '</ul>'; return $formatted; }
/** * Retrieve website model * * @return Website|bool */ public function getWebsite() { if ($this->getWebsiteId() === null) { return false; } return $this->_storeManager->getWebsite($this->getWebsiteId()); }
/** * Get scope name and scopeId * @todo refactor to scope resolver * @return void */ private function initScope() { if (is_null($this->getSection())) { $this->setSection(''); } if (is_null($this->getWebsite())) { $this->setWebsite(''); } if (is_null($this->getStore())) { $this->setStore(''); } if ($this->getStore()) { $scope = 'stores'; $store = $this->_storeManager->getStore($this->getStore()); $scopeId = (int) $store->getId(); $scopeCode = $this->getStore(); } elseif ($this->getWebsite()) { $scope = 'websites'; $website = $this->_storeManager->getWebsite($this->getWebsite()); $scopeId = (int) $website->getId(); $scopeCode = $this->getWebsite(); } else { $scope = 'default'; $scopeId = 0; $scopeCode = ''; } $this->setScope($scope); $this->setScopeId($scopeId); $this->setScopeCode($scopeCode); }