fix: Ensure all product fields returned in API response

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
This commit is contained in:
dwindown
2025-11-20 00:20:59 +07:00
parent c686777c7c
commit c10d5d1bd0
3 changed files with 61 additions and 4 deletions

View File

@@ -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(),