/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { if ($this->_appState->isInstalled()) { if (empty($code)) { $store = $this->_storeManager->getStore(); } elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) { $store = $this->_storeManager->getDefaultStoreView(); } else { $store = $this->_storeFactory->create(); $store->load($code); } if (!$store->getCode()) { throw NoSuchEntityException::singleField('storeCode', $code); } $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource(); $config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); $collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId())); $dbStoreConfig = array(); foreach ($collection as $item) { $dbStoreConfig[$item->getPath()] = $item->getValue(); } $config = $this->_converter->convert($dbStoreConfig, $config); } else { $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource(); $config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); } return $config; }
/** * @return void */ public function execute() { $currentActiveStore = $this->storeManager->getStore(); $storeCode = $this->_request->getParam(StoreResolver::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie()); try { $store = $this->storeRepository->getActiveStoreByCode($storeCode); } catch (StoreIsInactiveException $e) { $error = __('Requested store is inactive'); } catch (NoSuchEntityException $e) { $error = __('Requested store is not found'); } if (isset($error)) { $this->messageManager->addError($error); $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); return; } $defaultStoreView = $this->storeManager->getDefaultStoreView(); if ($defaultStoreView->getId() == $store->getId()) { $this->storeCookieManager->deleteStoreCookie($store); } else { $this->httpContext->setValue(Store::ENTITY, $store->getCode(), $defaultStoreView->getCode()); $this->storeCookieManager->setStoreCookie($store); } if ($store->isUseStoreInUrl()) { // Change store code in redirect url if (strpos($this->_redirect->getRedirectUrl(), $currentActiveStore->getBaseUrl()) !== false) { $this->getResponse()->setRedirect(str_replace($currentActiveStore->getBaseUrl(), $store->getBaseUrl(), $this->_redirect->getRedirectUrl())); } else { $this->getResponse()->setRedirect($store->getBaseUrl()); } } else { $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } }
public function sendNotification($data) { if (!$data) { return false; } $this->inlineTranslation->suspend(); try { $postObject = new \Magento\Framework\DataObject(); $postObject->setData($data); $error = false; $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; /* $from = [ 'name' => '', 'email' => '' ];*/ $email_template = $this->scopeConfig->getValue('cadou/email/template'); if (empty($email_template)) { $email_template = (string) 'cadou_email_template'; // this code we have mentioned in the email_templates.xml } $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); /*$this->messageManager->addSuccess( __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.') );*/ return TRUE; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())); return FALSE; } }
/** * @param \Magento\Framework\App\ActionInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\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); }
/** * 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; }
/** * Set store for resource model * * @param null|string|bool|int|Store $store * @return $this */ public function setStoreId($store) { if (is_int($store)) { $this->_storeId = $store; } else { $this->_storeId = $this->_storeManager->getStore()->getId(); } if (empty($this->_storeId)) { $defaultStore = $this->_storeManager->getDefaultStoreView(); if ($defaultStore) { $this->_storeId = (int) $defaultStore->getId(); } } return $this; }
/** * Delete cookie "store" if the store (a value in the cookie) does not exist or is inactive * * @param \Magento\Framework\App\FrontController $subject * @param \Magento\Framework\App\RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\RequestInterface $request) { $storeCodeFromCookie = $this->storeCookieManager->getStoreCodeFromCookie(); if ($storeCodeFromCookie) { try { $this->storeRepository->getActiveStoreByCode($storeCodeFromCookie); } catch (StoreIsInactiveException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } catch (NoSuchEntityException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } catch (InvalidArgumentException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } } }
/** * @param array $productFixtures * @param array $galleryFixtures * @throws \Exception */ public function install(array $productFixtures, array $galleryFixtures) { $this->eavConfig->clear(); $this->setGalleryFixtures($galleryFixtures); $product = $this->productFactory->create(); foreach ($productFixtures 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; } $row = $data; $attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']); $this->converter->setAttributeSetId($attributeSetId); $data = $this->converter->convertRow($row); $product->unsetData(); $product->setData($data); $product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getDefaultStoreView()->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID); if (empty($data['visibility'])) { $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); } $this->prepareProduct($product, $data); $product->save(); $this->installGallery($product); } } }
/** * @param \Magento\Framework\App\ActionInterface $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { /** @var \Magento\Store\Model\Store $defaultStore */ $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $storeCode = $this->httpRequest->getParam(StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie()); if (is_array($storeCode)) { if (!isset($storeCode['_data']['code'])) { throw new \InvalidArgumentException(new Phrase('Invalid store parameter.')); } $storeCode = $storeCode['_data']['code']; } /** @var \Magento\Store\Model\Store $currentStore */ $currentStore = $storeCode ? $this->storeManager->getStore($storeCode) : $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); }
/** * @param array $row * @return \Magento\Review\Model\Review */ protected function prepareReview($row) { /** @var $review \Magento\Review\Model\Review */ $review = $this->reviewFactory->create(); $storeId = $this->storeManager->getDefaultStoreView()->getStoreId(); $review->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))->setEntityPkValue($this->getProductIdBySku($row['sku']))->setNickname($row['reviewer'])->setTitle($row['title'])->setDetail($row['review'])->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED)->setStoreId($storeId)->setStores([$storeId]); return $review; }
/** * Retrieve the search engine mapping. * * @return MappingInterface */ private function getMapping() { if ($this->mapping === null) { $defaultStore = $this->storeManager->getDefaultStoreView(); $index = $this->indexManager->getIndexByName($this->indexName, $defaultStore); $this->mapping = $index->getType($this->typeName)->getMapping(); } return $this->mapping; }
/** * Check to see if there are any native tax rules created that may affect AvaTax * * @return array */ public function checkNativeTaxRules() { $errors = []; if ($this->avaTaxConfig->isModuleEnabled() && $this->avaTaxConfig->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT && !$this->avaTaxConfig->isNativeTaxRulesIgnored()) { $taxRules = $this->taxRuleRepository->getList($this->searchCriteriaBuilder->create()); if (count($taxRules->getItems())) { $errors[] = __('You have %1 native Magento Tax Rule(s) configured. ' . 'Please <a href="%2">review the tax rule(s)</a> and delete any that you do not specifically want enabled. ' . 'You should only have rules setup if you want to use them as backup rules in case of AvaTax ' . 'errors (see <a href="#row_tax_avatax_error_handling_header">Error Action setting</a>) ' . 'or if you need to support VAT tax. ' . '<a href="%3">Ignore this notification</a>.', count($taxRules->getItems()), $this->backendUrl->getUrl('tax/rule'), $this->backendUrl->getUrl('avatax/tax/ignoreTaxRuleNotification')); } } return $errors; }
/** * Get category tree * * @param int|null $rootNode * @param bool $reload * @return \Magento\Framework\Data\Tree\Node */ protected function getTree($rootNode = null, $reload = false) { if (!$this->categoryTree || $reload) { if ($rootNode === null) { $rootNode = $this->storeManager->getDefaultStoreView()->getRootCategoryId(); } $tree = $this->resourceCategoryTreeFactory->create(); $node = $tree->loadNode($rootNode)->loadChildren(); $tree->addCollectionData(null, false, $rootNode); $this->categoryTree = $node; } return $this->categoryTree; }
/** * Retrieve the category product sorter load URL. * * @param Category $category Category. * * @return string */ private function getProductSorterLoadUrl(Category $category) { $storeId = $category->getStoreId(); if ($storeId === 0) { $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId(); $storeId = current(array_filter($category->getStoreIds())); if (in_array($defaultStoreId, $category->getStoreIds())) { $storeId = $defaultStoreId; } } $urlParams = ['ajax' => true, 'store' => $storeId]; return $this->urlBuilder->getUrl('virtualcategory/category_virtual/preview', $urlParams); }
/** * @param array $fixtures * @throws \Exception */ public function install(array $fixtures) { $attributeCount = 0; 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; } $data['attribute_set'] = explode("\n", $data['attribute_set']); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */ $attribute = $this->eavConfig->getAttribute('catalog_product', $data['attribute_code']); if (!$attribute) { $attribute = $this->attributeFactory->create(); } $frontendLabel = explode("\n", $data['frontend_label']); if (count($frontendLabel) > 1) { $data['frontend_label'] = []; $data['frontend_label'][\Magento\Store\Model\Store::DEFAULT_STORE_ID] = $frontendLabel[0]; $data['frontend_label'][$this->storeManager->getDefaultStoreView()->getStoreId()] = $frontendLabel[1]; } $data['option'] = $this->getOption($attribute, $data); $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($data['frontend_input']); $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($data['frontend_input']); $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []]; $data['backend_type'] = $attribute->getBackendTypeByInput($data['frontend_input']); $attribute->addData($data); $attribute->setIsUserDefined(1); $attribute->setEntityTypeId($this->getEntityTypeId()); $attribute->save(); $attributeId = $attribute->getId(); if (is_array($data['attribute_set'])) { foreach ($data['attribute_set'] as $setName) { $setName = trim($setName); $attributeCount++; $attributeSet = $this->processAttributeSet($setName); $attributeGroupId = $attributeSet->getDefaultGroupId(); $attribute = $this->attributeFactory->create(); $attribute->setId($attributeId)->setAttributeGroupId($attributeGroupId)->setAttributeSetId($attributeSet->getId())->setEntityTypeId($this->getEntityTypeId())->setSortOrder($attributeCount + 999)->save(); } } } } $this->eavConfig->clear(); }
/** * Retrieve customer model by his email. * * @param string $customerEmail * @param int $websiteId * @throws NoSuchEntityException If customer with the specified customer email not found. * @throws \Magento\Framework\Model\Exception If website was not specified * @return Customer */ public function getCustomerModelByEmail($customerEmail, $websiteId = null) { $customer = $this->_customerFactory->create(); if (!isset($websiteId)) { $websiteId = $this->storeManager->getDefaultStoreView()->getWebsiteId(); } $customer->setWebsiteId($websiteId); $customer->loadByEmail($customerEmail); if (!$customer->getId()) { throw new NoSuchEntityException(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'email', 'fieldValue' => $customerEmail]); } else { return $customer; } }
/** * Check whether notification is displayed * * @return bool */ public function isDisplayed() { // Check configuration to see if this should be evaluated further if ($this->avaTaxConfig->isModuleEnabled() == false || $this->avaTaxConfig->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_ESTIMATE_AND_SUBMIT || $this->avaTaxConfig->getQueueAdminNotificationEnabled() == false) { return false; } // Query the database to get some stats about the queue $this->loadQueueStats(); // Determine if we need to notify the admin user if ($this->authorization->isAllowed('ClassyLlama_AvaTax::manage_avatax') && $this->statQueueCount > 0) { return true; } else { return false; } }
/** * Get country list * * @return array */ protected function getCountryList() { // It seems odd to check the parameters directly, but it's the same pattern being used in Magento_Backend if ($this->request->getParam('store')) { $scopeId = $this->request->getParam('store'); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } elseif ($this->request->getParam('website')) { $scopeId = $this->request->getParam('website'); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE; } elseif ($this->request->getParam('group')) { $scopeId = $this->request->getParam('website'); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE; } else { $scopeId = $this->storeManager->getDefaultStoreView(); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } return explode(',', $this->config->getTaxCalculationCountriesEnabled($scopeId, $scopeType)); }
/** * @return int */ public function getDefaultRootCategoryId() { return $this->storeManager->getDefaultStoreView()->getGroup()->getDafaultCategoryId(); }
/** * Edit category page * * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { $storeId = (int) $this->getRequest()->getParam('store'); $parentId = (int) $this->getRequest()->getParam('parent'); $categoryId = (int) $this->getRequest()->getParam('id'); if (!$categoryId && !$parentId) { if ($storeId) { $categoryId = (int) $this->storeManager->getStore($storeId)->getRootCategoryId(); } else { $categoryId = (int) $this->storeManager->getDefaultStoreView()->getRootCategoryId(); } $this->getRequest()->setParam('id', $categoryId); } $category = $this->_initCategory(true); if (!$category) { /** @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(); /** * Build response for ajax request */ if ($this->getRequest()->getQuery('isAjax')) { // prepare breadcrumbs of selected category, if any $breadcrumbsPath = $category->getPath(); if (empty($breadcrumbsPath)) { // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session $breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true); if (!empty($breadcrumbsPath)) { $breadcrumbsPath = explode('/', $breadcrumbsPath); // no need to get parent breadcrumbs if deleting category level 1 if (count($breadcrumbsPath) <= 1) { $breadcrumbsPath = ''; } else { array_pop($breadcrumbsPath); $breadcrumbsPath = implode('/', $breadcrumbsPath); } } } $eventResponse = new \Magento\Framework\DataObject(['content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml() . $resultPage->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(), 'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()]); $this->_eventManager->dispatch('category_prepare_ajax_response', ['response' => $eventResponse, 'controller' => $this]); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); $resultJson->setHeader('Content-type', 'application/json', true); $resultJson->setData($eventResponse->getData()); return $resultJson; } $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; }
/** * Check whether notification is displayed * * @return bool */ public function isDisplayed() { return $this->getText() && $this->isQueuePage() && $this->config->isModuleEnabled() && $this->config->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_ESTIMATE_AND_SUBMIT; }