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": {
|
"api.php": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 18156,
|
"size": 19666,
|
||||||
"lmtime": 1773088345243,
|
"lmtime": 1773184004748,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -302,8 +302,8 @@
|
|||||||
"docs": {
|
"docs": {
|
||||||
"api-public-product-management.md": {
|
"api-public-product-management.md": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 12452,
|
"size": 13629,
|
||||||
"lmtime": 1773088360435,
|
"lmtime": 1773184070257,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"class-methods.md": {
|
"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 )
|
function api_get_product_by_offer_and_client( $mdb, $offer_id, $client_id )
|
||||||
{
|
{
|
||||||
return $mdb -> query(
|
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
|
FROM products p
|
||||||
JOIN clients cl ON p.client_id = cl.id
|
JOIN clients cl ON p.client_id = cl.id
|
||||||
WHERE p.offer_id = :offer_id
|
WHERE p.offer_id = :offer_id
|
||||||
@@ -198,6 +198,74 @@ if ( \S::get( 'action' ) == 'campaign_comment_add' )
|
|||||||
exit;
|
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
|
// Zmiana custom_label_4 dla produktu przez API
|
||||||
if ( \S::get( 'action' ) == 'product_custom_label_4_set' )
|
if ( \S::get( 'action' ) == 'product_custom_label_4_set' )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user