fix: category selection, checkout redirect, sidebar shipping visibility

1. Category Selection Bug:
   - Added 'id' alias to category/tag API responses
   - Frontend uses cat.id which was undefined (API returned term_id)

2. Checkout Redirect:
   - Changed from window.location.href + reload to navigate()
   - Added !isProcessing check to empty cart condition

3. Sidebar Shipping for Virtual-Only:
   - Hide Shipping Method section when isVirtualOnly
   - Hide Shipping row in totals when isVirtualOnly

4. License Table:
   - Table creation runs via ensure_tables() on plugins_loaded
This commit is contained in:
Dwindi Ramadhana
2026-01-07 22:26:58 +07:00
parent 2cc20ff760
commit 3a08e80c1f
2 changed files with 16 additions and 12 deletions

View File

@@ -304,11 +304,11 @@ export default function Checkout() {
toast.success('Order placed successfully!'); toast.success('Order placed successfully!');
// Use full page reload instead of SPA routing // Navigate to thank you page via SPA routing
// This ensures auto-registered users get their auth cookies properly set // Using window.location.replace to prevent back button issues
const thankYouUrl = `${window.location.origin}/store/#/order-received/${data.order_id}?key=${data.order_key}`; const thankYouUrl = `/order-received/${data.order_id}?key=${data.order_key}`;
window.location.href = thankYouUrl; navigate(thankYouUrl, { replace: true });
window.location.reload(); return; // Stop execution here
} else { } else {
throw new Error(data.error || 'Failed to create order'); throw new Error(data.error || 'Failed to create order');
} }
@@ -320,8 +320,8 @@ export default function Checkout() {
} }
}; };
// Empty cart redirect // Empty cart redirect (but only if not processing)
if (cart.items.length === 0) { if (cart.items.length === 0 && !isProcessing) {
return ( return (
<Container> <Container>
<div className="text-center py-16"> <div className="text-center py-16">
@@ -771,7 +771,7 @@ export default function Checkout() {
</div> </div>
{/* Shipping Options */} {/* Shipping Options */}
{elements.shipping_options && ( {!isVirtualOnly && elements.shipping_options && (
<div className="mb-4 pb-4 border-b"> <div className="mb-4 pb-4 border-b">
<h3 className="font-medium mb-3">Shipping Method</h3> <h3 className="font-medium mb-3">Shipping Method</h3>
<div className="space-y-2"> <div className="space-y-2">
@@ -806,10 +806,12 @@ export default function Checkout() {
<span>-{formatPrice(discountTotal)}</span> <span>-{formatPrice(discountTotal)}</span>
</div> </div>
)} )}
{!isVirtualOnly && (
<div className="flex justify-between text-sm"> <div className="flex justify-between text-sm">
<span>Shipping</span> <span>Shipping</span>
<span>{shipping === 0 ? 'Free' : formatPrice(shipping)}</span> <span>{shipping === 0 ? 'Free' : formatPrice(shipping)}</span>
</div> </div>
)}
{tax > 0 && ( {tax > 0 && (
<div className="flex justify-between text-sm"> <div className="flex justify-between text-sm">
<span>Tax</span> <span>Tax</span>

View File

@@ -621,6 +621,7 @@ class ProductsController {
$categories = []; $categories = [];
foreach ($terms as $term) { foreach ($terms as $term) {
$categories[] = [ $categories[] = [
'id' => $term->term_id,
'term_id' => $term->term_id, 'term_id' => $term->term_id,
'name' => $term->name, 'name' => $term->name,
'slug' => $term->slug, 'slug' => $term->slug,
@@ -649,6 +650,7 @@ class ProductsController {
$tags = []; $tags = [];
foreach ($terms as $term) { foreach ($terms as $term) {
$tags[] = [ $tags[] = [
'id' => $term->term_id,
'term_id' => $term->term_id, 'term_id' => $term->term_id,
'name' => $term->name, 'name' => $term->name,
'slug' => $term->slug, 'slug' => $term->slug,