Esempio n. 1
0
 /**
  * @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());
     }
 }
Esempio n. 2
0
 /**
  * Get url for reorder action
  *
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 public function getReorderUrl($order)
 {
     if (!$this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]);
     }
     return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
 }
Esempio n. 3
0
 /**
  * Return back title for logged in and guest users
  *
  * @return \Magento\Framework\Phrase
  */
 public function getBackTitle()
 {
     if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return __('Back to My Orders');
     }
     return __('View Another Order');
 }
 /**
  * Test aroundDispatch
  */
 public function testAroundDispatch()
 {
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(1));
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
     $this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock], [Context::CONTEXT_AUTH, 0, $this->httpContextMock]]));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Esempio n. 5
0
 /**
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode());
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode());
     return $proceed($request);
 }
Esempio n. 6
0
 protected function setUp()
 {
     $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->request->expects($this->at(0))->method('getParam')->with('store_id')->will($this->returnValue(null));
     $this->request->expects($this->at(1))->method('getParam')->with('cid')->will($this->returnValue(null));
     $this->httpContext = $this->getMockBuilder('Magento\\Framework\\App\\Http\\Context')->setMethods(['getValue'])->disableOriginalConstructor()->getMock();
     $this->httpContext->expects($this->any())->method('getValue')->will($this->returnValue(1));
     $this->imageHelper = $this->getMock('Magento\\Catalog\\Helper\\Image', [], [], '', false);
     $this->outputHelper = $this->getMock('Magento\\Catalog\\Helper\\Output', ['productAttribute'], [], '', false);
     $this->msrpHelper = $this->getMock('Magento\\Msrp\\Helper\\Data', ['canApplyMsrp'], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->rssModel = $this->getMock('Magento\\Catalog\\Model\\Rss\\Product\\Special', [], [], '', false);
     $this->rssUrlBuilder = $this->getMock('Magento\\Framework\\App\\Rss\\UrlBuilderInterface');
     $this->storeManager = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface');
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->setMethods(['getId', 'getFrontendName', '__wakeup'])->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getId')->will($this->returnValue(1));
     $store->expects($this->any())->method('getFrontendName')->will($this->returnValue('Store 1'));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->scopeConfig = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('en_US'));
     $this->localeDate = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface');
     $this->dateFactory = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateFactory', ['create'], [], '', false);
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->block = $objectManagerHelper->getObject('Magento\\Catalog\\Block\\Rss\\Product\\Special', ['request' => $this->request, 'httpContext' => $this->httpContext, 'imageHelper' => $this->imageHelper, 'outputHelper' => $this->outputHelper, 'msrpHelper' => $this->msrpHelper, 'priceCurrency' => $this->priceCurrency, 'rssModel' => $this->rssModel, 'rssUrlBuilder' => $this->rssUrlBuilder, 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'localeDate' => $this->localeDate, 'dateFactory' => $this->dateFactory]);
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 protected function _toHtml()
 {
     if (!$this->_customerHelper->isRegistrationAllowed() || $this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
Esempio n. 8
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
Esempio n. 9
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 protected function _toHtml()
 {
     if (!$this->_registration->isAllowed() || $this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
Esempio n. 11
0
 /**
  * @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)
 {
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_SORT_DIRECTION, $this->toolbarModel->getDirection(), \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION);
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_SORT_ORDER, $this->toolbarModel->getOrder(), $this->productListHelper->getDefaultSortField());
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_DISPLAY_MODE, $this->toolbarModel->getMode(), $this->productListHelper->getDefaultViewMode());
     $this->httpContext->setValue(Data::CONTEXT_CATALOG_LIMIT, $this->toolbarModel->getLimit(), $this->productListHelper->getDefaultLimitPerPageValue($this->productListHelper->getDefaultViewMode()));
     return $proceed($request);
 }
Esempio n. 12
0
 public function testSendVary()
 {
     $vary = array('some-vary-key' => 'some-vary-value');
     $expected = sha1(serialize($vary));
     $this->_context->setValue('some-vary-key', 'some-vary-value', 'default');
     $this->_cookieMock->expects($this->once())->method('set')->with(Http::COOKIE_VARY_STRING, $expected);
     $this->_model->sendVary();
 }
Esempio n. 13
0
 public function testGetVaryString()
 {
     $this->object->setValue('key2', 'value2', 'default2');
     $this->object->setValue('key1', 'value1', 'default1');
     $data = ['key2' => 'value2', 'key1' => 'value1'];
     ksort($data);
     $this->assertEquals(sha1(serialize($data)), $this->object->getVaryString());
 }
Esempio n. 14
0
 /**
  * Get customer group id
  *
  * @return int
  */
 protected function getCustomerGroupId()
 {
     $customerGroupId = (int) $this->getRequest()->getParam('cid');
     if ($customerGroupId == null) {
         $customerGroupId = $this->httpContext->getValue(Context::CONTEXT_GROUP);
     }
     return $customerGroupId;
 }
Esempio n. 15
0
 /**
  * @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);
 }
Esempio n. 16
0
 /**
  * Send Vary cookie
  *
  * @return void
  */
 public function sendVary()
 {
     $varyString = $this->context->getVaryString();
     if ($varyString) {
         $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
         $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookMetadata);
     } elseif ($this->request->get(self::COOKIE_VARY_STRING)) {
         $cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
         $this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata);
     }
 }
Esempio n. 17
0
 /**
  * Send Vary coookie
  * @return void
  */
 public function sendVary()
 {
     $data = $this->context->getData();
     if (!empty($data)) {
         ksort($data);
         $vary = sha1(serialize($data));
         $this->cookie->set(self::COOKIE_VARY_STRING, $vary, null, '/');
     } else {
         $this->cookie->set(self::COOKIE_VARY_STRING, null, -1, '/');
     }
 }
Esempio n. 18
0
 public function testAroundDispatchHasSortDirection()
 {
     $this->toolbarModelMock->expects($this->exactly(1))->method('getDirection')->will($this->returnValue('asc'));
     $this->toolbarModelMock->expects($this->once())->method('getOrder')->will($this->returnValue('Name'));
     $this->toolbarModelMock->expects($this->once())->method('getMode')->will($this->returnValue('list'));
     $this->toolbarModelMock->expects($this->once())->method('getLimit')->will($this->returnValue(array(1 => 1, 2 => 2)));
     $this->productListHelperMock->expects($this->once())->method('getDefaultSortField')->will($this->returnValue('Field'));
     $this->productListHelperMock->expects($this->exactly(2))->method('getDefaultViewMode')->will($this->returnValue('grid'));
     $this->productListHelperMock->expects($this->once())->method('getDefaultLimitPerPageValue')->will($this->returnValue(array(10 => 10)));
     $this->httpContextMock->expects($this->exactly(4))->method('setValue')->will($this->returnValueMap(array(array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_DIRECTION, 'asc', \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION, $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_SORT_ORDER, 'Name', 'Field', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_DISPLAY_MODE, 'list', 'grid', $this->httpContextMock), array(\Magento\Catalog\Helper\Data::CONTEXT_CATALOG_LIMIT, array(1 => 1, 2 => 2), array(10 => 10)))));
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Esempio n. 19
0
 public function testSendVary()
 {
     $data = ['some-vary-key' => 'some-vary-value'];
     $expectedCookieName = Http::COOKIE_VARY_STRING;
     $expectedCookieValue = sha1(serialize($data));
     $publicCookieMetadataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
     $publicCookieMetadataMock->expects($this->once())->method('setPath')->with('/')->will($this->returnSelf());
     $this->contextMock->expects($this->once())->method('getData')->with()->will($this->returnValue($data));
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadataMock));
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with($expectedCookieName, $expectedCookieValue, $publicCookieMetadataMock);
     $this->model->sendVary();
 }
Esempio n. 20
0
 /**
  * Retrieve welcome text
  *
  * @return string
  */
 public function getWelcome()
 {
     if (empty($this->_data['welcome'])) {
         if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
             $customerName = $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject());
             $this->_data['welcome'] = __('Welcome, %1!', $this->escapeHtml($customerName));
         } else {
             $this->_data['welcome'] = $this->_scopeConfig->getValue('design/header/welcome', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         }
     }
     return $this->_data['welcome'];
 }
Esempio n. 21
0
 /**
  * Send Vary cookie
  *
  * @return void
  */
 public function sendVary()
 {
     $data = $this->context->getData();
     if (!empty($data)) {
         ksort($data);
         $cookieValue = sha1(serialize($data));
         $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
         $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $cookieValue, $sensitiveCookMetadata);
     } else {
         $cookieMetadata = $this->cookieMetadataFactory->createCookieMetadata()->setPath('/');
         $this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata);
     }
 }
Esempio n. 22
0
 public function testGetCacheKeyInfo()
 {
     $store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $store->expects($this->once())->method('getId')->willReturn(1);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->once())->method('getId')->willReturn('blank');
     $this->design->expects($this->once())->method('getDesignTheme')->willReturn($theme);
     $this->httpContext->expects($this->once())->method('getValue')->willReturn('context_group');
     $this->productsList->setData('conditions', 'some_serialized_conditions');
     $this->request->expects($this->once())->method('getParam')->with('np')->willReturn(1);
     $cacheKey = ['CATALOG_PRODUCTS_LIST_WIDGET', 1, 'blank', 'context_group', 1, 5, 'some_serialized_conditions'];
     $this->assertEquals($cacheKey, $this->productsList->getCacheKeyInfo());
 }
 /**
  * @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)
 {
     if (!$this->customerSession->isLoggedIn() || !$this->moduleManager->isEnabled('Magento_PageCache') || !$this->cacheConfig->isEnabled() || !$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         return $proceed($request);
     }
     $defaultBillingAddress = $this->customerSession->getDefaultTaxBillingAddress();
     $defaultShippingAddress = $this->customerSession->getDefaultTaxShippingAddress();
     $customerTaxClassId = $this->customerSession->getCustomerTaxClassId();
     if (!empty($defaultBillingAddress) || !empty($defaultShippingAddress)) {
         $taxRates = $this->taxCalculation->getTaxRates($defaultBillingAddress, $defaultShippingAddress, $customerTaxClassId);
         $this->httpContext->setValue('tax_rates', $taxRates, 0);
     }
     return $proceed($request);
 }
Esempio n. 24
0
 public function testGetCacheKeyInfo()
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->atLeastOnce())->method('getId')->willReturn(55);
     $store->expects($this->atLeastOnce())->method('getRootCategoryId')->willReturn(60);
     $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->atLeastOnce())->method('getId')->willReturn(65);
     $this->design->expects($this->atLeastOnce())->method('getDesignTheme')->willReturn($theme);
     $this->httpContext->expects($this->atLeastOnce())->method('getValue')->with(\Magento\Customer\Model\Context::CONTEXT_GROUP)->willReturn(70);
     $this->block->setTemplate('block_template');
     $this->block->setNameInLayout('block_name');
     $expectedResult = ['CATALOG_NAVIGATION', 55, 65, 70, 'template' => 'block_template', 'name' => 'block_name', 60, 'category_path' => 60, 'short_cache_id' => 'c3de6d1160d1e7730b04d6cad409a2b4'];
     $this->assertEquals($expectedResult, $this->block->getCacheKeyInfo());
 }
Esempio n. 25
0
    /**
     * @param \Magento\Framework\App\ActionInterface $subject
     * @param callable $proceed
     * @param \Magento\Framework\App\RequestInterface $request
     * @return mixed
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function aroundExecute(
        \Magento\Framework\App\ActionInterface $subject,
        \Closure $proceed,
        \Magento\Framework\App\RequestInterface $request
    ) {
        if (!$this->weeeHelper->isEnabled() ||
            !$this->customerSession->isLoggedIn() ||
            !$this->moduleManager->isEnabled('Magento_PageCache') ||
            !$this->cacheConfig->isEnabled()) {
            return $proceed($request);
        }

        $basedOn = $this->taxHelper->getTaxBasedOn();
        if ($basedOn != 'shipping' && $basedOn != 'billing') {
            return $proceed($request);
        }

        $weeeTaxRegion = $this->getWeeeTaxRegion($basedOn);
        $websiteId = $this->storeManager->getStore()->getWebsiteId();
        $countryId = $weeeTaxRegion['countryId'];
        $regionId = $weeeTaxRegion['regionId'];

        if (!$countryId && !$regionId) {
            // country and region does not exist
            return $proceed($request);
        } else if ($countryId && !$regionId) {
            // country exist and region does not exist
            $regionId = 0;
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
        } else {
            // country and region exist
            $exist = $this->weeeTax->isWeeeInLocation(
                $countryId,
                $regionId,
                $websiteId
            );
            if (!$exist) {
                // just check the country for weee
                $regionId = 0;
                $exist = $this->weeeTax->isWeeeInLocation(
                    $countryId,
                    $regionId,
                    $websiteId
                );
            }
        }

        if ($exist) {
            $this->httpContext->setValue(
                'weee_tax_region',
                ['countryId' => $countryId, 'regionId' => $regionId],
                0
            );
        }
        return $proceed($request);
    }
Esempio n. 26
0
 /**
  * Get url for reorder action
  *
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 public function getReorderUrl($order)
 {
     if (!$this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return $this->getUrl('sales/guest/reorder', array('order_id' => $order->getId()));
     }
     return $this->getUrl('sales/order/reorder', array('order_id' => $order->getId()));
 }
Esempio n. 27
0
 public function testDispatchCurrentStoreCurrency()
 {
     $this->httpContextMock->expects($this->at(0))->method('setValue')->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
     /** Make sure that current currency is taken from current store if no value is provided in session */
     $this->httpContextMock->expects($this->at(1))->method('setValue')->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT);
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
Esempio n. 28
0
 /**
  * Return back title for logged in and guest users
  *
  * @return string
  */
 public function getBackTitle()
 {
     if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return __('Back to My Orders');
     }
     return __('View Another Order');
 }
Esempio n. 29
0
 /**
  * @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);
 }
Esempio n. 30
0
 /**
  * Get default value for From field
  *
  * @return string
  */
 public function getDefaultFrom()
 {
     if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return $this->_customerSession->getCustomer()->getName();
     } else {
         return $this->getEntity()->getBillingAddress()->getName();
     }
 }