/** * Purge existing OrderCoupons * * @param OrderInterface $order Order where to delete all coupons * * @return $this Self object */ private function truncateOrderCoupons(OrderInterface $order) { $orderCoupons = $this->orderCouponManager->getOrderCoupons($order); if ($orderCoupons instanceof Collection) { foreach ($orderCoupons as $orderCoupon) { $this->orderCouponObjectManager->remove($orderCoupon); } $this->orderCouponObjectManager->flush($orderCoupons->toArray()); } return $this; }
/** * 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())); } }