private function addCouponToOrder($coupons, $new_order)
    {
        $errors = new \Illuminate\Support\MessageBag;
        
        if (count($coupons) > 0) {
            foreach ($coupons as $item) {
                $model = Coupon::find($item);
                if ($model != null) {
                    try {
                        $new_order->addCoupon($model);
                    } catch (Exception $exp) {
                        $errors->add(
                            'couponError',
                            "Coupon " . $model->code . " cannot be added because: " . $exp->getMessage()
                        );
                        
                    }
                }
            }
            
            // Set coupon discount
            $new_order->setDiscounts();
        }
        
        return $errors;
    }
private function addCouponToOrder($coupons, $new_order)
    {
        $errors = new \Illuminate\Support\MessageBag;
        
        if (count($coupons) > 0) {
            foreach ($coupons as $item) {
                $model = Coupon::find($item);
                if ($model != null) {
                    try {
                        $new_order->addCoupon($model);
                    } catch (Exception $exp) {
                        $errors->add(
                            'couponError',
                            "Coupon " . $model->code . " cannot be added because: " . $exp->getMessage()
                        );
                        
                    }
                }
            }
            
            // Set coupon discount
            $new_order->setDiscounts();
        }
        
        return $errors;
    }
private function addCouponToOrder ( $ coupons , $ new_order ) { $ errors = new \ Illuminate \ Support \ MessageBag ; if ( count ( $ coupons ) > 0 ) { foreach ( $ coupons as $ item ) { $ model = Coupon :: find ( $ item ) ; if ( $ model != null ) { try { $ new_order -> addCoupon ( $ model ) ; } catch ( Exception $ exp ) { $ errors -> add ( 'couponError' , "Coupon " . $ model -> code . " cannot be added because: " . $ exp -> getMessage ( ) ) ; } } } // Set coupon discount $ new_order -> setDiscounts ( ) ; } return $ errors ; }
Add coupons to order

@param array $coupons
@param object $new_order Order

@return array
Add coupons to order