/**
  * A new Order has been created.
  *
  * This method adds Coupon logic in this transformation
  *
  * @param CartInterface  $cart  Cart
  * @param OrderInterface $order Order
  */
 public function createOrderCouponsByCartCoupons(CartInterface $cart, OrderInterface $order)
 {
     $cartCouponAmount = $cart->getCouponAmount();
     if ($cartCouponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($cartCouponAmount);
     }
     /**
      * @var CouponInterface $coupons
      */
     $coupons = $this->cartCouponManager->getCoupons($cart);
     if (empty($coupons)) {
         return;
     }
     /**
      * Before applying Coupons to Order, we should remove old references
      * if exist.
      */
     $this->orderCouponTruncator->truncateOrderCoupons($order);
     /**
      * An event is dispatched for each convertible coupon.
      */
     foreach ($coupons as $coupon) {
         $this->orderCouponEventDispatcher->dispatchOrderCouponOnApplyEvent($order, $coupon);
     }
 }
 /**
  * Performs all processes to be performed after the order creation.
  *
  * Flushes all loaded order and related entities.
  *
  * @param CartInterface  $cart  Cart
  * @param OrderInterface $order Order
  *
  * @return $this Self object
  */
 public function loadOrderShippingMethod(CartInterface $cart, OrderInterface $order)
 {
     $shippingMethodId = $cart->getShippingMethod();
     if (empty($shippingMethodId)) {
         return $this;
     }
     $shippingMethod = $this->shippingWrapper->getOneById($cart, $shippingMethodId);
     if ($shippingMethod instanceof ShippingMethod) {
         $order->setShippingAmount($shippingMethod->getPrice());
         $order->setShippingMethod($shippingMethod);
     }
 }
 /**
  * test createFromCart method
  *
  * @group order
  */
 public function testCreateOrderFromCart()
 {
     $orderInitialState = $this->getParameter('elcodi.core.cart.order_initial_state');
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderInterface', $this->order);
     $this->assertSame($this->order->getCart(), $this->cart);
     $this->assertTrue($this->cart->isOrdered());
     $this->assertCount(2, $this->order->getOrderLines());
     $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $this->order->getLastOrderHistory());
     $this->assertEquals($this->order->getLastOrderHistory()->getState(), $orderInitialState);
     $orderHistories = $this->order->getOrderHistories();
     /**
      * @var OrderHistoryInterface $orderHistory
      */
     foreach ($orderHistories as $orderHistory) {
         $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\OrderHistoryInterface', $orderHistory);
         $this->assertEquals($orderHistory->getState(), $orderInitialState);
     }
     $this->getObjectManager('order')->clear();
     $this->assertCount(1, $this->findAll('order'));
 }
Beispiel #4
0
 /**
  * Given existent Order, returns if go to new state is permitted.
  *
  * @param OrderInterface $order Order
  * @param string         $state New state
  *
  * @return boolean Order can change to desired state
  */
 public function checkOrderCanChangeToState(OrderInterface $order, $state)
 {
     $lastOrderHistoryState = $order->getLastOrderHistory();
     if (!$this->orderStateManager->isOrderStateChangePermitted($lastOrderHistoryState->getState(), $state)) {
         return false;
     }
     return $order->getOrderLines()->forAll(function ($_, OrderLineInterface $orderLine) use($state) {
         return $this->orderLineManager->checkOrderLineCanChangeToState($orderLine, $state);
     });
 }
Beispiel #5
0
 /**
  * Edit and Saves order
  *
  * @param OrderInterface $order Order
  *
  * @return array Data
  *
  * @Route(
  *      path = "/{id}",
  *      name = "admin_order_edit",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET"}
  * )
  * @Template
  *
  * @EntityAnnotation(
  *      class = "elcodi.entity.order.class",
  *      name = "order",
  *      mapping = {
  *          "id" = "~id~"
  *      }
  * )
  */
 public function editAction(OrderInterface $order)
 {
     $nextPaymentTransitions = $this->get('elcodi.order.payment_states_machine')->getAvailableStates($order->getPaymentStateLineStack()->getLastStateLine()->getName());
     $nextShippingTransitions = $this->get('elcodi.order.shipping_states_machine')->getAvailableStates($order->getShippingStateLineStack()->getLastStateLine()->getName());
     $allStates = array_merge($order->getPaymentStateLineStack()->getStateLines()->toArray(), $order->getShippingStateLineStack()->getStateLines()->toArray());
     usort($allStates, function (StateLineInterface $a, StateLineInterface $b) {
         return $a->getCreatedAt() == $b->getCreatedAt() ? $a->getId() > $b->getId() : $a->getCreatedAt() > $b->getCreatedAt();
     });
     $addressFormatter = $this->get('elcodi.formatter.address');
     $deliveryAddress = $order->getDeliveryAddress();
     $deliveryInfo = $addressFormatter->toArray($deliveryAddress);
     $billingAddress = $order->getBillingAddress();
     $billingInfo = $addressFormatter->toArray($billingAddress);
     return ['order' => $order, 'nextPaymentTransitions' => $nextPaymentTransitions, 'nextShippingTransitions' => $nextShippingTransitions, 'allStates' => $allStates, 'deliveryInfo' => $deliveryInfo, 'billingInfo' => $billingInfo];
 }
Beispiel #6
0
 /**
  * Checkout payment fail action
  *
  * @param CustomerInterface $customer Customer
  * @param OrderInterface    $order    Order
  *
  * @throws AccessDeniedException Customer cannot see this Order
  *
  * @return array
  *
  * @Route(
  *      path = "/payment/fail/order/{id}",
  *      name = "store_checkout_payment_fail",
  *      methods = {"GET"}
  * )
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "elcodi.wrapper.customer",
  *          "method" = "get",
  *          "static" = false
  *      },
  *      name = "customer",
  * )
  * @EntityAnnotation(
  *      class = "elcodi.entity.order.class",
  *      name = "order",
  *      mapping = {
  *          "id" = "~id~",
  *      }
  * )
  */
 public function paymentFailAction(CustomerInterface $customer, OrderInterface $order)
 {
     /**
      * Checking if logged user has permission to see
      * this page
      */
     if ($order->getCustomer() != $customer) {
         throw $this->createAccessDeniedException();
     }
     return $this->renderTemplate('Pages:checkout-payment-fail.html.twig', ['order' => $order]);
 }