protected function sortCoupons(array $coupons)
    {
        $couponsKept = array();

        /** @var CouponInterface $coupon */
        foreach ($coupons as $coupon) {
            if ($coupon && !$coupon->isExpired()) {
                if ($coupon->isCumulative()) {
                    if (isset($couponsKept[0])) {
                        /** @var CouponInterface $previousCoupon */
                        $previousCoupon = $couponsKept[0];
                        if ($previousCoupon->isCumulative()) {
                            // Add Coupon
                            $couponsKept[] = $coupon;
                        } else {
                            // Reset Coupons, add last
                            $couponsKept = array($coupon);
                        }
                    } else {
                        // Reset Coupons, add last
                        $couponsKept = array($coupon);
                    }
                } else {
                    // Reset Coupons, add last
                    $couponsKept = array($coupon);
                }
            }
        }

        $coupons = $couponsKept;
        $couponsKept = array();

        /** @var CouponInterface $coupon */
        foreach ($coupons as $coupon) {
            try {
                if ($coupon->isMatching()) {
                    $couponsKept[] = $coupon;
                }
            } catch (UnmatchableConditionException $e) {
                // ignore unmatchable coupon
                continue;
            }
        }

        return $couponsKept;
    }
protected function sortCoupons(array $coupons)
    {
        $couponsKept = array();

        /** @var CouponInterface $coupon */
        foreach ($coupons as $coupon) {
            if ($coupon && !$coupon->isExpired()) {
                if ($coupon->isCumulative()) {
                    if (isset($couponsKept[0])) {
                        /** @var CouponInterface $previousCoupon */
                        $previousCoupon = $couponsKept[0];
                        if ($previousCoupon->isCumulative()) {
                            // Add Coupon
                            $couponsKept[] = $coupon;
                        } else {
                            // Reset Coupons, add last
                            $couponsKept = array($coupon);
                        }
                    } else {
                        // Reset Coupons, add last
                        $couponsKept = array($coupon);
                    }
                } else {
                    // Reset Coupons, add last
                    $couponsKept = array($coupon);
                }
            }
        }

        $coupons = $couponsKept;
        $couponsKept = array();

        /** @var CouponInterface $coupon */
        foreach ($coupons as $coupon) {
            try {
                if ($coupon->isMatching()) {
                    $couponsKept[] = $coupon;
                }
            } catch (UnmatchableConditionException $e) {
                // ignore unmatchable coupon
                continue;
            }
        }

        return $couponsKept;
    }
protected function sortCoupons ( array $ coupons ) { $ couponsKept = array ( ) ; /** @var CouponInterface $coupon */ foreach ( $ coupons as $ coupon ) { if ( $ coupon && ! $ coupon -> isExpired ( ) ) { if ( $ coupon -> isCumulative ( ) ) { if ( isset ( $ couponsKept [ 0 ] ) ) { /** @var CouponInterface $previousCoupon */ $ previousCoupon = $ couponsKept [ 0 ] ; if ( $ previousCoupon -> isCumulative ( ) ) { // Add Coupon $ couponsKept [ ] = $ coupon ; } else { // Reset Coupons, add last $ couponsKept = array ( $ coupon ) ; } } else { // Reset Coupons, add last $ couponsKept = array ( $ coupon ) ; } } else { // Reset Coupons, add last $ couponsKept = array ( $ coupon ) ; } } } $ coupons = $ couponsKept ; $ couponsKept = array ( ) ; /** @var CouponInterface $coupon */ foreach ( $ coupons as $ coupon ) { try { if ( $ coupon -> isMatching ( ) ) { $ couponsKept [ ] = $ coupon ; } } catch ( UnmatchableConditionException $ e ) { // ignore unmatchable coupon continue ; } } return $ couponsKept ; }
Sort Coupon to keep
Coupon not cumulative cancels previous

@param array $coupons CouponInterface to process

@return array Array of CouponInterface sorted
Sort Coupon to keep Coupon not cumulative cancels previous