feat: migrate shipping to form-level and integrate flags.json as single source of truth

Shipping Migration:
- Move shipping configuration from product-level to form-level
- Add form shipping tab in form settings (no_shipping, flat_rate, free_shipping)
- Update FlatRate to register at form level instead of product level
- Update checkout logic to read from form settings
- Support percentage-based flat rate calculation
- Simplify shipping method IDs (flat_rate, free_shipping)

Currency Flags Integration:
- Add formipay_get_all_currency_flags() to read from admin/assets/json/flags.json
- Remove hardcoded CURRENCY_FLAGS emoji map from VariationField.js
- Create CurrencyFlag component to render base64 flag images
- Localize currency_flags to window.formipayProductDetails
- Update shipping info display in admin order details

Benefits:
- Form-level shipping prevents multiplying shipping costs per product
- Single source of truth for currency flags (flags.json)
- Better support for future cart system
- Consistent with e-commerce standards
This commit is contained in:
dwindown
2026-04-23 08:12:40 +07:00
parent 0094a3571c
commit 008188b790
13 changed files with 2819 additions and 797 deletions

View File

@@ -122,15 +122,21 @@ function get_global_currency_array() {
if(false === $ifSingleCurrency){
// $currency_sort = [];
$default_sort_key = null;
// Extract currency code from default_currency for comparison (handles case where default has symbol but multicurrencies don't)
$default_currency_code = explode(':::', $default_currency)[0];
foreach($global_currencies as $key => $currency){
$currency_value = $currency['currency'];
if($currency_value === $default_currency){
// Compare by currency code only (before first :::)
$currency_code = explode(':::', $currency_value)[0];
if($currency_code === $default_currency_code){
$default_sort_key = $key;
}
}
$currency_sort = [$default_sort_key => $global_currencies[$default_sort_key]];
unset($global_currencies[$default_sort_key]);
$global_currencies = $currency_sort + $global_currencies;
// Convert associative array to indexed array for JavaScript
$global_currencies = array_values($global_currencies);
}else{
if(false === boolval($multicurrency)){
$global_currencies = [
@@ -176,6 +182,31 @@ function formipay_get_flag_by_currency($currency) {
}
/**
* Get all currency flags from flags.json
* Returns an array mapping currency codes to base64 flag images
* This is the single source of truth for currency flags - never duplicate this data
*
* @return array Array of currency code => flag image mapping
*/
function formipay_get_all_currency_flags() {
static $currency_flags = null;
if ($currency_flags !== null) {
return $currency_flags;
}
$json = file_get_contents(FORMIPAY_PATH . 'admin/assets/json/flags.json');
$flags = json_decode($json, true);
$currency_flags = [];
foreach ($flags as $item) {
$currency_flags[$item['code']] = $item['flag'];
}
return $currency_flags;
}
function formipay_price_format($num = 0, $post_id = 0){
$decimal_digits = 2;
@@ -361,7 +392,15 @@ function formipay_get_order($order_id) {
case 'payment_gateway':
$label = esc_html__( 'Payment Gateway', 'formipay' );
break;
case 'shipping_country':
$label = esc_html__( 'Shipping Country', 'formipay' );
break;
case 'shipping_method':
$label = esc_html__( 'Shipping Method', 'formipay' );
break;
default:
if(!empty($all_fields[$name.'_config'])){
$label = $all_fields[$name.'_config']['label'];