本文整理匯總了PHP中Magento\Store\Model\StoreManagerInterface::getDefaultStoreView方法的典型用法代碼示例。如果您正苦於以下問題:PHP StoreManagerInterface::getDefaultStoreView方法的具體用法?PHP StoreManagerInterface::getDefaultStoreView怎麽用?PHP StoreManagerInterface::getDefaultStoreView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Store\Model\StoreManagerInterface
的用法示例。
在下文中一共展示了StoreManagerInterface::getDefaultStoreView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: read
/**
* 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;
}
示例2: execute
/**
* @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());
}
}
示例3: sendNotification
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;
}
}
示例4: aroundDispatch
/**
* @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);
}
示例5: execute
/**
* 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;
}
示例6: setStoreId
/**
* 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;
}
示例7: beforeDispatch
/**
* 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());
}
}
}
示例8: install
/**
* @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);
}
}
}
示例9: aroundDispatch
/**
* @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);
}
示例10: prepareReview
/**
* @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;
}
示例11: getMapping
/**
* 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;
}
示例12: checkNativeTaxRules
/**
* 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;
}
示例13: getTree
/**
* 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;
}
示例14: getProductSorterLoadUrl
/**
* 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);
}
示例15: install
/**
* @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();
}