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:
@@ -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