fix Products, Coupons, and admin pages

This commit is contained in:
dwindown
2025-09-15 17:44:39 +07:00
parent 255da46509
commit 4151ea3b9e
10 changed files with 729 additions and 297 deletions

View File

@@ -187,13 +187,111 @@ class Coupon {
public function rule_config($fields) {
$multicurrency = formipay_is_multi_currency_active();
$all_currencies = formipay_currency_as_options();
$global_selected_currencies = formipay_global_currency_options();
$global_currencies = formipay_global_currency_options('raw');
$default_currency = formipay_default_currency();
// Group : Rules
$rules_group = array(
$rules_group_1 = array(
'rules_general_group' => array(
'type' => 'group_title',
'group' => 'started'
),
'active' => array(
'type' => 'checkbox',
'label' => __( 'Active this coupon', 'formipay' ),
'value' => true
'value' => true,
),
'type' => array(
'type' => 'radio',
'label' => __( 'Type', 'formipay' ),
'required' => true,
'options' => array(
'fixed' => __( 'Fixed', 'formipay' ),
'percentage' => __( 'Percentage', 'formipay' )
),
),
'amount_percentage' => array(
'type' => 'number',
'label' => __( 'Amount', 'formipay' ),
'required' => true,
'dependency' => array(
'key' => 'type',
'value' => 'percentage'
),
'group' => 'ended'
)
);
$rules_group_2 = [];
$global_currencies = get_global_currency_array();
$default_currency = formipay_default_currency();
$rules_group_2['discount_amount_wrapper'] = array(
'type' => 'group_title',
'label' => __( 'Discount Amount', 'formipay' ),
'dependency' => array(
'key' => 'type',
'value' => 'fixed'
),
'group' => 'started',
);
$rules_group_max['discount_max_amount_wrapper'] = array(
'type' => 'group_title',
'label' => __( 'Max Discount Amount', 'formipay' ),
'description' => __( 'Leave empty to not limit the max discount amount.', 'formipay' ),
'group' => 'started',
);
foreach($global_currencies as $currency){
$default_currency_symbol = formipay_get_currency_data_by_value($default_currency, 'symbol');
$currency_symbol = formipay_get_currency_data_by_value($currency['currency'], 'symbol');
$currency_title = ucwords(formipay_get_currency_data_by_value($currency['currency'], 'title'));
$decimal_digits = intval($currency['decimal_digits']);
$step = $decimal_digits * 10;
$step = $step > 0 ? 1 / $step : 1;
$rules_group_2['amount_fixed_'.$currency_symbol] = array(
'type' => 'number',
'label' => sprintf(
__( '<img src="%s" width="18" /> Amount in %s', 'formipay' ),
formipay_get_flag_by_currency($currency['currency']),
$currency_symbol
),
'step' => $step,
'min' => 0,
'required' => true,
'placeholder' => __( 'Enter Amount...', 'formipay' ),
'dependency' => array(
'key' => 'type',
'value' => 'fixed'
)
);
$rules_group_max['max_amount_'.$currency_symbol] = array(
'type' => 'number',
'label' => sprintf(
__( '<img src="%s" width="18" /> Max Amount in %s', 'formipay' ),
formipay_get_flag_by_currency($currency['currency']),
$currency_symbol
),
'step' => $step,
'min' => 0,
'placeholder' => __( 'Enter Max Amount...', 'formipay' )
);
}
$last_rules_group_2 = array_key_last($rules_group_2);
$rules_group_2[$last_rules_group_2]['group'] = 'ended';
$last_rules_group_max = array_key_last($rules_group_max);
$rules_group_max[$last_rules_group_max]['group'] = 'ended';
$rules_group_3 = array(
'rules_group' => array(
'type' => 'group_title',
'label' => __( 'Rules', 'formipay' ),
@@ -209,19 +307,6 @@ class Coupon {
- <b>save10</b> is invalid<br>
- <b>Save10</b> is invalid.', 'formipay' )
),
'type' => array(
'type' => 'radio',
'label' => __( 'Type', 'formipay' ),
'options' => array(
'fixed' => __( 'Fixed', 'formipay' ),
'percentage' => __( 'Percentage', 'formipay' )
)
),
'amount' => array(
'type' => 'number',
'label' => __( 'Amount', 'formipay' ),
'description' => sprintf('<span style="color: red;">' . __( 'Be carefully, this amount is not regarding the currency.', 'formipay') . '</span>' )
),
'free_shipping' => array(
'type' => 'checkbox',
'label' => __( 'Free Shipping', 'formipay' ),
@@ -236,13 +321,15 @@ class Coupon {
'value' => 'fixed'
)
),
'max_discount' => array(
'type' => 'number',
'label' => __( 'Max Discount Amount', 'formipay' ),
'description' => __( 'Leave it empty to not limit the max discount amount.', 'formipay' )
),
// 'max_discount' => array(
// 'type' => 'number',
// 'label' => __( 'Max Discount Amount', 'formipay' ),
// 'description' => __( 'Leave it empty to not limit the max discount amount.', 'formipay' )
// ),
);
$rules_group = $rules_group_1 + $rules_group_2 + $rules_group_max + $rules_group_3;
$rules_group = apply_filters( 'formipay/coupon-settings/tab:rules/group:rules', $rules_group );
$last_rules_group = array_key_last($rules_group);
@@ -290,8 +377,19 @@ class Coupon {
'forms' => array(
'type' => 'autocomplete',
'post_type' => array('formipay-form'),
'label' => __( 'These forms can use the coupon', 'formipay' ),
'description' => __( 'Leave it empty to enable all forms to use this coupon. <span style="color: red;">Please be carefully, this coupon amount is not regarding the currency of the selected form.</span>', 'formipay' )
'label' => __( 'Forms', 'formipay' ),
'description' => __( 'Only selected form(s) can use the coupon. Leave empty to apply to all forms.', 'formipay' )
),
'products' => array(
'type' => 'autocomplete',
'post_type' => array('formipay-product'),
'label' => __( 'Products', 'formipay' ),
'description' => __( 'Only selected product(s) can use the coupon. Leave empty to apply to all products.', 'formipay' )
),
'customers' => array(
'type' => 'autocomplete',
'label' => __( 'Customers', 'formipay' ),
'description' => __( 'Only selected customer(s) can use the coupon. Leave empty to apply to all customers.', 'formipay' )
)
);