/** * Performs all processes to be performed after the order creation. * * Flushes all loaded order and related entities. * * @param CartInterface $cart Cart */ public function loadCartShippingAmount(CartInterface $cart) { $shippingMethodId = $cart->getShippingMethod(); if (empty($shippingMethodId)) { return; } $shippingMethod = $this->shippingWrapper->getOneById($cart, $shippingMethodId); if ($shippingMethod instanceof ShippingMethod) { $cart->setShippingAmount($shippingMethod->getPrice()); } }
/** * Performs all processes to be performed after the order creation * * Flushes all loaded order and related entities. * * @param CartOnLoadEvent $event Event * * @return $this Self object */ public function loadShippingPrice(CartOnLoadEvent $event) { $cart = $event->getCart(); $shippingMethodId = $cart->getShippingMethod(); if (empty($shippingMethodId)) { return $this; } $shippingMethod = $this->shippingWrapper->getOneById($cart, $shippingMethodId); if ($shippingMethod instanceof ShippingMethod) { $cartAmount = $cart->getAmount(); $convertedShippingAmount = $this->currencyConverter->convertMoney($shippingMethod->getPrice(), $cartAmount->getCurrency()); $cart->setAmount($cartAmount->add($convertedShippingAmount)); } return $this; }
/** * Performs all processes to be performed after the order creation * * Flushes all loaded order and related entities. * * @param OrderOnCreatedEvent $event Event * * @return $this Self object */ public function saveOrder(OrderOnCreatedEvent $event) { $cart = $event->getCart(); $shippingMethodId = $cart->getShippingMethod(); if (empty($shippingMethodId)) { return $this; } $shippingMethod = $this->shippingWrapper->getOneById($cart, $shippingMethodId); $order = $event->getOrder(); if ($shippingMethod instanceof ShippingMethod) { $order->setShippingAmount($shippingMethod->getPrice()); $order->setShippingMethod($shippingMethod); } return $this; }
/** * Loads cheapest shipping method if exists * * @param CartOnLoadEvent $event Event * * @return $this Self object */ public function loadCheapestShippingMethod(CartOnLoadEvent $event) { $cart = $event->getCart(); $cartShippingMethodId = $cart->getShippingMethod(); /** * We don't have the need to find the cheapest one if the real one is * already defined */ if (null !== $cartShippingMethodId) { return $this; } /** * If the cart is not associated to any customer, just skip it */ if (!$cart->getCustomer() instanceof CustomerInterface) { return $this; } $address = $cart->getDeliveryAddress() instanceof AddressInterface ? $cart->getDeliveryAddress() : $cart->getCustomer()->getAddresses()->first(); /** * If the user does'nt have any address defined, we cannot approximate * anything */ if (!$address instanceof AddressInterface) { return $this; } $cart->setDeliveryAddress($address); $validShippingMethods = $this->shippingWrapper->get($cart); if (!empty($validShippingMethods)) { $cheapestShippingMethod = $this->shippingResolver->getCheapestShippingMethod($validShippingMethods); $cart->setCheapestShippingMethod($cheapestShippingMethod->getId()); } return $this; }