示例#1
0
     if (sizeof($nonFreeLessons) > 0) {
         $currentUser->addLessons($nonFreeLessons, array_fill(0, sizeof($nonFreeLessons), 'student'), true);
     }
     if (sizeof($nonFreeCourses) > 0) {
         $currentUser->addCourses($nonFreeCourses, array_fill(0, sizeof($nonFreeCourses), 'student'), true);
     }
     $currentUser->user['balance'] = $currentUser->user['balance'] - $totalPrice;
     $currentUser->persist();
     $fields = array("amount" => $totalPrice, "timestamp" => time(), "method" => "balance", "status" => "completed", "users_LOGIN" => $currentUser->user['login'], "lessons" => $nonFreeLessons, "courses" => $nonFreeCourses);
     $payment = payments::create($fields);
     if ($coupon) {
         $coupon->useCoupon($currentUser, $payment, array('lessons' => $nonFreeLessons, 'courses' => $nonFreeCourses));
     }
 } else {
     if ($form->exportValue('coupon') && ($coupon = new coupons($form->exportValue('coupon'), true))) {
         if (!$coupon->checkEligibility($currentUser)) {
             throw new Exception(_INVALIDCOUPON);
         }
         if (!$GLOBALS['configuration']['paypalbusiness']) {
             //If we have paypal, the reduction is already done
             $totalPrice = $totalPrice * (1 - $coupon->{$coupon->entity}['discount'] / 100);
         }
     }
     //in case of 100% discount
     if ($totalPrice == 0) {
         //Assign new lessons as inactive
         if (sizeof($nonFreeLessons) > 0) {
             $currentUser->addLessons($nonFreeLessons, array_fill(0, sizeof($nonFreeLessons), 'student'), true);
         }
         if (sizeof($nonFreeCourses) > 0) {
             $currentUser->addCourses($nonFreeCourses, array_fill(0, sizeof($nonFreeCourses), 'student'), true);