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' )
|
||||
{
|
||||
|
||||
@@ -644,6 +644,63 @@ Bledy specyficzne:
|
||||
- Podano oba identyfikatory jednoczesnie: `422` z `"Provide only one identifier: client_id or google_ads_id"`
|
||||
- Klient nie znaleziony: `404` z `"Client not found"`
|
||||
|
||||
### 4.9 Lista wszystkich produktow klienta
|
||||
|
||||
- `action=products_get_all`
|
||||
- Cel: zwraca wszystkie produkty danego klienta (bez filtra), uzywane do bulk klasyfikacji custom_label_1 / przegladu pelnego asortymentu.
|
||||
|
||||
Parametry:
|
||||
- `api_key` (string, wymagany)
|
||||
- `client_id` (int, wymagany)
|
||||
|
||||
Uwagi:
|
||||
- Brak paginacji - zwraca komplet rekordow z tabeli `products` dla danego `client_id`, sortowane po `offer_id`.
|
||||
- Pola zwracane sa identyczne jak w `products_get_by_cl1` / `products_get_by_cl4`.
|
||||
|
||||
Przyklad:
|
||||
|
||||
```bash
|
||||
curl -X POST "https://example.com/api.php" \
|
||||
-d "action=products_get_all" \
|
||||
-d "api_key=YOUR_API_KEY" \
|
||||
-d "client_id=12"
|
||||
```
|
||||
|
||||
Przyklad odpowiedzi:
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "ok",
|
||||
"client_id": 12,
|
||||
"count": 2,
|
||||
"products": [
|
||||
{
|
||||
"offer_id": "SKU-123",
|
||||
"title": "Lampa sufitowa boho 40cm",
|
||||
"default_name": "Lampa sufitowa boho 40cm",
|
||||
"custom_title": null,
|
||||
"google_product_category": "Home & Garden > Lighting > Light Fixtures",
|
||||
"custom_label_1": "lampy",
|
||||
"custom_label_3": "",
|
||||
"custom_label_4": ""
|
||||
},
|
||||
{
|
||||
"offer_id": "SKU-456",
|
||||
"title": "Tasma LED 5m RGB",
|
||||
"default_name": "Tasma LED 5m",
|
||||
"custom_title": "Tasma LED 5m RGB",
|
||||
"google_product_category": "Home & Garden > Lighting > Light Bulbs",
|
||||
"custom_label_1": "tasmy_led",
|
||||
"custom_label_3": "",
|
||||
"custom_label_4": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Bledy specyficzne:
|
||||
- Brak `client_id`: `422` z `"Missing required param: client_id"`
|
||||
|
||||
## 5. Walidacja i bledy
|
||||
|
||||
### 5.1 Brak wymaganych parametrow
|
||||
|
||||
Reference in New Issue
Block a user