fix: consolidate backend changes and fix icon imports
- Add standard .gitignore patterns (node_modules, .env, IDE files) - Coupon.php: fix data structure for DataTable, add status filter - Order.php: fix data structure to match OrderListItem expectations - Product.php: add multi-currency prices array, unify nonce to 'formipay-admin' - client.js: fix AJAX action names to match PHP (underscores → hyphens) - OrderList.js: fix icon import (Icons.list), add response handling - OrderListItem.js: fix icon import (Icons.seen)
This commit is contained in:
@@ -612,6 +612,9 @@ class Coupon {
|
||||
$args['s'] = sanitize_text_field( wp_unslash($_REQUEST['search']) );
|
||||
}
|
||||
|
||||
// Handle status filtering (active/inactive)
|
||||
$status_filter = isset($_REQUEST['status']) ? sanitize_text_field($_REQUEST['status']) : 'all';
|
||||
|
||||
$get_coupons = get_posts($args);
|
||||
$global_currencies = get_global_currency_array();
|
||||
|
||||
@@ -619,13 +622,19 @@ class Coupon {
|
||||
if(!empty($get_coupons)){
|
||||
foreach($get_coupons as $key => $coupon){
|
||||
|
||||
$active = true;
|
||||
$is_active = formipay_get_post_meta($coupon->ID, 'active') == 'on';
|
||||
|
||||
// Apply status filter
|
||||
if ($status_filter !== 'all') {
|
||||
if ($status_filter === 'active' && !$is_active) continue;
|
||||
if ($status_filter === 'inactive' && $is_active) continue;
|
||||
}
|
||||
|
||||
$date_limit = formipay_get_post_meta($coupon->ID, 'date_limit');
|
||||
|
||||
$type = formipay_get_post_meta($coupon->ID, 'type');
|
||||
$amount_meta_key = "amount_$type";
|
||||
|
||||
|
||||
if($type == 'fixed'){
|
||||
$amount_value = [];
|
||||
foreach($global_currencies as $currency){
|
||||
@@ -646,23 +655,21 @@ class Coupon {
|
||||
$amount_value = floatval(formipay_get_post_meta($coupon->ID, $amount_meta_key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($active){
|
||||
$coupons[] = [
|
||||
'ID' => $coupon->ID,
|
||||
'code' => get_the_title($coupon->ID),
|
||||
'value' => $amount_value,
|
||||
'type' => ucfirst(formipay_get_post_meta($coupon->ID, 'type')),
|
||||
'case_sensitive' => formipay_get_post_meta($coupon->ID, 'case_sensitive'),
|
||||
'usages' => [
|
||||
'used' => $this->count_order_by_coupon_code(get_the_title($coupon->ID)),
|
||||
'limit' => (intval(formipay_get_post_meta($coupon->ID, 'use_limit')) > 0) ? formipay_get_post_meta($coupon->ID, 'use_limit') : '∞'
|
||||
],
|
||||
'date_limit' => false !== $date_limit ? formipay_date('Y-m-d', intval(formipay_get_post_meta($coupon->ID, 'date_limit')) / 1000) : 'none',
|
||||
'status' => (formipay_get_post_meta($coupon->ID, 'active') == 'on') ? 'Active' : 'Inactive'
|
||||
];
|
||||
}
|
||||
|
||||
$coupons[] = [
|
||||
'ID' => $coupon->ID,
|
||||
'code' => get_the_title($coupon->ID),
|
||||
'amount' => $amount_value,
|
||||
'type' => ucfirst(formipay_get_post_meta($coupon->ID, 'type')),
|
||||
'case_sensitive' => formipay_get_post_meta($coupon->ID, 'case_sensitive'),
|
||||
'usage_count' => $this->count_order_by_coupon_code(get_the_title($coupon->ID)),
|
||||
'usages' => $this->count_order_by_coupon_code(get_the_title($coupon->ID)),
|
||||
'date_limit' => false !== $date_limit ? formipay_date('Y-m-d', intval(formipay_get_post_meta($coupon->ID, 'date_limit')) / 1000) : 'none',
|
||||
'active' => $is_active ? 'on' : 'off',
|
||||
'post_status' => $is_active ? 'active' : 'inactive',
|
||||
'status' => $is_active ? 'active' : 'inactive'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ class Order {
|
||||
|
||||
// React admin
|
||||
printf(
|
||||
'<div id="formipay-admin-root" data-formipay-mount="%s"></div>',
|
||||
'<div class="wrap"><div id="formipay-admin-root" data-formipay-mount="%s"></div></div>',
|
||||
esc_attr($page)
|
||||
);
|
||||
|
||||
@@ -933,21 +933,31 @@ class Order {
|
||||
|
||||
// Process filtered orders
|
||||
if (!empty($get_filtered_orders)) {
|
||||
foreach ($get_filtered_orders as $key => $order) {
|
||||
foreach ($get_filtered_orders as $key => $order) {
|
||||
$currency = explode(':::', formipay_get_post_meta($order->form_id, 'product_currency'));
|
||||
$code = !empty($currency[0]) ? $currency[0] : '';
|
||||
// Prepare order data
|
||||
$code = !empty($currency[0]) ? $currency[0] : '';
|
||||
|
||||
// Keep status as-is (with hyphens) to match STATUS_COLORS keys
|
||||
$status = $order->status;
|
||||
|
||||
// Transform form_data to the structure expected by OrderListItem
|
||||
$raw_form_data = maybe_unserialize($order->form_data);
|
||||
$transformed_form_data = [];
|
||||
if (is_array($raw_form_data)) {
|
||||
foreach ($raw_form_data as $field_key => $field_value) {
|
||||
$transformed_form_data[] = [
|
||||
'name' => $field_key,
|
||||
'value' => is_array($field_value) && isset($field_value['value']) ? $field_value['value'] : $field_value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$orders[] = [
|
||||
'ID' => $order->id,
|
||||
'form' => get_the_title($order->form_id),
|
||||
'date' => $order->created_date,
|
||||
'payment_gateway' => ucwords(str_replace('_', ' ', $order->payment_gateway)),
|
||||
'status' => ucwords(str_replace('-', ' ', $order->status)),
|
||||
'total' => [
|
||||
'flag' => formipay_get_flag_by_currency($code),
|
||||
'name' => $code,
|
||||
'value' => formipay_price_format($order->total, $order->form_id),
|
||||
]
|
||||
'id' => $order->id,
|
||||
'created_date' => $order->created_date,
|
||||
'form_data' => $transformed_form_data,
|
||||
'total_formatted' => formipay_price_format($order->total, $order->form_id),
|
||||
'status' => $status,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ class Product {
|
||||
'confirmButton' => esc_html__( 'Confirm', 'formipay' )
|
||||
],
|
||||
],
|
||||
'nonce' => wp_create_nonce('formipay-admin-product-page')
|
||||
'nonce' => wp_create_nonce('formipay-admin')
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ class Product {
|
||||
|
||||
public function formipay_tabledata_products() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
@@ -668,26 +668,66 @@ class Product {
|
||||
$total_products = $query->found_posts;
|
||||
|
||||
// Process results
|
||||
$global_currencies = get_global_currency_array();
|
||||
$products = [];
|
||||
foreach ($product_ids as $product_id) {
|
||||
$product = get_post($product_id);
|
||||
|
||||
|
||||
$currency = explode(':::', get_post_meta($product_id, 'product_currency', true));
|
||||
$categories = wp_get_post_terms($product_id, 'formipay-product-category', ['fields' => 'names']);
|
||||
|
||||
|
||||
// Build multi-currency prices array
|
||||
$prices = [];
|
||||
foreach ($global_currencies as $curr) {
|
||||
$curr_raw = $curr['currency'];
|
||||
$curr_parts = explode(':::', $curr_raw);
|
||||
$curr_code = $curr_parts[0] ?? '';
|
||||
$symbol = formipay_get_currency_data_by_value($curr_raw, 'symbol');
|
||||
|
||||
$regular_price = get_post_meta($product_id, 'setting_product_price_regular_' . $symbol, true);
|
||||
$sale_price = get_post_meta($product_id, 'setting_product_price_sale_' . $symbol, true);
|
||||
|
||||
// Only add if we have at least a regular price
|
||||
if (!empty($regular_price)) {
|
||||
// Format price using this currency's own formatting rules
|
||||
$decimal_digits = intval($curr['decimal_digits'] ?? 2);
|
||||
$decimal_symbol = $curr['decimal_symbol'] ?? '.';
|
||||
$thousand_separator = $curr['thousand_separator'] ?? ',';
|
||||
|
||||
$formatted_regular = $symbol . ' ' . number_format(floatval($regular_price), $decimal_digits, $decimal_symbol, $thousand_separator);
|
||||
$formatted_sale = !empty($sale_price) ? $symbol . ' ' . number_format(floatval($sale_price), $decimal_digits, $decimal_symbol, $thousand_separator) : '';
|
||||
|
||||
$prices[] = [
|
||||
'currency' => $curr_code,
|
||||
'symbol' => $symbol,
|
||||
'flag' => formipay_get_flag_by_currency($curr_raw),
|
||||
'regular_price' => $formatted_regular,
|
||||
'sale_price' => $formatted_sale,
|
||||
'has_sale' => !empty($sale_price),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to single price if no multi-currency prices set
|
||||
if (empty($prices)) {
|
||||
$fallback_price = get_post_meta($product_id, 'price', true);
|
||||
$prices[] = [
|
||||
'currency' => $currency[0] ?? 'USD',
|
||||
'symbol' => $currency[2] ?? '$',
|
||||
'flag' => formipay_get_flag_by_currency($currency[0] ?? ''),
|
||||
'regular_price' => formipay_price_format($fallback_price, $product_id),
|
||||
'sale_price' => '',
|
||||
'has_sale' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$products[] = [
|
||||
'ID' => $product_id,
|
||||
'title' => $product->post_title,
|
||||
'category' => implode(', ', $categories),
|
||||
'type' => formipay_get_post_meta($product_id, 'product_type'),
|
||||
'stock' => formipay_get_post_meta($product_id, 'stock') ?: '∞',
|
||||
'price' => [
|
||||
'flag' => formipay_get_flag_by_currency($currency[0] ?? ''),
|
||||
'name' => formipay_price_format(
|
||||
get_post_meta($product_id, 'price', true),
|
||||
$product_id
|
||||
)
|
||||
],
|
||||
'prices' => $prices,
|
||||
'status' => $product->post_status,
|
||||
];
|
||||
}
|
||||
@@ -710,7 +750,7 @@ class Product {
|
||||
|
||||
public function formipay_create_product_post() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
@@ -745,7 +785,7 @@ class Product {
|
||||
|
||||
public function formipay_product_get_currencies() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
@@ -773,7 +813,7 @@ class Product {
|
||||
|
||||
public function formipay_delete_product() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
@@ -801,7 +841,7 @@ class Product {
|
||||
|
||||
public function formipay_bulk_delete_product() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
@@ -847,7 +887,7 @@ class Product {
|
||||
|
||||
public function formipay_duplicate_product() {
|
||||
|
||||
check_ajax_referer( 'formipay-admin-product-page', '_wpnonce' );
|
||||
check_ajax_referer( 'formipay-admin', '_wpnonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
|
||||
|
||||
Reference in New Issue
Block a user