refactor(Core): optimize admin panel and refactor
This commit is contained in:
@@ -166,7 +166,6 @@ class RuleController extends BaseController {
|
||||
$rule->end_date = !empty($_POST['end_date']) ? sanitize_text_field($_POST['end_date']) : null;
|
||||
$rule->enabled = isset($_POST['enabled']) ? 1 : 0;
|
||||
|
||||
// Parse conditions
|
||||
if (isset($_POST['conditions']) && is_array($_POST['conditions'])) {
|
||||
$rule->conditions = array_map(function($condition) {
|
||||
return [
|
||||
@@ -174,9 +173,15 @@ class RuleController extends BaseController {
|
||||
'value' => sanitize_text_field($condition['value'] ?? '')
|
||||
];
|
||||
}, $_POST['conditions']);
|
||||
} else {
|
||||
$rule->conditions = [
|
||||
[
|
||||
'type' => sanitize_text_field($_POST['condition_type'] ?? 'user_type'),
|
||||
'value' => sanitize_text_field($_POST['condition_value'] ?? 'new'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Parse actions
|
||||
if (isset($_POST['actions']) && is_array($_POST['actions'])) {
|
||||
$rule->actions = array_map(function($action) {
|
||||
return [
|
||||
@@ -184,6 +189,15 @@ class RuleController extends BaseController {
|
||||
'value' => sanitize_text_field($action['value'] ?? '')
|
||||
];
|
||||
}, $_POST['actions']);
|
||||
} else {
|
||||
$rule->actions = [
|
||||
[
|
||||
'type' => sanitize_text_field($_POST['action_type'] ?? 'discount_percent'),
|
||||
'value' => sanitize_text_field($_POST['action_value'] ?? '0'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rule->syncLegacyFields();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user