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


PHP Request::getSession方法代码示例

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


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

示例1: cartFormAfterBuild

 /**
  * Add fields for attribute values selection in our own way (since the product on has its default PSE, it has
  * no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes).
  *
  * @param TheliaFormEvent $event
  */
 public function cartFormAfterBuild(TheliaFormEvent $event)
 {
     $sessionLocale = null;
     $session = $this->request->getSession();
     if ($session !== null) {
         $sessionLang = $session->getLang();
         if ($sessionLang !== null) {
             $sessionLocale = $sessionLang->getLocale();
         }
     }
     $product = ProductQuery::create()->findPk($this->request->getProductId());
     if ($product === null || $product->getTemplate() === null) {
         return;
     }
     $productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find();
     /** @var Attribute $productAttribute */
     foreach ($productAttributes as $productAttribute) {
         $attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId());
         $choices = [];
         /** @var AttributeAv $attributeValue */
         foreach ($attributeValues as $attributeValue) {
             if ($sessionLocale !== null) {
                 $attributeValue->setLocale($sessionLocale);
             }
             $choices[$attributeValue->getId()] = $attributeValue->getTitle();
         }
         $event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]);
     }
 }
开发者ID:bcbrr,项目名称:LegacyProductAttributes,代码行数:35,代码来源:CartAddFormExtension.php

示例2: createOrderProductAttributeCombinations

 /**
  * Save the attribute combinations for the order from our cart item attribute combinations.
  *
  * @param OrderEvent $event
  *
  * @throws PropelException
  */
 public function createOrderProductAttributeCombinations(OrderEvent $event)
 {
     $legacyCartItemAttributeCombinations = LegacyCartItemAttributeCombinationQuery::create()->findByCartItemId($event->getCartItemId());
     // works with Thelia 2.2
     if (method_exists($event, 'getId')) {
         $orderProductId = $event->getId();
     } else {
         // Thelia 2.1 however does not provides the order product id in the event
         // Since the order contains potentially identical (for Thelia) cart items that are only differentiated
         // by the cart item attribute combinations that we are storing ourselves, we cannot use information
         // such as PSE id to cross reference the cart item we are given to the order product that was created from
         // it (as far as I can tell).
         // So we will ASSUME that the order product with the higher id is the one created from this cart item.
         // This is PROBABLY TRUE on a basic Thelia install with no modules messing with the cart and orders in a way
         // that create additional order products, BUT NOT IN GENERAL !
         // This also assumes that ids are generated incrementally, which is NOT GUARANTEED (but true for MySQL
         // with default settings).
         // The creation date was previously used but is even less reliable.
         // FIXME: THIS IS NOT A SANE WAY TO DO THIS
         $orderProductId = OrderProductQuery::create()->orderById(Criteria::DESC)->findOne()->getId();
     }
     $lang = $this->request->getSession()->getLang();
     /** @var LegacyCartItemAttributeCombination $legacyCartItemAttributeCombination */
     foreach ($legacyCartItemAttributeCombinations as $legacyCartItemAttributeCombination) {
         /** @var Attribute $attribute */
         $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $legacyCartItemAttributeCombination->getAttributeId());
         /** @var AttributeAv $attributeAv */
         $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $legacyCartItemAttributeCombination->getAttributeAvId());
         (new OrderProductAttributeCombination())->setOrderProductId($orderProductId)->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save();
     }
 }
开发者ID:bcbrr,项目名称:LegacyProductAttributes,代码行数:38,代码来源:OrderAction.php

示例3: __construct

 public function __construct(Request $request)
 {
     if ($request->getSession() != null) {
         $this->locale = $request->getSession()->getLang()->getLocale();
     } else {
         $this->locale = Lang::getDefaultLanguage()->getLocale();
     }
 }
开发者ID:alex63530,项目名称:thelia,代码行数:8,代码来源:TinyMCELanguage.php

示例4: verifyCreditUsage

 public function verifyCreditUsage(OrderEvent $event)
 {
     $session = $this->request->getSession();
     if ($session->get('creditAccount.used') == 1) {
         $customer = $event->getOrder()->getCustomer();
         $amount = $session->get('creditAccount.amount');
         $creditEvent = new CreditAccountEvent($customer, $amount * -1, $event->getOrder()->getId());
         $creditEvent->setWhoDidIt(Translator::getInstance()->trans('Customer', [], CreditAccount::DOMAIN))->setOrderId($event->getOrder()->getId());
         $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         $session->set('creditAccount.used', 0);
         $session->set('creditAccount.amount', 0);
     }
 }
开发者ID:gillesbourgeat,项目名称:CreditAccount,代码行数:13,代码来源:CreditEventListener.php

示例5: getSession

 /**
  * get the session
  *
  * @return Session
  */
 protected function getSession()
 {
     if (null === $this->session) {
         if (null !== $this->getRequest()) {
             $this->session = $this->request->getSession();
         }
     }
     return $this->session;
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:14,代码来源:BaseHook.php

示例6: delete

 public function delete(LangDeleteEvent $event)
 {
     if (null !== ($lang = LangQuery::create()->findPk($event->getLangId()))) {
         if ($lang->getByDefault()) {
             throw new \RuntimeException(Translator::getInstance()->trans('It is not allowed to delete the default language'));
         }
         $lang->setDispatcher($event->getDispatcher())->delete();
         $session = $this->request->getSession();
         // If we've just deleted the current admin edition language, set it to the default one.
         if ($lang->getId() == $session->getAdminEditionLang()->getId()) {
             $session->setAdminEditionLang(LangModel::getDefaultLanguage());
         }
         // If we've just deleted the current admin language, set it to the default one.
         if ($lang->getId() == $session->getLang()->getId()) {
             $session->setLang(LangModel::getDefaultLanguage());
         }
         $event->setLang($lang);
     }
 }
开发者ID:margery,项目名称:thelia,代码行数:19,代码来源:Lang.php

示例7: cleanOutdatedFormErrorInformation

 /**
  * Remove obsolete form error information.
  */
 protected function cleanOutdatedFormErrorInformation()
 {
     $formErrorInformation = $this->request->getSession()->getFormErrorInformation();
     if (!empty($formErrorInformation)) {
         $now = time();
         // Cleanup obsolete form information, and try to find the form data
         foreach ($formErrorInformation as $name => $formData) {
             if ($now - $formData['timestamp'] > self::FORM_ERROR_LIFETIME_SECONDS) {
                 unset($formErrorInformation[$name]);
             }
         }
         $this->request->getSession()->setFormErrorInformation($formErrorInformation);
     }
     return $this;
 }
开发者ID:jeremyFreeAgent,项目名称:thelia,代码行数:18,代码来源:ParserContext.php

示例8: addCustomerFamilyFieldsForUpdate

 /**
  * Callback used to add some fields to the Thelia's CustomerCreateForm.
  * It add two fields : one for the SIRET number and one for VAT.
  * @param TheliaFormEvent $event
  */
 public function addCustomerFamilyFieldsForUpdate(TheliaFormEvent $event)
 {
     // Adding new fields
     $customer = $this->request->getSession()->getCustomerUser();
     if (is_null($customer)) {
         // No customer => no account update => stop here
         return;
     }
     $customerCustomerFamily = CustomerCustomerFamilyQuery::create()->findOneByCustomerId($customer->getId());
     $cfData = array(self::CUSTOMER_FAMILY_CODE_FIELD_NAME => (is_null($customerCustomerFamily) or is_null($customerCustomerFamily->getCustomerFamily())) ? '' : $customerCustomerFamily->getCustomerFamily()->getCode(), self::CUSTOMER_FAMILY_SIRET_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getSiret(), self::CUSTOMER_FAMILY_VAT_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getVat());
     // Retrieving CustomerFamily choices
     $customerFamilyChoices = array();
     /** @var \CustomerFamily\Model\CustomerFamily $customerFamilyChoice */
     foreach (CustomerFamilyQuery::create()->find() as $customerFamilyChoice) {
         $customerFamilyChoices[$customerFamilyChoice->getCode()] = self::trans($customerFamilyChoice->getTitle());
     }
     // Building additional fields
     $event->getForm()->getFormBuilder()->add(self::CUSTOMER_FAMILY_CODE_FIELD_NAME, 'choice', array('constraints' => array(new Constraints\Callback(array('methods' => array(array($this, 'checkCustomerFamily')))), new Constraints\NotBlank()), 'choices' => $customerFamilyChoices, 'empty_data' => false, 'required' => false, 'label' => self::trans('Customer family'), 'label_attr' => array('for' => 'customer_family_id'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_CODE_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_SIRET_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Siret number'), 'label_attr' => array('for' => 'siret'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_SIRET_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_VAT_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Vat'), 'label_attr' => array('for' => 'vat'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_VAT_FIELD_NAME]));
 }
开发者ID:bcbrr,项目名称:CustomerFamily,代码行数:24,代码来源:CustomerFamilyFormListener.php

示例9: performCheck

 /**
  * Check if the current user is granted access to a ressource.
  *
  * @param string|array $resources Resource name or resources list.
  * @param string|array $accesses  Access name or accesses list.
  * @param boolean      $accessOr  Whether to return true if at least one resource/access couple is granted.
  *
  * @return boolean Whether access is granted.
  */
 protected function performCheck($resources, $accesses, $accessOr = false)
 {
     /** @var Session $session */
     $session = $this->request->getSession();
     if ($session->getCustomerUser() === null || $session->has(CustomerGroup::getModuleCode()) === false) {
         return false;
     }
     $accessIdsList = [];
     foreach ($accesses as $access) {
         $accessIdsList[] = CustomerGroupAclAccessManager::getAccessPowsValue(strtoupper(trim($access)));
     }
     $accessIdsList = array_unique($accessIdsList);
     $groupId = $this->request->getSession()->get(CustomerGroup::getModuleCode())['id'];
     // For each acl be sure that the current customer has the right access
     $query = CustomerGroupAclQuery::create()->filterByActivate(1)->filterByCustomerGroupId($groupId)->filterByType($accessIdsList, Criteria::IN)->useAclQuery()->filterByCode($resources, Criteria::IN)->endUse();
     $rights = $query->count();
     $askedRights = count($resources) * count($accessIdsList);
     return $accessOr === true && $rights > 0 || $rights === $askedRights;
 }
开发者ID:MaximeMorille,项目名称:CustomerGroupAcl,代码行数:28,代码来源:CustomerGroupAclTool.php

示例10: afterOrder

 /**
  * @param \Thelia\Core\Event\Order\OrderEvent $event
  *
  * @throws \Exception if something goes wrong.
  */
 public function afterOrder(OrderEvent $event)
 {
     /** @var CouponInterface[] $consumedCoupons */
     $consumedCoupons = $this->couponManager->getCouponsKept();
     if (is_array($consumedCoupons) && count($consumedCoupons) > 0) {
         $con = Propel::getWriteConnection(OrderCouponTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             foreach ($consumedCoupons as $couponCode) {
                 $couponQuery = CouponQuery::create();
                 $couponModel = $couponQuery->findOneByCode($couponCode->getCode());
                 $couponModel->setLocale($this->request->getSession()->getLang()->getLocale());
                 /* decrease coupon quantity */
                 $this->couponManager->decrementQuantity($couponModel, $event->getOrder()->getCustomerId());
                 /* memorize coupon */
                 $orderCoupon = new OrderCoupon();
                 $orderCoupon->setOrder($event->getOrder())->setCode($couponModel->getCode())->setType($couponModel->getType())->setAmount($couponModel->getAmount())->setTitle($couponModel->getTitle())->setShortDescription($couponModel->getShortDescription())->setDescription($couponModel->getDescription())->setExpirationDate($couponModel->getExpirationDate())->setIsCumulative($couponModel->getIsCumulative())->setIsRemovingPostage($couponModel->getIsRemovingPostage())->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())->setSerializedConditions($couponModel->getSerializedConditions())->setPerCustomerUsageCount($couponModel->getPerCustomerUsageCount());
                 $orderCoupon->save();
                 // Copy order coupon free shipping data for countries and modules
                 $couponCountries = CouponCountryQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponCountry $couponCountry */
                 foreach ($couponCountries as $couponCountry) {
                     $occ = new OrderCouponCountry();
                     $occ->setCouponId($orderCoupon->getId())->setCountryId($couponCountry->getCountryId())->save();
                 }
                 $couponModules = CouponModuleQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponModule $couponModule */
                 foreach ($couponModules as $couponModule) {
                     $ocm = new OrderCouponModule();
                     $ocm->setCouponId($orderCoupon->getId())->setModuleId($couponModule->getModuleId())->save();
                 }
             }
             $con->commit();
         } catch (\Exception $ex) {
             $con->rollBack();
             throw $ex;
         }
     }
     // Clear all coupons.
     $event->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
 }
开发者ID:bobanmilano,项目名称:thelia,代码行数:46,代码来源:Coupon.php

示例11: __construct

 public function __construct(Request $request, TokenProvider $tokenProvider)
 {
     $this->request = $request;
     $this->session = $request->getSession();
     $this->tokenProvider = $tokenProvider;
 }
开发者ID:margery,项目名称:thelia,代码行数:6,代码来源:Cart.php

示例12: getOrder

 public function getOrder(Request $request)
 {
     $session = $request->getSession();
     if (null !== ($order = $session->getOrder())) {
         return $order;
     }
     $order = new Order();
     $session->setOrder($order);
     return $order;
 }
开发者ID:margery,项目名称:thelia,代码行数:10,代码来源:OrderController.php

示例13: getSession

 /**
  * Returns the session from the current request
  *
  * @return \Thelia\Core\HttpFoundation\Session\Session
  */
 protected function getSession()
 {
     return $this->request->getSession();
 }
开发者ID:badelas,项目名称:thelia,代码行数:9,代码来源:Order.php

示例14: manageLocale

 protected function manageLocale(RewritingResolver $rewrittenUrlData, TheliaRequest $request)
 {
     $lang = LangQuery::create()->findOneByLocale($rewrittenUrlData->locale);
     $langSession = $request->getSession()->getLang();
     if ($lang != $langSession) {
         if (ConfigQuery::isMultiDomainActivated()) {
             $this->redirect(sprintf("%s/%s", $lang->getUrl(), $rewrittenUrlData->rewrittenUrl));
         } else {
             $request->getSession()->setLang($lang);
         }
     }
 }
开发者ID:margery,项目名称:thelia,代码行数:12,代码来源:RewritingRouter.php

示例15: __construct

 public function __construct(Request $request)
 {
     $this->locale = $request->getSession()->getLang()->getLocale();
 }
开发者ID:fachriza,项目名称:thelia,代码行数:4,代码来源:TinyMCELanguage.php


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