Dispatch event just before a coupon is applied into an Order.

@param OrderInterface  $cart   Cart where to apply the coupon
@param CouponInterface $coupon Coupon to be applied

@return $this Self object
347516
public function dispatchOrderCouponOnApplyEvent(
        OrderInterface $cart,
        CouponInterface $coupon
    ) {
        $event = new OrderCouponOnApplyEvent(
            $cart,
            $coupon
        );

        $this->eventDispatcher->dispatch(
            ElcodiCartCouponEvents::ORDER_COUPON_ONAPPLY,
            $event
        );
    }
1062819
public function applyCoupon($coupon, $subscription = 'default', $removeOthers = false)
    {
        $subscription = $this->subscription($subscription);

        if (! $subscription) {
            throw new InvalidArgumentException('Unable to apply coupon. Subscription does not exist.');
        }

        $subscription->applyCoupon($coupon, $removeOthers);
    }
271187
public function dispatchPaymentCollectionEvent(CartInterface $cart = null)
    {
        $event = new PaymentCollectionEvent($cart);

        $this
            ->eventDispatcher
            ->dispatch(
                ElcodiPaymentEvents::PAYMENT_COLLECT,
                $event
            );

        return $event->getPaymentMethods();
    }
758529
public function updateCondition(CouponCreateOrUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $modelCoupon = $event->getCouponModel();

        $this->createOrUpdateCondition($modelCoupon, $event, $dispatcher);
    }
979065
public void cart_cartId_coupon_DELETE(String cartId, String coupon) throws IOException {
		String qPath = "/order/cart/{cartId}/coupon";
		StringBuilder sb = path(qPath, cartId);
		query(sb, "coupon", coupon);
		execN(qPath, "DELETE", sb.toString(), null);
	}
689149
public function dispatchShippingCollectionEvent(CartInterface $cart)
    {
        $event = new ShippingCollectionEvent($cart);

        $this
            ->eventDispatcher
            ->dispatch(
                ElcodiShippingEvents::SHIPPING_COLLECT,
                $event
            );

        return $event->getShippingMethods();
    }
1249088
public function removeCouponByCode(
        CartInterface $cart,
        $couponCode
    ) {
        $coupon = $this
            ->couponRepository
            ->findOneBy([
                'code' => $couponCode,
            ]);

        if (!($coupon instanceof CouponInterface)) {
            return false;
        }

        return $this
            ->removeCoupon(
                $cart,
                $coupon
            );
    }
91712
public function tryAutomaticCoupons(CartInterface $cart)
    {
        if ($cart->getCartLines()->isEmpty()) {
            return;
        }

        $automaticCoupons = $this->getNonAppliedAutomaticCoupons($cart);

        foreach ($automaticCoupons as $coupon) {
            try {
                $this
                    ->cartCouponManager
                    ->addCoupon($cart, $coupon);
            } catch (AbstractCouponException $e) {
                // Silently tries next coupon on controlled exception
            }
        }
    }
112440
public function notifyCouponUsage(CouponInterface $coupon)
    {
        $couponUsedEvent = new CouponOnUsedEvent($coupon);

        $this->eventDispatcher->dispatch(
            ElcodiCouponEvents::COUPON_USED,
            $couponUsedEvent
        );

        return $this;
    }
944889
public function findCartCouponsByCart(CartInterface $cart)
    {
        return $this
            ->createQueryBuilder('cc')
            ->where('cc.cart = :cart')
            ->setParameter('cart', $cart)
            ->getQuery()
            ->getResult();
    }
1202614
public function dispatchCartOnEmptyEvent(CartInterface $cart)
    {
        $this->eventDispatcher->dispatch(
            ElcodiCartEvents::CART_ONEMPTY,
            new CartOnEmptyEvent($cart)
        );

        return $this;
    }
1323989
private function isActive(CouponInterface $coupon, \DateTime $now = null)
    {
        if (!$coupon->isEnabled()) {
            return false;
        }

        $now = $now ?: $this
            ->dateTimeFactory
            ->create();

        if ($coupon->getValidFrom() > $now) {
            return false;
        }

        $validTo = $coupon->getValidTo();
        if ($validTo && $now > $validTo) {
            return false;
        }

        return true;
    }
548245
public function setCoupon($coupon)
    {
        if ($coupon->value > 0) {
            $this->coupon['value'] = $coupon->value;
        }
        elseif ($coupon->discount > 0) {
            $this->coupon['percent'] = $coupon->discount;
        }
        session(['coupon' => $coupon]);
    }
418592
public function saveCart(CartInterface $cart)
    {
        if (!$cart->getCartLines()->isEmpty()) {
            $this->cartObjectManager->persist($cart);
        }

        $this
            ->cartObjectManager
            ->flush();
    }
477135
public function dispatchCartInconsistentEvent(
        CartInterface $cart,
        CartLineInterface $cartLine
    ) {
        $this->eventDispatcher->dispatch(
            ElcodiCartEvents::CART_INCONSISTENT,
            new CartInconsistentEvent(
                $cart,
                $cartLine
            )
        );

        return $this;
    }
1174684
public function applyDiscount($percentage, $couponId = null)
    {
        if ($percentage > 100) {
            throw new IncorrectDiscount('Maximum percentage discount can be 100%.');
        }

        if ($this->subtotal == 0) {
            throw new IncorrectDiscount('Discount cannot be applied on an empty cart.');
        }

        $this->discountPercentage = $percentage;
        $this->couponId = $couponId;
        $this->discount = round(($this->subtotal * $percentage) / 100, 2);

        $cartData = $this->cartUpdates($isNewItem = false, $keepDiscount = true);

        event(new DiscountApplied($cartData));

        return $cartData;
    }
612518
public function getSessionCart(EventDispatcherInterface $dispatcher = null)
    {
        $cart_id = $this->get("thelia.cart_id", null);
        if (null !== $cart_id) {
            $cart = CartQuery::create()->findPk($cart_id);
        } else {
            $cart = self::$transientCart;
        }

        // If we do not have a cart, or if the current cart is nor valid
        // restore it from the cart cookie, or create a new one
        if (null === $cart || ! $this->isValidCart($cart)) {
            // A dispatcher is required here. If we do not have it, throw an exception
            // This is a temporary workaround to ensure backward compatibility with getCart(),
            // When genCart() will be removed, this check should be removed, and  $dispatcher should become
            // a required parameter.

            if (null == $dispatcher) {
                throw new \InvalidArgumentException(
                    "In this context (no cart in session), an EventDispatcher should be provided to Session::getSessionCart()."
                );
            }

            $cartEvent = new CartRestoreEvent();

            if (null !== $cart) {
                $cartEvent->setCart($cart);
            }

            $dispatcher->dispatch(TheliaEvents::CART_RESTORE_CURRENT, $cartEvent);

            if (null === $cart = $cartEvent->getCart()) {
                throw new \LogicException(
                    "Unable to get a Cart."
                );
            }

            // Store the cart.
            $this->setSessionCart($cart);
        }

        return $cart;
    }