API: products_get_all - lista wszystkich produktow klienta (bulk CL1)
This commit is contained in:
51
api.php
51
api.php
@@ -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' )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user