From 84690849a1d91df325634382420bc81e90bfed0c Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Sat, 21 Mar 2026 00:57:16 +0100 Subject: [PATCH] update --- api.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/api.php b/api.php index c2392ad..cda3c7b 100644 --- a/api.php +++ b/api.php @@ -547,6 +547,75 @@ if ( \S::get( 'action' ) == 'product_google_category_get' ) ] ); } +// Lista niezoptymalizowanych produktów (brak custom title LUB brak kategorii Google) +if ( \S::get( 'action' ) == 'products_unoptimized_list' ) +{ + api_validate_api_key( $mdb ); + + $client_id_param = (int) \S::get( 'client_id' ); + $limit = (int) \S::get( 'limit' ); + + if ( $client_id_param <= 0 ) + { + api_json_response( [ 'result' => 'error', 'message' => 'Missing required param: client_id' ], 422 ); + } + + if ( $limit <= 0 || $limit > 200 ) + { + $limit = 50; + } + + $rows = $mdb -> query( + 'SELECT p.id, p.offer_id, p.name, p.title, p.google_product_category, + COALESCE( SUM( pa.clicks_all_time ), 0 ) AS clicks_all_time, + COALESCE( SUM( pa.impressions_all_time ), 0 ) AS impressions_all_time, + COALESCE( SUM( pa.cost_all_time ), 0 ) AS cost_all_time + FROM products p + LEFT JOIN products_aggregate pa ON pa.product_id = p.id + WHERE p.client_id = :client_id + AND ( + p.title IS NULL OR p.title = \'\' OR p.title = p.name + OR p.google_product_category IS NULL OR p.google_product_category = \'\' + ) + GROUP BY p.id + ORDER BY clicks_all_time DESC, impressions_all_time DESC + LIMIT :limit', + [ + ':client_id' => (int) $client_id_param, + ':limit' => (int) $limit + ] + ) -> fetchAll( \PDO::FETCH_ASSOC ); + + $products = []; + foreach ( $rows as $row ) + { + $base_name = trim( (string) ( $row['name'] ?? '' ) ); + $custom_title = trim( (string) ( $row['title'] ?? '' ) ); + $google_category = trim( (string) ( $row['google_product_category'] ?? '' ) ); + $is_title_changed = $custom_title !== '' && $custom_title !== $base_name; + + $products[] = [ + 'offer_id' => $row['offer_id'], + 'default_name' => $base_name, + 'custom_title' => $custom_title !== '' ? $custom_title : null, + 'title_changed' => $is_title_changed, + 'google_product_category' => $google_category !== '' ? $google_category : null, + 'needs_title' => !$is_title_changed, + 'needs_category' => $google_category === '', + 'clicks' => (int) $row['clicks_all_time'], + 'impressions' => (int) $row['impressions_all_time'], + 'cost' => round( (float) $row['cost_all_time'], 2 ) + ]; + } + + api_json_response( [ + 'result' => 'ok', + 'client_id' => $client_id_param, + 'count' => count( $products ), + 'products' => $products + ] ); +} + // Odczyt minimalnego ROAS produktu przez API if ( \S::get( 'action' ) == 'product_min_roas_get' ) {