From 07b5b072c2534cb59b953a4ec5fe2ff4755686ec Mon Sep 17 00:00:00 2001 From: dwindown Date: Wed, 19 Nov 2025 23:32:59 +0700 Subject: [PATCH] fix: Use active WooCommerce currency instead of hardcoded USD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: - icon (always $) - step="0.01" (always 2 decimals) - placeholder="0.00" (always 2 decimals) After: - {store.symbol} (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 --- admin-spa/src/routes/Products/Edit.tsx | 4 ++-- admin-spa/src/routes/Products/index.tsx | 3 ++- .../Products/partials/tabs/GeneralTab.tsx | 20 +++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/admin-spa/src/routes/Products/Edit.tsx b/admin-spa/src/routes/Products/Edit.tsx index ab9726f..b8386b1 100644 --- a/admin-spa/src/routes/Products/Edit.tsx +++ b/admin-spa/src/routes/Products/Edit.tsx @@ -39,8 +39,8 @@ export default function ProductEdit() { queryClient.invalidateQueries({ queryKey: ['products'] }); queryClient.invalidateQueries({ queryKey: ['products', id] }); - // Navigate back to product detail or list - navigate(`/products/${id}`); + // Navigate back to products list + navigate('/products'); }, onError: (error: any) => { toast.error(error.message || __('Failed to update product')); diff --git a/admin-spa/src/routes/Products/index.tsx b/admin-spa/src/routes/Products/index.tsx index ad53cc8..21d3ffb 100644 --- a/admin-spa/src/routes/Products/index.tsx +++ b/admin-spa/src/routes/Products/index.tsx @@ -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 ? ( ) : product.regular_price ? ( - ${parseFloat(product.regular_price).toFixed(2)} + {formatMoney(product.regular_price)} ) : ( )} diff --git a/admin-spa/src/routes/Products/partials/tabs/GeneralTab.tsx b/admin-spa/src/routes/Products/partials/tabs/GeneralTab.tsx index e9984b4..af5c584 100644 --- a/admin-spa/src/routes/Products/partials/tabs/GeneralTab.tsx +++ b/admin-spa/src/routes/Products/partials/tabs/GeneralTab.tsx @@ -8,6 +8,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Separator } from '@/components/ui/separator'; import { DollarSign } from 'lucide-react'; +import { getStoreCurrency } from '@/lib/currency'; type GeneralTabProps = { name: string; @@ -63,6 +64,9 @@ export function GeneralTab({ salePrice && regularPrice && parseFloat(salePrice) < parseFloat(regularPrice) ? Math.round((1 - parseFloat(salePrice) / parseFloat(regularPrice)) * 100) : 0; + + const store = getStoreCurrency(); + return ( @@ -187,14 +191,16 @@ export function GeneralTab({ {__('Regular Price')} {type === 'simple' && '*'}
- + + {store.symbol} + setRegularPrice(e.target.value)} - placeholder="0.00" + placeholder={store.decimals === 0 ? '0' : '0.00'} required={type === 'simple'} className="pl-10" /> @@ -209,14 +215,16 @@ export function GeneralTab({
- + + {store.symbol} + setSalePrice(e.target.value)} - placeholder="0.00" + placeholder={store.decimals === 0 ? '0' : '0.00'} className="pl-10" />