update
This commit is contained in:
86
api.php
86
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_3, p.custom_label_4
|
||||
'SELECT p.id, p.title AS name, p.title_gmc AS 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
|
||||
@@ -423,7 +423,7 @@ if ( \S::get( 'action' ) == 'product_title_set' )
|
||||
}
|
||||
|
||||
$old_title = (string) ( $product['title'] ?? '' );
|
||||
\factory\Products::set_product_data( (int) $product['id'], 'title', $new_title );
|
||||
\factory\Products::set_product_data( (int) $product['id'], 'title_gmc', $new_title );
|
||||
|
||||
$old_title_for_log = trim( $old_title ) !== '' ? $old_title : '[pusty]';
|
||||
$new_title_for_log = $new_title !== null ? $new_title : '[pusty]';
|
||||
@@ -566,7 +566,7 @@ if ( \S::get( 'action' ) == 'products_unoptimized_list' )
|
||||
}
|
||||
|
||||
$rows = $mdb -> query(
|
||||
'SELECT p.id, p.offer_id, p.name, p.title, p.google_product_category,
|
||||
'SELECT p.id, p.offer_id, p.title AS name, p.title_gmc AS title, p.google_product_category,
|
||||
COALESCE( SUM( pa.clicks_all_time ), 0 ) AS clicks_all_time,
|
||||
COALESCE( SUM( pa.impressions_all_time ), 0 ) AS impressions_all_time,
|
||||
COALESCE( SUM( pa.cost_all_time ), 0 ) AS cost_all_time
|
||||
@@ -574,7 +574,7 @@ if ( \S::get( 'action' ) == 'products_unoptimized_list' )
|
||||
LEFT JOIN products_aggregate pa ON pa.product_id = p.id
|
||||
WHERE p.client_id = :client_id
|
||||
AND (
|
||||
p.title IS NULL OR p.title = \'\' OR p.title = p.name
|
||||
p.title_gmc IS NULL OR p.title_gmc = \'\' OR p.title_gmc = p.title
|
||||
OR p.google_product_category IS NULL OR p.google_product_category = \'\'
|
||||
)
|
||||
GROUP BY p.id
|
||||
@@ -778,8 +778,8 @@ if ( \S::get( 'action' ) == 'products_to_optimize' )
|
||||
$products = $mdb -> query(
|
||||
'SELECT p.id,
|
||||
p.offer_id,
|
||||
p.name AS original_name,
|
||||
p.title AS custom_title,
|
||||
p.title AS original_name,
|
||||
p.title_gmc AS custom_title,
|
||||
p.google_product_category,
|
||||
p.product_url,
|
||||
SUM( pa.clicks_30 ) AS clicks_30,
|
||||
@@ -792,7 +792,7 @@ if ( \S::get( 'action' ) == 'products_to_optimize' )
|
||||
INNER JOIN products_aggregate AS pa ON pa.product_id = p.id
|
||||
WHERE p.client_id = :client_id
|
||||
AND (
|
||||
TRIM( COALESCE( p.title, \'\' ) ) = \'\'
|
||||
TRIM( COALESCE( p.title_gmc, \'\' ) ) = \'\'
|
||||
OR TRIM( COALESCE( p.google_product_category, \'\' ) ) = \'\'
|
||||
)
|
||||
GROUP BY p.id
|
||||
@@ -920,7 +920,7 @@ if ( \S::get( 'action' ) == 'products_get_by_cl1' )
|
||||
}
|
||||
|
||||
$rows = $mdb -> query(
|
||||
'SELECT p.id, p.offer_id, p.name, p.title, p.google_product_category,
|
||||
'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
|
||||
@@ -974,3 +974,73 @@ if ( \S::get( 'action' ) == 'domain_opr_save' )
|
||||
echo json_encode( ['result' => 'ok'] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Zmiana custom_label_1 dla produktu przez API
|
||||
if ( \S::get( 'action' ) == 'product_custom_label_1_set' )
|
||||
{
|
||||
api_validate_api_key( $mdb );
|
||||
|
||||
$offer_id = trim( (string) \S::get( 'offer_id' ) );
|
||||
$client_id_param = (int) \S::get( 'client_id' );
|
||||
$custom_label_1 = trim( (string) ( \S::get( 'custom_label_1' ) ?? \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_1', $custom_label_1 );
|
||||
|
||||
if ( !$update_result )
|
||||
{
|
||||
api_json_response( [ 'result' => 'error', 'message' => 'Failed to update custom_label_1' ], 500 );
|
||||
}
|
||||
|
||||
\factory\Products::add_product_comment( (int) $product['id'], 'Zmiana etykiety 1 na: ' . ( $custom_label_1 !== '' ? $custom_label_1 : '(puste)' ) . ' (API)' );
|
||||
|
||||
api_json_response( [
|
||||
'result' => 'ok',
|
||||
'product_id' => (int) $product['id'],
|
||||
'offer_id' => $offer_id,
|
||||
'client_id' => $client_id_param,
|
||||
'custom_label_1' => $custom_label_1
|
||||
] );
|
||||
}
|
||||
|
||||
// Odczyt custom_label_1 dla produktu przez API
|
||||
if ( \S::get( 'action' ) == 'product_custom_label_1_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_1' => trim( (string) ( $product['custom_label_1'] ?? '' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
// === KONIEC BLOKU ===
|
||||
|
||||
Reference in New Issue
Block a user