Skip to content

Commit 0cebf3e

Browse files
authored
Merge pull request #2698 from themeum/bivas-v4
Fix: Add checkout error message for pause enrollment courses
2 parents 12f1870 + 80f0cf9 commit 0cebf3e

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

assets/src/js/front/pages/course-landing.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ window.jQuery(document).ready(($) => {
2525
data: {
2626
action: 'tutor_reset_course_progress',
2727
course_id: course_id,
28+
context: 'course-landing',
2829
},
2930
beforeSend: () => {
3031
button.prop('disabled', true).addClass('is-loading');
@@ -35,7 +36,7 @@ window.jQuery(document).ready(($) => {
3536
}
3637
},
3738
error: function(response) {
38-
tutor_toast(__( 'Error', 'tutor' ),(response.responseJSON || {}).message ||__('Something went wrong', 'tutor'));
39+
tutor_toast(__( 'Error', 'tutor' ),(response.responseJSON || {}).message ||__('Something went wrong', 'tutor'), 'error' );
3940
},
4041
complete: function () {
4142
button.prop('disabled', false).removeClass('is-loading');

assets/src/js/frontend/learning-area/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface CourseCompletePayload {
1010
}
1111
interface CourseRetakePayload {
1212
course_id: number;
13+
context: string;
1314
}
1415

1516
/**
@@ -70,7 +71,7 @@ export const courseCompleteHandler = () => {
7071
},
7172

7273
async handleCourseRetake(courseId: number) {
73-
await this.courseRetakeMutation?.mutate({ course_id: courseId });
74+
await this.courseRetakeMutation?.mutate({ course_id: courseId, context: 'learning-area' });
7475
},
7576
};
7677
};

assets/src/js/frontend/learning-area/sidebar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { type AxiosError } from 'axios';
1212

1313
interface ResetProgressPayload {
1414
course_id: number;
15+
context: string;
1516
}
1617

1718
interface ResetProgressResponse {
@@ -104,7 +105,7 @@ export const sidebarComponent = ({
104105
},
105106

106107
resetProgress() {
107-
this.resetProgressMutation?.mutate({ course_id: this.courseId });
108+
this.resetProgressMutation?.mutate({ course_id: this.courseId, context: 'learning-area-sidebar' });
108109
},
109110
};
110111
};

classes/Course.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3084,10 +3084,16 @@ public function delete_associated_enrollment( $post_id ) {
30843084
public function tutor_reset_course_progress() {
30853085
tutor_utils()->checking_nonce();
30863086
$course_id = Input::post( 'course_id', 0, Input::TYPE_INT );
3087+
$context = Input::post( 'context', '' );
30873088
$course_reset_progress = tutor_utils()->get_option( 'course_reset_progress', false );
30883089
$course_retake_feature = tutor_utils()->get_option( 'course_retake_feature', false );
30893090

3090-
if ( ! $course_reset_progress || ! $course_retake_feature ) {
3091+
if ( ! $course_reset_progress && 'learning-area-sidebar' === $context ) {
3092+
$this->response_bad_request( __( 'You are not allowed to reset course progress.', 'tutor' ) );
3093+
return;
3094+
}
3095+
3096+
if ( ! $course_retake_feature && ( 'course-landing' === $context || 'learning-area' === $context ) ) {
30913097
$this->response_bad_request( __( 'You are not allowed to reset course progress.', 'tutor' ) );
30923098
return;
30933099
}

ecommerce/CheckoutController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,9 @@ public function pay_now() {
635635
$errors,
636636
sprintf(
637637
// Translators: %s course name.
638-
__( ' Course %s cannot be enrolled right now.', 'tutor' )
638+
__( 'Course %s cannot be enrolled right now.', 'tutor' ),
639+
get_the_title( $course_id ) ?? ''
639640
),
640-
get_the_title( $course_id ) ?? ''
641641
);
642642
}
643643
}

0 commit comments

Comments
 (0)