当前位置: 首页>>代码示例>>PHP>>正文


PHP Http\Context类代码示例

本文整理汇总了PHP中Magento\Framework\App\Http\Context的典型用法代码示例。如果您正苦于以下问题:PHP Context类的具体用法?PHP Context怎么用?PHP Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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());
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:37,代码来源:SwitchAction.php

示例2: getReorderUrl

 /**
  * 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()]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Buttons.php

示例3: getBackTitle

 /**
  * 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');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Invoice.php

示例4: testAroundDispatch

 /**
  * 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));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:ContextPluginTest.php

示例5: aroundDispatch

 /**
  * @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);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:13,代码来源:Context.php

示例6: _toHtml

 /**
  * {@inheritdoc}
  */
 protected function _toHtml()
 {
     if (!$this->_customerHelper->isRegistrationAllowed() || $this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:RegisterLink.php

示例7: _toHtml

 /**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:Link.php

示例8: _toHtml

 /**
  * @return string
  */
 protected function _toHtml()
 {
     if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:Link.php

示例9: _toHtml

 /**
  * {@inheritdoc}
  */
 protected function _toHtml()
 {
     if (!$this->_registration->isAllowed() || $this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return '';
     }
     return parent::_toHtml();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:RegisterLink.php

示例10: aroundDispatch

 /**
  * @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);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:ContextPlugin.php

示例11: getCustomerGroupId

 /**
  * 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Discounts.php

示例12: 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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Context.php

示例13: getWelcome

 /**
  * 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'];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:17,代码来源:Header.php

示例14: testGetCacheKeyInfo

 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());
 }
开发者ID:nja78,项目名称:magento2,代码行数:14,代码来源:ProductsListTest.php

示例15: 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)
 {
     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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:ContextPlugin.php


注:本文中的Magento\Framework\App\Http\Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。