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


PHP Context::setValue方法代码示例

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


在下文中一共展示了Context::setValue方法的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: 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

示例3: 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

示例4: testSendVary

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

示例5: testGetData

 public function testGetData()
 {
     $this->object->setValue('key1', 'value1', 'default1');
     $this->object->setValue('key2', 'value2', 'default2');
     $this->object->setValue('key3', 'value3', 'value3');
     $this->object->unsValue('key1');
     $this->assertEquals(['key2' => 'value2'], $this->object->getData());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:8,代码来源:ContextTest.php

示例6: testGetVaryString

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

示例7: 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

示例8: 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

示例9: aroundExecute

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

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

示例11: setCustomerDataAsLoggedIn

 /**
  * @param CustomerData $customer
  * @return $this
  */
 public function setCustomerDataAsLoggedIn($customer)
 {
     $this->_httpContext->setValue(Context::CONTEXT_AUTH, true, false);
     $this->setCustomerData($customer);
     $customerModel = $this->_customerFactory->create()->updateData($customer);
     $this->setCustomer($customerModel);
     $this->_eventManager->dispatch('customer_login', ['customer' => $customerModel]);
     $this->_eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Session.php

示例12: _checkRequestStore

 /**
  * @param \Magento\Store\Model\StoreManagerInterface $storage
  * @param string $scopeType
  * @return void
  */
 protected function _checkRequestStore(\Magento\Store\Model\StoreManagerInterface $storage, $scopeType)
 {
     $storeCode = $this->request->getParam('___store');
     if (empty($storeCode)) {
         return;
     }
     if (!$this->setCurrentStore($storage, $storeCode, $scopeType)) {
         return;
     }
     if ($storage->getStore()->getCode() == $storeCode) {
         $store = $storage->getStore($storeCode);
         if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) {
             $this->_cookie->set(Store::COOKIE_NAME, null);
         } else {
             $this->_cookie->set(Store::COOKIE_NAME, $storage->getStore()->getCode(), true);
             $this->_httpContext->setValue(Store::ENTITY, $storage->getStore()->getCode(), \Magento\Store\Model\Store::DEFAULT_CODE);
         }
     }
     return;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:25,代码来源:StorageFactory.php

示例13: _checkRequestStore

 /**
  * @param \Magento\Store\Model\StoreManagerInterface $storage
  * @param string $scopeType
  * @return void
  */
 protected function _checkRequestStore(\Magento\Store\Model\StoreManagerInterface $storage, $scopeType)
 {
     $storeCode = $this->request->getParam('___store');
     if (empty($storeCode)) {
         return;
     }
     if (!$this->setCurrentStore($storage, $storeCode, $scopeType)) {
         return;
     }
     if ($storage->getStore()->getCode() == $storeCode) {
         $store = $storage->getStore($storeCode);
         if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) {
             $this->_cookieManager->deleteCookie(Store::COOKIE_NAME);
         } else {
             $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear();
             $this->_cookieManager->setPublicCookie(Store::COOKIE_NAME, $storage->getStore()->getCode(), $publicCookieMetadata);
             $this->_httpContext->setValue(Store::ENTITY, $storage->getStore()->getCode(), \Magento\Store\Model\Store::DEFAULT_CODE);
         }
     }
     return;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:26,代码来源:StorageFactory.php

示例14: testGetWelcomeLoggedIn

 /**
  * Test welcome message when customer is logged in
  */
 public function testGetWelcomeLoggedIn()
 {
     $this->context->setValue(Context::CONTEXT_AUTH, true, false);
     $this->assertEquals('Welcome, John Smith!', $this->block->getWelcome());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:8,代码来源:HeaderTest.php

示例15: setCurrentCurrencyCode

 /**
  * Set current store currency code
  *
  * @param   string $code
  * @return  string
  */
 public function setCurrentCurrencyCode($code)
 {
     $code = strtoupper($code);
     if (in_array($code, $this->getAvailableCurrencyCodes())) {
         $this->_getSession()->setCurrencyCode($code);
         $defaultCode = $this->_storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode();
         $this->_httpContext->setValue(Context::CONTEXT_CURRENCY, $code, $defaultCode);
     }
     return $this;
 }
开发者ID:mrbadao,项目名称:magento-ce,代码行数:16,代码来源:Store.php


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