/** * 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()); } }
/** * Remove shipping method from cart if this is not valid anymore * * @param CartOnLoadEvent $event Event * * @return $this Self object */ public function removeInvalidShippingMethod(CartOnLoadEvent $event) { $cart = $event->getCart(); $cartShippingMethodId = $cart->getShippingMethod(); if (null === $cartShippingMethodId) { return $this; } $shippingMethod = $this->shippingWrapper->getOneById($cart, $cartShippingMethodId); if (!$shippingMethod instanceof ShippingMethod) { $cart->setShippingMethod(null); $this->cartEventDispatcher->dispatchCartLoadEvents($cart); $event->stopPropagation(); } return $this; }
/** * 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; }