Skip to content

Commit 533b0f1

Browse files
committed
feat: saving "forced" enrollment action
1 parent e0e636e commit 533b0f1

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

admin/class-openedx-commerce-admin.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,24 @@ public function select_course_items( $items, $is_refunded = false ) {
498498
*/
499499
public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) {
500500

501+
$force_enrollment = get_option('openedx-enrollment-force', false);
502+
$allow_non_existing = get_option('openedx-enrollment-allowed', false);
503+
504+
if ($force_enrollment && $allow_non_existing) {
505+
$action = 'openedx_enrollment_allowed_force';
506+
} elseif ($force_enrollment) {
507+
$action = 'openedx_enrollment_force';
508+
} elseif ($allow_non_existing) {
509+
$action = 'openedx_enrollment_allowed';
510+
} else {
511+
$action = 'enrollment_process';
512+
}
513+
501514
foreach ( $courses as $item_id => $item ) {
502515

503516
$course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true );
504517
$course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true );
505-
$action = 'enrollment_process';
518+
// $action = 'enrollment_process';
506519

507520
$enrollment_arr = array(
508521
'openedx_enrollment_course_id' => $course_id,

admin/views/class-openedx-commerce-settings.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ public function openedx_settings_init() {
125125
'openedx-settings-section'
126126
);
127127

128+
add_settings_field(
129+
'openedx-enrollment-force',
130+
'Force Enrollment',
131+
array( $this, 'openedx_enrollment_force_callback' ),
132+
'openedx-settings',
133+
'openedx-settings-section'
134+
);
135+
136+
add_settings_field(
137+
'openedx-enrollment-allowed',
138+
'Allow Non-Existing Users',
139+
array( $this, 'openedx_enrollment_allowed_callback' ),
140+
'openedx-settings',
141+
'openedx-settings-section'
142+
);
143+
128144
register_setting(
129145
'openedx-settings-group',
130146
'openedx-domain',
@@ -149,6 +165,36 @@ public function openedx_settings_init() {
149165
'sanitize_text_field'
150166
);
151167

168+
register_setting(
169+
'openedx-settings-group',
170+
'openedx-enrollment-force',
171+
array(
172+
'type' => 'boolean',
173+
'sanitize_callback' => 'rest_sanitize_boolean',
174+
'default' => false,
175+
)
176+
);
177+
178+
register_setting(
179+
'openedx-settings-group',
180+
'openedx-enrollment-allowed',
181+
array(
182+
'type' => 'boolean',
183+
'sanitize_callback' => 'rest_sanitize_boolean',
184+
'default' => false,
185+
)
186+
);
187+
188+
register_setting(
189+
'openedx-settings-group',
190+
'openedx-enrollment-allowed',
191+
array(
192+
'type' => 'boolean',
193+
'sanitize_callback' => 'rest_sanitize_boolean',
194+
'default' => false,
195+
)
196+
);
197+
152198
if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) ||
153199
! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' )
154200
) {
@@ -324,5 +370,35 @@ public function openedx_settings_section_callback() {
324370
'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 <a href="https://docs.openedx.org/projects/wordpress-ecommerce-plugin/en/latest/how-tos/create_an_openedx_app.html">Create an Open edX Application for the Plugin Settings</a> in the documentation.'
325371
);
326372
}
373+
374+
/**
375+
* Output the enrollment force settings field.
376+
*
377+
* Retrieves the saved enrollment force value and outputs a checkbox input field and description text.
378+
*
379+
* @return void
380+
*/
381+
public function openedx_enrollment_force_callback() {
382+
$force_enrollment = get_option('openedx-enrollment-force', false);
383+
?>
384+
<input type="checkbox" id="openedx-enrollment-force" name="openedx-enrollment-force" value="1" <?php checked(1, $force_enrollment, true); ?>>
385+
<label for="openedx-enrollment-force"><?php esc_html_e('Use the "force" flag. Disregard the course\'s enrollment end dates.', 'openedx-commerce'); ?></label>
386+
<?php
387+
}
388+
389+
/**
390+
* Output the enrollment allowed settings field.
391+
*
392+
* Retrieves the saved enrollment allowed value and outputs a checkbox input field and description text.
393+
*
394+
* @return void
395+
*/
396+
public function openedx_enrollment_allowed_callback() {
397+
$allow_non_existing = get_option('openedx-enrollment-allowed', false);
398+
?>
399+
<input type="checkbox" id="openedx-enrollment-allowed" name="openedx-enrollment-allowed" value="1" <?php checked(1, $allow_non_existing, true); ?>>
400+
<label for="openedx-enrollment-allowed"><?php esc_html_e('Create course enrollment allowed if the user doesn\'t exist in the Open edX platform.', 'openedx-commerce'); ?></label>
401+
<?php
402+
}
327403
}
328404

openedx-commerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Open edX Commerce
44
* Plugin URI: https://github.com/openedx/openedx-wordpress-ecommerce
55
* Description: Easily connect your WooCommerce store to Open edX.
6-
* Version: 2.0.7
6+
* Version: 2.0.8
77
* Author: Open edX Community
88
* Author URI: https://github.com/openedx/openedx-wordpress-ecommerce
99
* License: GPL-2.0+
@@ -32,7 +32,7 @@
3232
* Start at version 1.0.0 and use SemVer - https://semver.org
3333
* Rename this for your plugin and update it as you release new versions.
3434
*/
35-
define( 'OPENEDX_COMMERCE_VERSION', '2.0.7' );
35+
define( 'OPENEDX_COMMERCE_VERSION', '2.0.8' );
3636

3737
/**
3838
* The code that runs during plugin activation.

0 commit comments

Comments
 (0)