Beispiel #1
0
 /**
  * Generate the cart cookie identifier, or return null if the cart is only managed in the session object,
  * not in a client cookie.
  *
  * @return string
  */
 protected function generateCartCookieIdentifier()
 {
     $id = null;
     if (ConfigQuery::read("cart.use_persistent_cookie", 1) == 1) {
         $id = $this->tokenProvider->getToken();
         $this->session->set('cart_use_cookie', $id);
     }
     return $id;
 }
Beispiel #2
0
 public function setUp()
 {
     $this->request = new Request();
     $this->session = new Session(new MockArraySessionStorage());
     $this->session->setSessionCart(null);
     $this->request->setSession($this->session);
     $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'));
     $this->cartAction = new \Thelia\Action\Cart($this->request, new TokenProvider($this->request, $translator, 'baba au rhum'));
     $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false);
     $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) {
         $event->setDispatcher($this->dispatcher);
         if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
             $this->cartAction->restoreCurrentCart($event);
         } elseif ($type == TheliaEvents::CART_CREATE_NEW) {
             $this->cartAction->createEmptyCart($event);
         }
     }));
 }
 /**
  * @return array
  *
  * At least one element will be present within the array.
  * Potential keys within this array are:
  * scheme - e.g. http
  * host
  * port
  * user
  * pass
  * path
  * query - after the question mark ?
  * fragment - after the hashmark #
  */
 protected function getParseUrlByCurrentLocale()
 {
     // for one domain by lang
     if ((int) ConfigQuery::read('one_domain_foreach_lang', 0) === 1) {
         // $langUrl = $this->session->getLang()->getUrl();
         $langUrl = LangQuery::create()->findOneByLocale($this->session->getLang()->getLocale())->getUrl();
         if (!empty($langUrl) && false !== ($parse = parse_url($langUrl))) {
             return $parse;
         }
     }
     // return config url site
     $urlSite = ConfigQuery::read('url_site');
     if (!empty($urlSite) && false !== ($parse = parse_url($urlSite))) {
         return $parse;
     }
     // return current host
     return parse_url($this->request->getUri());
 }
 protected function applyUserLocale(UserInterface $user, Session $session)
 {
     // Set the current language according to locale preference
     $locale = $user->getLocale();
     if (null === ($lang = LangQuery::create()->findOneByLocale($locale))) {
         $lang = Lang::getDefaultLanguage();
     }
     $session->setLang($lang);
 }
 /**
  * covers RewritingRouter::matchRequest
  */
 public function testMatchRequestWithDifferentLocaleAndDomain()
 {
     ConfigQuery::write('rewriting_enable', 1);
     ConfigQuery::write('one_domain_foreach_lang', 1);
     $defaultLang = LangQuery::create()->findOneByLocale('en_US');
     $defaultLang->setUrl('http://test_en.com');
     $frenchLang = LangQuery::create()->findOneByLocale('fr_FR');
     $saveUrl = $frenchLang->getUrl();
     $frenchLang->setUrl('http://test.com')->save();
     $product = ProductQuery::create()->findOne();
     $product->setLocale($defaultLang->getLocale());
     $rewriting = RewritingUrlQuery::create()->filterByView('product')->filterByViewId($product->getId())->filterByViewLocale('fr_FR')->filterByRedirected(null)->findOne();
     $request = Request::create('http://test_en.com/' . $rewriting->getUrl());
     $session = new Session(new MockArraySessionStorage());
     $session->setLang($defaultLang);
     $request->setSession($session);
     $url = new URL();
     $requestContext = new RequestContext();
     $requestContext->fromRequest($request);
     $url->setRequestContext($requestContext);
     try {
         $rewritingRouter = new RewritingRouter();
         $parameters = $rewritingRouter->matchRequest($request);
     } catch (RedirectException $e) {
         $this->assertRegExp("/http:\\/\\/test\\.com\\/.*/", $e->getUrl());
         return;
     }
     $this->fail('->matchRequest must throw a RedirectException');
 }
Beispiel #6
0
 public function testGetAdminEditionCurrencyWithNoCurrencyInSession()
 {
     $session = new Session(new MockArraySessionStorage());
     $this->assertInstanceOf('Thelia\\Model\\Currency', $session->getAdminEditionCurrency());
 }
Beispiel #7
0
 protected function generateCookie(Session $session)
 {
     $id = null;
     if (ConfigQuery::read("cart.session_only", 0) == 0) {
         $id = uniqid('', true);
         $session->set('cart_use_cookie', $id);
     }
     return $id;
 }