diff --git a/api.php b/api.php index cda3c7b..a5ec289 100644 --- a/api.php +++ b/api.php @@ -901,6 +901,66 @@ if ( \S::get( 'action' ) == 'campaign_roas_history_get' ) ] ); } +// Lista produktów filtrowana po custom_label_1 (źródło dla kampanii [PLA_CL1] Shopping) +if ( \S::get( 'action' ) == 'products_get_by_cl1' ) +{ + api_validate_api_key( $mdb ); + + $client_id_param = (int) \S::get( 'client_id' ); + $cl1_value = trim( (string) \S::get( 'custom_label_1' ) ); + + if ( $client_id_param <= 0 ) + { + api_json_response( [ 'result' => 'error', 'message' => 'Missing required param: client_id' ], 422 ); + } + + if ( $cl1_value === '' ) + { + api_json_response( [ 'result' => 'error', 'message' => 'Missing required param: custom_label_1' ], 422 ); + } + + $rows = $mdb -> query( + 'SELECT p.id, p.offer_id, p.name, p.title, p.google_product_category, + p.custom_label_1, p.custom_label_3, p.custom_label_4 + FROM products p + WHERE p.client_id = :client_id + AND p.custom_label_1 = :cl1 + ORDER BY p.offer_id', + [ + ':client_id' => $client_id_param, + ':cl1' => $cl1_value + ] + ) -> fetchAll( \PDO::FETCH_ASSOC ); + + $products = []; + foreach ( $rows as $row ) + { + $base_name = trim( (string) ( $row['name'] ?? '' ) ); + $custom_title = trim( (string) ( $row['title'] ?? '' ) ); + $title = $custom_title !== '' ? $custom_title : $base_name; + $google_category = trim( (string) ( $row['google_product_category'] ?? '' ) ); + + $products[] = [ + 'offer_id' => (string) ( $row['offer_id'] ?? '' ), + 'title' => $title, + 'default_name' => $base_name, + 'custom_title' => $custom_title !== '' ? $custom_title : null, + 'google_product_category' => $google_category !== '' ? $google_category : null, + 'custom_label_1' => trim( (string) ( $row['custom_label_1'] ?? '' ) ), + 'custom_label_3' => trim( (string) ( $row['custom_label_3'] ?? '' ) ), + 'custom_label_4' => trim( (string) ( $row['custom_label_4'] ?? '' ) ) + ]; + } + + api_json_response( [ + 'result' => 'ok', + 'client_id' => $client_id_param, + 'custom_label_1' => $cl1_value, + 'count' => count( $products ), + 'products' => $products + ] ); +} + // Open Page Rank - zapis if ( \S::get( 'action' ) == 'domain_opr_save' ) {