From 533b0f131f61c32e22e7c0df4acc5d258939f9c3 Mon Sep 17 00:00:00 2001 From: ramadanomar Date: Fri, 21 Mar 2025 05:05:01 +0200 Subject: [PATCH 1/2] feat: saving "forced" enrollment action --- admin/class-openedx-commerce-admin.php | 15 +++- .../views/class-openedx-commerce-settings.php | 76 +++++++++++++++++++ openedx-commerce.php | 4 +- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php index 80dc75b..59bc826 100644 --- a/admin/class-openedx-commerce-admin.php +++ b/admin/class-openedx-commerce-admin.php @@ -498,11 +498,24 @@ public function select_course_items( $items, $is_refunded = false ) { */ public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) { + $force_enrollment = get_option('openedx-enrollment-force', false); + $allow_non_existing = get_option('openedx-enrollment-allowed', false); + + if ($force_enrollment && $allow_non_existing) { + $action = 'openedx_enrollment_allowed_force'; + } elseif ($force_enrollment) { + $action = 'openedx_enrollment_force'; + } elseif ($allow_non_existing) { + $action = 'openedx_enrollment_allowed'; + } else { + $action = 'enrollment_process'; + } + foreach ( $courses as $item_id => $item ) { $course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true ); $course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true ); - $action = 'enrollment_process'; + // $action = 'enrollment_process'; $enrollment_arr = array( 'openedx_enrollment_course_id' => $course_id, diff --git a/admin/views/class-openedx-commerce-settings.php b/admin/views/class-openedx-commerce-settings.php index b9d8713..3948983 100644 --- a/admin/views/class-openedx-commerce-settings.php +++ b/admin/views/class-openedx-commerce-settings.php @@ -125,6 +125,22 @@ public function openedx_settings_init() { 'openedx-settings-section' ); + add_settings_field( + 'openedx-enrollment-force', + 'Force Enrollment', + array( $this, 'openedx_enrollment_force_callback' ), + 'openedx-settings', + 'openedx-settings-section' + ); + + add_settings_field( + 'openedx-enrollment-allowed', + 'Allow Non-Existing Users', + array( $this, 'openedx_enrollment_allowed_callback' ), + 'openedx-settings', + 'openedx-settings-section' + ); + register_setting( 'openedx-settings-group', 'openedx-domain', @@ -149,6 +165,36 @@ public function openedx_settings_init() { 'sanitize_text_field' ); + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-force', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-allowed', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-allowed', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' ) ) { @@ -324,5 +370,35 @@ public function openedx_settings_section_callback() { 'Configuring the necessary parameters here to establish the connection between this plugin and your Open edX platform. For more information, you can visit the how-to Create an Open edX Application for the Plugin Settings in the documentation.' ); } + + /** + * Output the enrollment force settings field. + * + * Retrieves the saved enrollment force value and outputs a checkbox input field and description text. + * + * @return void + */ + public function openedx_enrollment_force_callback() { + $force_enrollment = get_option('openedx-enrollment-force', false); + ?> + > + + + > + + Date: Mon, 4 Aug 2025 16:21:16 -0500 Subject: [PATCH 2/2] fix: linting and fixing QA reports --- admin/class-openedx-commerce-admin.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php index 59bc826..35046b2 100644 --- a/admin/class-openedx-commerce-admin.php +++ b/admin/class-openedx-commerce-admin.php @@ -498,14 +498,14 @@ public function select_course_items( $items, $is_refunded = false ) { */ public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) { - $force_enrollment = get_option('openedx-enrollment-force', false); - $allow_non_existing = get_option('openedx-enrollment-allowed', false); + $force_enrollment = get_option( 'openedx-enrollment-force', false ); + $allow_non_existing = get_option( 'openedx-enrollment-allowed', false ); - if ($force_enrollment && $allow_non_existing) { + if ( $force_enrollment && $allow_non_existing ) { $action = 'openedx_enrollment_allowed_force'; - } elseif ($force_enrollment) { + } elseif ( $force_enrollment ) { $action = 'openedx_enrollment_force'; - } elseif ($allow_non_existing) { + } elseif ( $allow_non_existing ) { $action = 'openedx_enrollment_allowed'; } else { $action = 'enrollment_process'; @@ -515,7 +515,6 @@ public function items_enrollment_request( $courses, $order_id, $billing_email, $ $course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true ); $course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true ); - // $action = 'enrollment_process'; $enrollment_arr = array( 'openedx_enrollment_course_id' => $course_id,