Example #1
0
 public function setUp()
 {
     $this->requestStack = new RequestStack();
     $request = new Request();
     $this->requestStack->push($request);
     $this->session = new Session(new MockArraySessionStorage());
     $request->setSession($this->session);
     $this->dispatcher = new EventDispatcher();
     $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'));
     $token = new TokenProvider($this->requestStack, $translator, 'test');
     $this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token));
     $this->session->setSessionCart(null);
     $request->setSession($this->session);
     /** @var \Thelia\Action\Cart  cartAction */
     $this->cartAction = new \Thelia\Action\Cart($this->requestStack, new TokenProvider($this->requestStack, $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) {
         if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
             $this->cartAction->restoreCurrentCart($event, null, $this->dispatcher);
         } elseif ($type == TheliaEvents::CART_CREATE_NEW) {
             $this->cartAction->createEmptyCart($event, null, $this->dispatcher);
         }
     }));
 }
Example #2
0
 public function persistCart(CartPersistEvent $event)
 {
     $cart = $event->getCart();
     if ($cart->isNew()) {
         $cart->setToken($this->generateCartCookieIdentifier())->save();
         $this->session->setSessionCart($cart);
     }
 }
Example #3
0
 /**
  * Create a new, empty cart object, and assign it to the current customer, if any.
  *
  * @param CartCreateEvent $cartCreateEvent
  */
 public function createEmptyCart(CartCreateEvent $cartCreateEvent)
 {
     $cart = new CartModel();
     $cart->setCurrency($this->session->getCurrency(true));
     if (null !== ($customer = $this->session->getCustomerUser())) {
         $cart->setCustomer(CustomerQuery::create()->findPk($customer->getId()));
     }
     $this->session->setSessionCart($cart);
     if (ConfigQuery::read("cart.use_persistent_cookie", 1) == 1) {
         // set cart_use_cookie to "" to remove the cart cookie
         // see Thelia\Core\EventListener\ResponseListener
         $this->session->set("cart_use_cookie", "");
     }
     $cartCreateEvent->setCart($cart);
 }