API: products_get_all - lista wszystkich produktow klienta (bulk CL1)

This commit is contained in:
2026-05-11 23:03:03 +02:00
parent b1b5e416ba
commit 9fb1db3006
2 changed files with 108 additions and 0 deletions

51
api.php
View File

@@ -1268,6 +1268,57 @@ if ( \S::get( 'action' ) == 'products_get_by_cl4' )
] );
}
// Lista wszystkich produktów klienta (bez filtra CL); używane do bulk klasyfikacji CL1
if ( \S::get( 'action' ) == 'products_get_all' )
{
api_validate_api_key( $mdb );
$client_id_param = (int) \S::get( 'client_id' );
if ( $client_id_param <= 0 )
{
api_json_response( [ 'result' => 'error', 'message' => 'Missing required param: client_id' ], 422 );
}
$rows = $mdb -> query(
'SELECT p.id, p.offer_id, p.title AS name, p.title_gmc AS 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
ORDER BY p.offer_id',
[
':client_id' => $client_id_param
]
) -> 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,
'count' => count( $products ),
'products' => $products
] );
}
// Open Page Rank - zapis
if ( \S::get( 'action' ) == 'domain_opr_save' )
{