/**
  * Assign the Cart stored in session to the logged Customer.
  *
  * When a user has successfully logged in, a check is needed
  * to see if a Cart was created in session when she was not
  * logged.
  *
  * @param AuthenticationEvent $event Event
  */
 public function onAuthenticationSuccess(AuthenticationEvent $event)
 {
     $loggedUser = $event->getAuthenticationToken()->getUser();
     $cart = $this->cartWrapper->get();
     if ($loggedUser instanceof CustomerInterface && ($cart instanceof CartInterface && $cart->getId())) {
         /*
          * We assume that a cart with an ID is
          * not a pristine entity coming from a
          * factory method. (i.e. has already been
          * flushed)
          */
         $cart->setCustomer($loggedUser);
         $this->cartManager->flush($cart);
     }
 }
Example #2
0
 /**
  * Get total order amount.
  *
  * Money value-object amounts are stored as integers, representing
  * CENTS, so we have to divide by 100 since PaymentBridgeInterface
  * expects a decimal value
  *
  * @return integer
  */
 public function getAmount()
 {
     /**
      * Tweak to allow payment methods to access
      * amount and currency when an order has not
      * been created yet.
      *
      * If there is no order yet we have
      * to pull the amount from the Cart
      */
     if (!$this->order instanceof OrderInterface) {
         return $this->cartWrapper->get()->getAmount()->getAmount();
     }
     $amount = $this->order->getAmount();
     if ($amount instanceof Money) {
         return $this->order->getAmount()->getAmount();
     }
     throw new \LogicException(sprintf('Invalid Amount for Order [%d]', $this->getOrderId()));
 }
Example #3
0
 /**
  * Create order given current cart. This event is only for pushing the new
  * Order to the payment infrastructure
  *
  * @param AbstractPaymentEvent $event Event
  */
 public function transformCartToOrder(AbstractPaymentEvent $event)
 {
     $cart = $this->cartWrapper->get();
     $order = $this->cartOrderTransformer->createOrderFromCart($cart);
     $event->getPaymentBridge()->setOrder($order);
 }