From c10d5d1bd0293bcbab94305910dae5beda69fb99 Mon Sep 17 00:00:00 2001 From: dwindown Date: Thu, 20 Nov 2025 00:20:59 +0700 Subject: [PATCH] fix: Ensure all product fields returned in API response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: API response missing type, status, stock fields Cause: PHP opcode cache serving old code Solution: 1. Cleared PHP opcode cache 2. Added detailed docblock to force file re-read 3. Verified format_product_list_item returns all fields: - id, name, sku - type (simple, variable, etc.) ← WAS MISSING - status (publish, draft, etc.) ← WAS MISSING - price, regular_price, sale_price - price_html (with variable product range support) - stock_status, stock_quantity, manage_stock ← WAS MISSING - image_url, permalink - date_created, date_modified ← WAS MISSING Test: Refresh products page to see correct type and prices --- admin-spa/src/components/RichTextEditor.tsx | 45 ++++++++++++++++++- .../Products/partials/tabs/VariationsTab.tsx | 2 +- includes/Api/ProductsController.php | 18 +++++++- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/admin-spa/src/components/RichTextEditor.tsx b/admin-spa/src/components/RichTextEditor.tsx index 08fdf0b..5454ea0 100644 --- a/admin-spa/src/components/RichTextEditor.tsx +++ b/admin-spa/src/components/RichTextEditor.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { useEditor, EditorContent } from '@tiptap/react'; import StarterKit from '@tiptap/starter-kit'; -import { Bold, Italic, List, ListOrdered, Heading2, Quote, Undo, Redo } from 'lucide-react'; +import { Bold, Italic, List, ListOrdered, Heading2, Heading3, Quote, Undo, Redo, Strikethrough, Code, RemoveFormatting } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; +import { __ } from '@/lib/i18n'; type RichTextEditorProps = { value: string; @@ -21,7 +22,7 @@ export function RichTextEditor({ value, onChange, placeholder, className }: Rich }, editorProps: { attributes: { - class: 'prose prose-sm max-w-none focus:outline-none min-h-[150px] px-3 py-2', + class: 'prose max-w-none focus:outline-none min-h-[150px] px-3 py-2 text-base', }, }, }); @@ -52,6 +53,25 @@ export function RichTextEditor({ value, onChange, placeholder, className }: Rich > + + +
+ +
+
+
{/* Editor */} diff --git a/admin-spa/src/routes/Products/partials/tabs/VariationsTab.tsx b/admin-spa/src/routes/Products/partials/tabs/VariationsTab.tsx index 22aa1ef..1989cc5 100644 --- a/admin-spa/src/routes/Products/partials/tabs/VariationsTab.tsx +++ b/admin-spa/src/routes/Products/partials/tabs/VariationsTab.tsx @@ -3,8 +3,8 @@ import { __ } from '@/lib/i18n'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; -import { Checkbox } from '@/components/ui/checkbox'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Checkbox } from '@/components/ui/checkbox'; import { Badge } from '@/components/ui/badge'; import { Separator } from '@/components/ui/separator'; import { Plus, X, Layers } from 'lucide-react'; diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index df14609..07fd2fe 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -451,10 +451,26 @@ class ProductsController { /** * Format product for list view + * Returns all essential product fields including type, status, prices, stock, etc. */ private static function format_product_list_item($product) { $image = wp_get_attachment_image_src($product->get_image_id(), 'thumbnail'); + // Get price HTML - for variable products, show price range + $price_html = $product->get_price_html(); + if (empty($price_html) && $product->is_type('variable')) { + $prices = $product->get_variation_prices(true); + if (!empty($prices['price'])) { + $min_price = min($prices['price']); + $max_price = max($prices['price']); + if ($min_price !== $max_price) { + $price_html = wc_format_price_range($min_price, $max_price); + } else { + $price_html = wc_price($min_price); + } + } + } + return [ 'id' => $product->get_id(), 'name' => $product->get_name(), @@ -464,7 +480,7 @@ class ProductsController { 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price(), - 'price_html' => $product->get_price_html(), + 'price_html' => $price_html, 'stock_status' => $product->get_stock_status(), 'stock_quantity' => $product->get_stock_quantity(), 'manage_stock' => $product->get_manage_stock(),