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;
    }
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;
    }
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 ; }
Applies disount to the cart.

@param float Discount Percentage
@param int Coupon id
@return array
@throws IncorrectDiscount
Applies disount to the cart .