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;
    }
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;
    }
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 ; }
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
Creates a new OrderCoupon instance given a Coupon and saves it into the persistence layer .