/**
  * Creates a new OrderCoupon instance given a Coupon and saves it into the
  * persistence layer.
  *
  * Also notifies to CouponBundle that a simple coupon has been
  * used by an Order.
  *
  * @param OrderInterface  $order  Order
  * @param CouponInterface $coupon Coupon
  *
  * @return OrderCouponInterface Order coupon created
  */
 public function createOrderCouponByCoupon(OrderInterface $order, CouponInterface $coupon)
 {
     $orderCoupon = $this->orderCouponFactory->create()->setOrder($order)->setCoupon($coupon)->setAmount($coupon->getAbsolutePrice())->setName($coupon->getName())->setCode($coupon->getCode());
     $this->orderCouponObjectManager->persist($orderCoupon);
     $this->orderCouponObjectManager->flush($orderCoupon);
     $this->couponEventDispatcher->notifyCouponUsage($coupon);
     return $orderCoupon;
 }
 /**
  * Event subscribed on OrderCoupon applied into an order.
  *
  * Just should create a new OrderCoupon instance, persist and flush it
  *
  * Also notifies to CouponBundle that a simple coupon has been
  * used by an Order.
  *
  * @param OrderCouponOnApplyEvent $event Event
  */
 public function convertToOrderCoupons(OrderCouponOnApplyEvent $event)
 {
     $order = $event->getOrder();
     $coupon = $event->getCoupon();
     $orderCoupon = $this->orderCouponFactory->create()->setOrder($order)->setCoupon($coupon)->setAmount($coupon->getAbsolutePrice())->setName($coupon->getName())->setCode($coupon->getCode());
     $this->orderCouponObjectManager->persist($orderCoupon);
     $this->orderCouponObjectManager->flush($orderCoupon);
     $event->setOrderCoupon($orderCoupon);
     $this->couponEventDispatcher->notifyCouponUsage($coupon);
 }