/** * A new Order has been created. * * This method adds Coupon logic in this transformation * * @param OrderOnCreatedEvent $orderOnCreatedEvent OrderOnCreated Event * * @return null */ public function convertCouponToOrder(OrderOnCreatedEvent $orderOnCreatedEvent) { $order = $orderOnCreatedEvent->getOrder(); $cart = $orderOnCreatedEvent->getCart(); $cartCouponAmount = $cart->getCouponAmount(); if ($cartCouponAmount instanceof MoneyInterface) { $order->setCouponAmount($cartCouponAmount); } /** * @var CouponInterface[]|Collection $coupons */ $coupons = $this->cartCouponManager->getCoupons($cart); if ($coupons->isEmpty()) { return null; } /** * Before applying Coupons to Order, we should remove old references * if exist. Otherwise, */ $this->truncateOrderCoupons($order); /** * An event is dispatched for each convertible coupon */ foreach ($coupons as $coupon) { $this->orderCouponEventDispatcher->dispatchOrderCouponOnApplyEvent($order, $coupon); } }
/** * Create metrics about the order creation * * @param OrderOnCreatedEvent $event Event */ public function addMetric(OrderOnCreatedEvent $event) { $storeTracker = $this->store->getTracker(); $this->metricManager->addEntry($storeTracker, 'order_nb', '0', ElcodiMetricTypes::TYPE_BEACON_ALL, new DateTime()); $orderAmount = $event->getOrder()->getAmount()->getAmount(); $this->metricManager->addEntry($storeTracker, 'order_total', $orderAmount, ElcodiMetricTypes::TYPE_ACCUMULATED, new DateTime()); }
/** * 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; }
/** * After an Order is created, the cart is set as Ordered enabling related * flag * * @param OrderOnCreatedEvent $event Event */ public function setCartAsOrdered(OrderOnCreatedEvent $event) { $cart = $event->getCart()->setOrdered(true); $this->cartObjectManager->flush($cart); }
/** * Load cart shipping amount * * @param OrderOnCreatedEvent $event Event */ public function loadOrderShippingMethod(OrderOnCreatedEvent $event) { $this->orderShippingMethodLoader->loadOrderShippingMethod($event->getCart(), $event->getOrder()); }
/** * Performs all processes to be performed after the order creation * * Flushes all loaded order and related entities. * * @param OrderOnCreatedEvent $event Event */ public function onOrderCreated(OrderOnCreatedEvent $event) { $order = $event->getOrder(); $this->orderObjectManager->persist($order); $this->orderObjectManager->flush(); }
/** * Method triggered when a customer purchases a cart * * This listener just creates new Coupon if do not exists and if needs to be * generated * * @param OrderOnCreatedEvent $event Event */ public function onOrderCreated(OrderOnCreatedEvent $event) { /** * @var Cookie $cookie * @var CustomerInterface $customer */ $customer = $event->getOrder()->getCustomer(); if ($this->request instanceof Request) { $hash = $this->getReferralProgramCookieHash(); $this->referralCouponManager->checkCouponAssignment($customer, $hash, ElcodiReferralProgramRuleTypes::TYPE_ON_FIRST_PURCHASE)->checkCouponsUsed($customer, $this->orderCouponManager->getOrderCoupons($event->getOrder())); } }
/** * A new Order has been created. * * @param OrderOnCreatedEvent $event OrderOnCreated Event */ public function createOrderCouponsByCartCoupons(OrderOnCreatedEvent $event) { $this->cartCouponToOrderTransformer->createOrderCouponsByCartCoupons($event->getCart(), $event->getOrder()); }
/** * Send email * * @param OrderOnCreatedEvent $event Event */ public function sendOrderConfirmationEmail(OrderOnCreatedEvent $event) { $order = $event->getOrder(); $customer = $order->getCustomer(); $this->sendEmail('order_confirmation', ['order' => $order, 'customer' => $customer], $customer->getEmail()); }