fix: Use active WooCommerce currency instead of hardcoded USD
Fixed Issues: 1. ✅ Currency hardcoded to USD in product forms 2. ✅ Edit page redirect to non-existent detail page Changes: 🌍 Currency Integration (GeneralTab.tsx): - Import getStoreCurrency() from @/lib/currency - Get store currency data: symbol, decimals, position - Replace hardcoded $ icon with dynamic store.symbol - Use store.decimals for input step: * step="1" for zero-decimal currencies (IDR, JPY, etc.) * step="0.01" for decimal currencies (USD, EUR, etc.) - Update placeholder based on decimals: * "0" for zero-decimal * "0.00" for decimal Before: - <DollarSign /> icon (always $) - step="0.01" (always 2 decimals) - placeholder="0.00" (always 2 decimals) After: - <span>{store.symbol}</span> (Rp, $, RM, etc.) - step={store.decimals === 0 ? '1' : '0.01'} - placeholder={store.decimals === 0 ? '0' : '0.00'} 🌍 Currency Display (index.tsx): - Import formatMoney() from @/lib/currency - Replace hardcoded $: * Before: ${parseFloat(product.regular_price).toFixed(2)} * After: formatMoney(product.regular_price) - Now respects: * Currency symbol (Rp, $, RM, etc.) * Decimal places (0 for IDR, 2 for USD) * Thousand separator (. for IDR, , for USD) * Decimal separator (, for IDR, . for USD) * Position (left/right/left_space/right_space) Examples: - IDR: Rp 100.000 (no decimals, dot separator) - USD: $100.00 (2 decimals, comma separator) - MYR: RM 100.00 (2 decimals) 🔧 Edit Page Fix: - Changed redirect after update: * Before: navigate(`/products/${id}`) → 404 (no detail page) * After: navigate('/products') → products list ✅ Result: ✅ Product forms use active WooCommerce currency ✅ Prices display with correct symbol and format ✅ Input fields respect currency decimals ✅ Edit page redirects to index after save ✅ Consistent with Orders module pattern
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { formatMoney, getStoreCurrency } from '@/lib/currency';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { setQuery, getQuery } from '@/lib/query-params';
|
||||
import { ProductCard } from './components/ProductCard';
|
||||
@@ -386,7 +387,7 @@ export default function Products() {
|
||||
{product.price_html ? (
|
||||
<span dangerouslySetInnerHTML={{ __html: product.price_html }} />
|
||||
) : product.regular_price ? (
|
||||
<span>${parseFloat(product.regular_price).toFixed(2)}</span>
|
||||
<span>{formatMoney(product.regular_price)}</span>
|
||||
) : (
|
||||
<span className="text-muted-foreground">—</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user