debug: Add debug markers to verify ProductsController is running
Added debug markers: 1. _debug field in response with timestamp 2. X-WooNooW-Version header 3. Improved variation attribute retrieval Issue: API returns different structure than code produces Response has: id, name, price (only 9 fields) Code returns: id, name, type, status, price, etc (15+ fields) This suggests: - Response is cached somewhere - Different controller handling request - Middleware transforming response Debug steps: 1. Check response for _debug field 2. Check response headers for X-WooNooW-Version 3. If missing, endpoint not using our code 4. Check wp-content/debug.log for error messages
This commit is contained in:
@@ -167,12 +167,14 @@ class ProductsController {
|
|||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
'pages' => $query->max_num_pages,
|
'pages' => $query->max_num_pages,
|
||||||
|
'_debug' => 'ProductsController-v2-' . time(), // Verify this code is running
|
||||||
], 200);
|
], 200);
|
||||||
|
|
||||||
// Prevent caching
|
// Prevent caching
|
||||||
$response->header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
$response->header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||||
$response->header('Pragma', 'no-cache');
|
$response->header('Pragma', 'no-cache');
|
||||||
$response->header('Expires', '0');
|
$response->header('Expires', '0');
|
||||||
|
$response->header('X-WooNooW-Version', '2.0'); // Debug header
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@@ -579,29 +581,35 @@ class ProductsController {
|
|||||||
|
|
||||||
// Format attributes with human-readable names and values
|
// Format attributes with human-readable names and values
|
||||||
$formatted_attributes = [];
|
$formatted_attributes = [];
|
||||||
$variation_attributes = $variation->get_attributes();
|
|
||||||
|
|
||||||
// Debug: Log raw variation attributes
|
// Get parent product attributes to know what to look for
|
||||||
error_log('WooNooW Debug - Variation #' . $variation_id . ' raw attributes: ' . print_r($variation_attributes, true));
|
$parent_attributes = $product->get_attributes();
|
||||||
|
|
||||||
foreach ($variation_attributes as $attr_name => $attr_value) {
|
foreach ($parent_attributes as $parent_attr) {
|
||||||
// Handle taxonomy attributes (pa_*)
|
if (!$parent_attr->get_variation()) {
|
||||||
if (strpos($attr_name, 'pa_') === 0) {
|
continue; // Skip non-variation attributes
|
||||||
// Global attribute
|
|
||||||
$taxonomy = $attr_name;
|
|
||||||
$clean_name = wc_attribute_label($taxonomy);
|
|
||||||
|
|
||||||
if (!empty($attr_value)) {
|
|
||||||
$term = get_term_by('slug', $attr_value, $taxonomy);
|
|
||||||
$attr_value = $term ? $term->name : $attr_value;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Custom attribute
|
|
||||||
$clean_name = ucfirst(str_replace('_', ' ', $attr_name));
|
|
||||||
// For custom attributes, the value is already the display value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$formatted_attributes[$clean_name] = $attr_value;
|
$attr_name = $parent_attr->get_name();
|
||||||
|
$clean_name = $parent_attr->get_name(); // Already clean for custom attributes
|
||||||
|
|
||||||
|
// Get the variation's value for this attribute
|
||||||
|
if (strpos($attr_name, 'pa_') === 0) {
|
||||||
|
// Global/taxonomy attribute
|
||||||
|
$clean_name = wc_attribute_label($attr_name);
|
||||||
|
$value = $variation->get_attribute($attr_name);
|
||||||
|
|
||||||
|
// Convert slug to term name
|
||||||
|
if (!empty($value)) {
|
||||||
|
$term = get_term_by('slug', $value, $attr_name);
|
||||||
|
$value = $term ? $term->name : $value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Custom attribute - get from meta
|
||||||
|
$value = get_post_meta($variation_id, 'attribute_' . sanitize_title($attr_name), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$formatted_attributes[$clean_name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$variations[] = [
|
$variations[] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user