This commit is contained in:
2026-04-30 01:04:06 +02:00
parent 2903ea2517
commit 2639242ca6
21 changed files with 1989 additions and 116 deletions

View File

@@ -8,8 +8,8 @@ class Products
'custom_label_4',
'custom_label_3',
'custom_label_1',
'title',
'description',
'title_gmc',
'description_gmc',
'google_product_category',
'product_url'
], true );
@@ -32,6 +32,57 @@ class Products
return true;
}
static public function delete_product_scope_history( $product_id, $campaign_id, $ad_group_id )
{
global $mdb;
$product_id = (int) $product_id;
$campaign_id = (int) $campaign_id;
$ad_group_id = (int) $ad_group_id;
if ( $product_id <= 0 )
{
return false;
}
$where = [
'product_id' => $product_id,
'campaign_id' => $campaign_id,
'ad_group_id' => $ad_group_id
];
$pdo = $mdb -> pdo;
$started_tx = false;
try
{
if ( !$pdo -> inTransaction() )
{
$pdo -> beginTransaction();
$started_tx = true;
}
$mdb -> delete( 'products_aggregate', $where );
$mdb -> delete( 'products_history', $where );
$mdb -> delete( 'products_history_30', $where );
if ( $started_tx )
{
$pdo -> commit();
}
return true;
}
catch ( \Throwable $e )
{
if ( $started_tx && $pdo -> inTransaction() )
{
$pdo -> rollBack();
}
return false;
}
}
static public function get_product_comments( $product_id )
{
global $mdb;
@@ -154,8 +205,8 @@ class Products
$sql = 'SELECT
p.id AS product_id,
p.offer_id,
p.name,
p.title,
p.title_gmc,
SUM( pa.impressions_30 ) AS impressions_30
FROM products_aggregate AS pa
INNER JOIN products AS p ON p.id = pa.product_id
@@ -171,9 +222,9 @@ class Products
}
$sql .= '
GROUP BY p.id, p.offer_id, p.name, p.title
GROUP BY p.id, p.offer_id, p.title, p.title_gmc
HAVING COALESCE( SUM( pa.impressions_30 ), 0 ) = 0
ORDER BY COALESCE( NULLIF( TRIM( p.title ), \'\' ), NULLIF( TRIM( p.name ), \'\' ), p.offer_id ) ASC, p.id ASC
ORDER BY COALESCE( NULLIF( TRIM( p.title_gmc ), \'\' ), NULLIF( TRIM( p.title ), \'\' ), p.offer_id ) ASC, p.id ASC
LIMIT ' . $limit;
try
@@ -496,8 +547,8 @@ class Products
if ( $search !== '' )
{
$sql .= ' AND (
p.name LIKE :search
OR p.title LIKE :search
p.title LIKE :search
OR p.title_gmc LIKE :search
OR p.offer_id LIKE :search
OR p.custom_label_4 LIKE :search
OR p.custom_label_1 LIKE :search
@@ -566,7 +617,7 @@ class Products
END AS ad_group_name,
MIN( pa.campaign_id ) AS history_campaign_id,
MIN( pa.ad_group_id ) AS history_ad_group_id,
COALESCE( NULLIF( TRIM( p.title ), \'\' ), NULLIF( TRIM( p.name ), \'\' ), p.offer_id ) AS name,
COALESCE( NULLIF( TRIM( p.title_gmc ), \'\' ), NULLIF( TRIM( p.title ), \'\' ), p.offer_id ) AS name,
SUM( pa.impressions_all_time ) AS impressions,
SUM( pa.impressions_30 ) AS impressions_30,
SUM( pa.clicks_all_time ) AS clicks,
@@ -595,7 +646,7 @@ class Products
self::build_scope_filters( $sql, $params, $campaign_id, $ad_group_id );
self::build_products_filters( $sql, $params, $search, $custom_label_4, $custom_label_1 );
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_1, p.name, p.title';
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_1, p.title, p.title_gmc';
$sql .= ' ORDER BY ' . $order_sql . ' ' . $order_dir . ', product_id DESC LIMIT ' . $start . ', ' . $limit;
return $mdb -> query( $sql, $params ) -> fetchAll( \PDO::FETCH_ASSOC );
@@ -773,7 +824,7 @@ class Products
'SELECT
p.id,
p.offer_id,
p.name,
p.title,
p.min_roas,
COALESCE( SUM( pa.impressions_all_time ), 0 ) AS impressions,
COALESCE( SUM( pa.impressions_30 ), 0 ) AS impressions_30,
@@ -800,7 +851,7 @@ class Products
FROM products AS p
LEFT JOIN products_aggregate AS pa ON pa.product_id = p.id
WHERE p.id = :pid
GROUP BY p.id, p.offer_id, p.name, p.min_roas',
GROUP BY p.id, p.offer_id, p.title, p.min_roas',
[ ':pid' => $product_id ]
) -> fetch( \PDO::FETCH_ASSOC );
}
@@ -883,7 +934,7 @@ class Products
return null;
}
return $mdb -> get( 'products', 'name', [ 'id' => $product_id ] );
return $mdb -> get( 'products', 'title', [ 'id' => $product_id ] );
}
static public function get_product_merchant_context( $product_id )
@@ -1269,7 +1320,7 @@ class Products
p.id,
p.client_id,
p.offer_id,
p.name,
p.title,
cl.google_ads_customer_id,
cl.google_merchant_account_id
FROM products AS p