update
This commit is contained in:
8
.vscode/ftp-kr.sync.cache.json
vendored
8
.vscode/ftp-kr.sync.cache.json
vendored
@@ -9,8 +9,8 @@
|
||||
},
|
||||
"api.php": {
|
||||
"type": "-",
|
||||
"size": 18156,
|
||||
"lmtime": 1773088345243,
|
||||
"size": 19666,
|
||||
"lmtime": 1773184004748,
|
||||
"modified": false
|
||||
},
|
||||
"autoload": {
|
||||
@@ -302,8 +302,8 @@
|
||||
"docs": {
|
||||
"api-public-product-management.md": {
|
||||
"type": "-",
|
||||
"size": 12452,
|
||||
"lmtime": 1773088360435,
|
||||
"size": 13629,
|
||||
"lmtime": 1773184070257,
|
||||
"modified": false
|
||||
},
|
||||
"class-methods.md": {
|
||||
|
||||
70
api.php
70
api.php
@@ -58,7 +58,7 @@ function api_validate_api_key( $mdb )
|
||||
function api_get_product_by_offer_and_client( $mdb, $offer_id, $client_id )
|
||||
{
|
||||
return $mdb -> query(
|
||||
'SELECT p.id, p.name, p.title, p.google_product_category, p.custom_label_4
|
||||
'SELECT p.id, p.name, p.title, p.google_product_category, p.custom_label_3, p.custom_label_4
|
||||
FROM products p
|
||||
JOIN clients cl ON p.client_id = cl.id
|
||||
WHERE p.offer_id = :offer_id
|
||||
@@ -198,6 +198,74 @@ if ( \S::get( 'action' ) == 'campaign_comment_add' )
|
||||
exit;
|
||||
}
|
||||
|
||||
// Zmiana custom_label_3 dla produktu przez API
|
||||
if ( \S::get( 'action' ) == 'product_custom_label_3_set' )
|
||||
{
|
||||
api_validate_api_key( $mdb );
|
||||
|
||||
$offer_id = trim( (string) \S::get( 'offer_id' ) );
|
||||
$client_id_param = (int) \S::get( 'client_id' );
|
||||
$custom_label_3 = trim( (string) ( \S::get( 'custom_label_3' ) ?? \S::get( 'value' ) ?? '' ) );
|
||||
|
||||
if ( $offer_id === '' || $client_id_param <= 0 )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Missing required params: offer_id, client_id' ], 422 );
|
||||
}
|
||||
|
||||
$product = api_get_product_by_offer_and_client( $mdb, $offer_id, $client_id_param );
|
||||
|
||||
if ( !$product )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Product not found' ], 404 );
|
||||
}
|
||||
|
||||
$update_result = \factory\Products::set_product_data( (int) $product['id'], 'custom_label_3', $custom_label_3 );
|
||||
|
||||
if ( !$update_result )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Failed to update custom_label_3' ], 500 );
|
||||
}
|
||||
|
||||
\factory\Products::add_product_comment( (int) $product['id'], 'Zmiana etykiety 3 na: ' . ( $custom_label_3 !== '' ? $custom_label_3 : '(puste)' ) . ' (API)' );
|
||||
|
||||
api_json_response( [
|
||||
'result' => 'ok',
|
||||
'product_id' => (int) $product['id'],
|
||||
'offer_id' => $offer_id,
|
||||
'client_id' => $client_id_param,
|
||||
'custom_label_3' => $custom_label_3
|
||||
] );
|
||||
}
|
||||
|
||||
// Odczyt custom_label_3 dla produktu przez API
|
||||
if ( \S::get( 'action' ) == 'product_custom_label_3_get' )
|
||||
{
|
||||
api_validate_api_key( $mdb );
|
||||
|
||||
$offer_id = trim( (string) \S::get( 'offer_id' ) );
|
||||
$client_id_param = (int) \S::get( 'client_id' );
|
||||
|
||||
if ( $offer_id === '' || $client_id_param <= 0 )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Missing required params: offer_id, client_id' ], 422 );
|
||||
}
|
||||
|
||||
$product = api_get_product_by_offer_and_client( $mdb, $offer_id, $client_id_param );
|
||||
|
||||
if ( !$product )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Product not found' ], 404 );
|
||||
}
|
||||
|
||||
api_json_response( [
|
||||
'result' => 'ok',
|
||||
'product_id' => (int) $product['id'],
|
||||
'offer_id' => $offer_id,
|
||||
'client_id' => $client_id_param,
|
||||
'custom_label_3' => trim( (string) ( $product['custom_label_3'] ?? '' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
// Zmiana custom_label_4 dla produktu przez API
|
||||
if ( \S::get( 'action' ) == 'product_custom_label_4_set' )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user