update
This commit is contained in:
@@ -104,6 +104,7 @@ class Clients
|
||||
$google_ads_customer_id = trim( \S::get( 'google_ads_customer_id' ) );
|
||||
$google_merchant_account_id = trim( \S::get( 'google_merchant_account_id' ) );
|
||||
$facebook_ads_account_id = self::normalize_facebook_ads_account_id( \S::get( 'facebook_ads_account_id' ) );
|
||||
$xml_feed_url = trim( \S::get( 'xml_feed_url' ) );
|
||||
$active_raw = \S::get( 'active' );
|
||||
$active = (string) $active_raw === '0' ? 0 : 1;
|
||||
|
||||
@@ -114,6 +115,13 @@ class Clients
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $xml_feed_url !== '' && !filter_var( $xml_feed_url, FILTER_VALIDATE_URL ) )
|
||||
{
|
||||
\S::alert( 'Niepoprawny URL feedu XML.' );
|
||||
header( 'Location: /clients' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$google_ads_start_date = trim( \S::get( 'google_ads_start_date' ) );
|
||||
|
||||
$data = [
|
||||
@@ -121,6 +129,7 @@ class Clients
|
||||
'google_ads_customer_id' => $google_ads_customer_id ?: null,
|
||||
'google_merchant_account_id' => $google_merchant_account_id ?: null,
|
||||
'facebook_ads_account_id' => $facebook_ads_account_id,
|
||||
'xml_feed_url' => $xml_feed_url ?: null,
|
||||
'google_ads_start_date' => $google_ads_start_date ?: null,
|
||||
'active' => $active,
|
||||
];
|
||||
|
||||
@@ -132,6 +132,23 @@ class Cron
|
||||
$products_temp_rows_total += (int) self::rebuild_products_temp_for_client( (int) $client['id'] );
|
||||
}
|
||||
|
||||
$xml_feed_report = null;
|
||||
if ( !empty( $client['xml_feed_url'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$xml_feed_report = \services\XmlFeedImporter::import_for_client( (int) $client['id'] );
|
||||
if ( !empty( $xml_feed_report['errors'] ) )
|
||||
{
|
||||
$products_errors = array_merge( $products_errors, (array) $xml_feed_report['errors'] );
|
||||
}
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
$products_errors[] = 'XML feed import: ' . $e -> getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$errors = array_merge( $campaign_errors, $products_errors );
|
||||
|
||||
self::output_cron_response( [
|
||||
@@ -152,6 +169,7 @@ class Cron
|
||||
'products_fetch_skipped_reasons' => array_keys( $products_fetch_skipped_reasons ),
|
||||
'history_30_products' => $history_30_products_total,
|
||||
'products_temp_rows' => $products_temp_rows_total,
|
||||
'xml_feed' => $xml_feed_report,
|
||||
'errors' => $errors
|
||||
] );
|
||||
}
|
||||
@@ -934,7 +952,7 @@ class Cron
|
||||
}
|
||||
|
||||
$not_found_rows = $mdb -> query(
|
||||
"SELECT id AS product_id, offer_id, name, title
|
||||
"SELECT id AS product_id, offer_id, title, title_gmc
|
||||
FROM products
|
||||
WHERE client_id = :client_id
|
||||
AND TRIM( COALESCE( offer_id, '' ) ) <> ''
|
||||
@@ -950,10 +968,10 @@ class Cron
|
||||
{
|
||||
$offer_id = trim( (string) ( $row['offer_id'] ?? '' ) );
|
||||
$product_id = (int) ( $row['product_id'] ?? 0 );
|
||||
$product_name = trim( (string) ( $row['title'] ?? '' ) );
|
||||
$product_name = trim( (string) ( $row['title_gmc'] ?? '' ) );
|
||||
if ( $product_name === '' )
|
||||
{
|
||||
$product_name = trim( (string) ( $row['name'] ?? '' ) );
|
||||
$product_name = trim( (string) ( $row['title'] ?? '' ) );
|
||||
}
|
||||
if ( $product_name === '' )
|
||||
{
|
||||
@@ -1109,7 +1127,7 @@ class Cron
|
||||
}
|
||||
|
||||
$existing_products_rows = $mdb -> query(
|
||||
'SELECT id, offer_id, name, title, product_url
|
||||
'SELECT id, offer_id, title, title_gmc, product_url
|
||||
FROM products
|
||||
WHERE client_id = :client_id
|
||||
ORDER BY id ASC',
|
||||
@@ -1127,8 +1145,8 @@ class Cron
|
||||
|
||||
$products_by_offer_id[ $offer_id ] = [
|
||||
'id' => (int) ( $row['id'] ?? 0 ),
|
||||
'name' => (string) ( $row['name'] ?? '' ),
|
||||
'title' => (string) ( $row['title'] ?? '' ),
|
||||
'title_gmc' => (string) ( $row['title_gmc'] ?? '' ),
|
||||
'product_url' => (string) ( $row['product_url'] ?? '' )
|
||||
];
|
||||
}
|
||||
@@ -1366,14 +1384,14 @@ class Cron
|
||||
$mdb -> insert( 'products', [
|
||||
'client_id' => $client_id,
|
||||
'offer_id' => $offer_external_id,
|
||||
'name' => $product_title
|
||||
'title' => $product_title
|
||||
] );
|
||||
|
||||
$product_id = $mdb -> id();
|
||||
|
||||
$products_by_offer_id[ $offer_external_id ] = [
|
||||
'id' => (int) $product_id,
|
||||
'name' => $product_title,
|
||||
'title' => $product_title,
|
||||
'product_url' => ''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -319,10 +319,10 @@ class Products
|
||||
}
|
||||
|
||||
$offer_id = trim( (string) ( $row['offer_id'] ?? '' ) );
|
||||
$product_name = trim( (string) ( $row['title'] ?? '' ) );
|
||||
$product_name = trim( (string) ( $row['title_gmc'] ?? '' ) );
|
||||
if ( $product_name === '' )
|
||||
{
|
||||
$product_name = trim( (string) ( $row['name'] ?? '' ) );
|
||||
$product_name = trim( (string) ( $row['title'] ?? '' ) );
|
||||
}
|
||||
if ( $product_name === '' )
|
||||
{
|
||||
@@ -697,8 +697,8 @@ class Products
|
||||
$product_id = \S::get( 'product_id' );
|
||||
|
||||
$product_name = \factory\Products::get_product_name( $product_id );
|
||||
$product_title = \factory\Products::get_product_data( $product_id, 'title' );
|
||||
$product_description = \factory\Products::get_product_data( $product_id, 'description' );
|
||||
$product_title = \factory\Products::get_product_data( $product_id, 'title_gmc' );
|
||||
$product_description = \factory\Products::get_product_data( $product_id, 'description_gmc' );
|
||||
$google_product_category = \factory\Products::get_product_data( $product_id, 'google_product_category' );
|
||||
$product_url = \factory\Products::get_product_data( $product_id, 'product_url' );
|
||||
|
||||
@@ -854,9 +854,9 @@ class Products
|
||||
}
|
||||
|
||||
$context = [
|
||||
'original_name' => $product['name'],
|
||||
'current_title' => \factory\Products::get_product_data( $product_id, 'title' ),
|
||||
'current_description' => \factory\Products::get_product_data( $product_id, 'description' ),
|
||||
'original_name' => $product['title'],
|
||||
'current_title' => \factory\Products::get_product_data( $product_id, 'title_gmc' ),
|
||||
'current_description' => \factory\Products::get_product_data( $product_id, 'description_gmc' ),
|
||||
'current_category' => \factory\Products::get_product_data( $product_id, 'google_product_category' ),
|
||||
'offer_id' => $product['offer_id'],
|
||||
'impressions_30' => $product['impressions_30'] ?? 0,
|
||||
@@ -986,7 +986,7 @@ class Products
|
||||
$custom_class = '';
|
||||
$custom_label_4 = \factory\Products::get_product_data( $product_id, 'custom_label_4' );
|
||||
$custom_label_1 = \factory\Products::get_product_data( $product_id, 'custom_label_1' );
|
||||
$custom_name = \factory\Products::get_product_data( $product_id, 'title' );
|
||||
$custom_name = \factory\Products::get_product_data( $product_id, 'title_gmc' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $product_id, 'product_url' ) );
|
||||
|
||||
if ( $custom_name )
|
||||
@@ -1095,6 +1095,9 @@ class Products
|
||||
foreach ( $breakdown_rows as $breakdown_row )
|
||||
{
|
||||
$breakdown_for_view[] = [
|
||||
'product_id' => (int) ( $breakdown_row['product_id'] ?? $product_id ),
|
||||
'campaign_id' => (int) ( $breakdown_row['campaign_id'] ?? 0 ),
|
||||
'ad_group_id' => (int) ( $breakdown_row['ad_group_id'] ?? 0 ),
|
||||
'campaign_name' => (string) ( $breakdown_row['campaign_name'] ?? '' ),
|
||||
'ad_group_name' => (string) ( $breakdown_row['ad_group_name'] ?? '' ),
|
||||
'impressions' => (int) ( $breakdown_row['impressions'] ?? 0 ),
|
||||
@@ -1185,6 +1188,29 @@ class Products
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function delete_product_scope_history()
|
||||
{
|
||||
$product_id = (int) \S::get( 'product_id' );
|
||||
$campaign_id = (int) \S::get( 'campaign_id' );
|
||||
$ad_group_id = (int) \S::get( 'ad_group_id' );
|
||||
|
||||
if ( $product_id <= 0 )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'message' => 'Brak identyfikatora produktu.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \factory\Products::delete_product_scope_history( $product_id, $campaign_id, $ad_group_id ) )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'message' => 'Nie udalo sie usunac wpisow historii dla tego zakresu.' ] );
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function save_min_roas()
|
||||
{
|
||||
$product_id = \S::get( 'product_id' );
|
||||
@@ -1390,8 +1416,8 @@ class Products
|
||||
$google_product_category = \S::get( 'google_product_category' );
|
||||
$product_url = \S::get( 'product_url' );
|
||||
|
||||
$old_title = (string) \factory\Products::get_product_data( $product_id, 'title' );
|
||||
$old_description = (string) \factory\Products::get_product_data( $product_id, 'description' );
|
||||
$old_title = (string) \factory\Products::get_product_data( $product_id, 'title_gmc' );
|
||||
$old_description = (string) \factory\Products::get_product_data( $product_id, 'description_gmc' );
|
||||
$old_category = (string) \factory\Products::get_product_data( $product_id, 'google_product_category' );
|
||||
|
||||
$changed_for_merchant = [];
|
||||
@@ -1400,13 +1426,13 @@ class Products
|
||||
{
|
||||
if ( $custom_title )
|
||||
{
|
||||
\factory\Products::set_product_data( $product_id, 'title', $custom_title );
|
||||
\factory\Products::set_product_data( $product_id, 'title_gmc', $custom_title );
|
||||
$changed_for_merchant['title'] = [ 'old' => $old_title, 'new' => (string) $custom_title ];
|
||||
}
|
||||
|
||||
if ( $custom_description )
|
||||
{
|
||||
\factory\Products::set_product_data( $product_id, 'description', $custom_description );
|
||||
\factory\Products::set_product_data( $product_id, 'description_gmc', $custom_description );
|
||||
$changed_for_merchant['description'] = [ 'old' => $old_description, 'new' => (string) $custom_description ];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user