update
This commit is contained in:
@@ -965,6 +965,10 @@ class Products
|
||||
|
||||
$db_results = \factory\Products::get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$recordsTotal = \factory\Products::get_records_total_products( $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$product_ids = array_values( array_unique( array_filter( array_map( function( $row ) {
|
||||
return (int) ( $row['product_id'] ?? 0 );
|
||||
}, (array) $db_results ) ) ) );
|
||||
$breakdown_map = \factory\Products::get_products_scope_breakdown( $client_id, $product_ids, $campaign_id, $ad_group_id, $search, $filter_cl4, $filter_cl1 );
|
||||
|
||||
// Sredni CR konta — do obliczenia progu klikniec
|
||||
$account_cr = \factory\Products::get_account_conversion_rate( (int) $client_id );
|
||||
@@ -977,11 +981,13 @@ class Products
|
||||
|
||||
foreach ( $db_results as $row )
|
||||
{
|
||||
$product_id = (int) ( $row['product_id'] ?? 0 );
|
||||
$breakdown_rows = (array) ( $breakdown_map[ $product_id ] ?? [] );
|
||||
$custom_class = '';
|
||||
$custom_label_4 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_4' );
|
||||
$custom_label_1 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_1' );
|
||||
$custom_name = \factory\Products::get_product_data( $row['product_id'], 'title' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $row['product_id'], 'product_url' ) );
|
||||
$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' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $product_id, 'product_url' ) );
|
||||
|
||||
if ( $custom_name )
|
||||
{
|
||||
@@ -1074,29 +1080,56 @@ class Products
|
||||
|
||||
$history_campaign_id = (int) ( $row['history_campaign_id'] ?? 0 );
|
||||
$history_ad_group_id = (int) ( $row['history_ad_group_id'] ?? 0 );
|
||||
$breakdown_for_view = [];
|
||||
|
||||
if ( $history_campaign_id <= 0 )
|
||||
if ( $history_campaign_id <= 0 && !empty( $breakdown_rows ) )
|
||||
{
|
||||
$history_campaign_id = (int) ( $row['campaign_id'] ?? 0 );
|
||||
$history_campaign_id = (int) ( $breakdown_rows[0]['campaign_id'] ?? 0 );
|
||||
}
|
||||
|
||||
if ( $history_ad_group_id <= 0 )
|
||||
if ( $history_ad_group_id <= 0 && !empty( $breakdown_rows ) )
|
||||
{
|
||||
$history_ad_group_id = (int) ( $row['ad_group_id'] ?? 0 );
|
||||
$history_ad_group_id = (int) ( $breakdown_rows[0]['ad_group_id'] ?? 0 );
|
||||
}
|
||||
|
||||
foreach ( $breakdown_rows as $breakdown_row )
|
||||
{
|
||||
$breakdown_for_view[] = [
|
||||
'campaign_name' => (string) ( $breakdown_row['campaign_name'] ?? '' ),
|
||||
'ad_group_name' => (string) ( $breakdown_row['ad_group_name'] ?? '' ),
|
||||
'impressions' => (int) ( $breakdown_row['impressions'] ?? 0 ),
|
||||
'impressions_30' => (int) ( $breakdown_row['impressions_30'] ?? 0 ),
|
||||
'clicks' => (int) ( $breakdown_row['clicks'] ?? 0 ),
|
||||
'clicks_30' => (int) ( $breakdown_row['clicks_30'] ?? 0 ),
|
||||
'ctr' => (float) ( $breakdown_row['ctr'] ?? 0 ),
|
||||
'cost' => (float) ( $breakdown_row['cost'] ?? 0 ),
|
||||
'cpc' => (float) ( $breakdown_row['cpc'] ?? 0 ),
|
||||
'conversions' => (float) ( $breakdown_row['conversions'] ?? 0 ),
|
||||
'conversions_value' => (float) ( $breakdown_row['conversions_value'] ?? 0 ),
|
||||
'roas' => (float) ( $breakdown_row['roas'] ?? 0 ),
|
||||
'min_roas' => (float) ( $row['min_roas'] ?? 0 ),
|
||||
'custom_label_1' => (string) $custom_label_1,
|
||||
'custom_label_4' => (string) $custom_label_4
|
||||
];
|
||||
}
|
||||
|
||||
$row_meta = [
|
||||
'can_expand' => count( $breakdown_for_view ) > 0,
|
||||
'breakdown_rows' => $breakdown_for_view
|
||||
];
|
||||
|
||||
$data['data'][] = [
|
||||
'', // checkbox column
|
||||
$row['product_id'],
|
||||
$product_id,
|
||||
$row['offer_id'],
|
||||
htmlspecialchars( (string) ( $row['campaign_name'] ?? '' ) ),
|
||||
htmlspecialchars( (string) ( $row['ad_group_name'] ?? '' ) ),
|
||||
$product_url_html,
|
||||
'<div class="table-product-title" product_id="' . $row['product_id'] . '">
|
||||
<a href="/products/product_history/client_id=' . $client_id . '&product_id=' . $row['product_id'] . '&campaign_id=' . $history_campaign_id . '&ad_group_id=' . $history_ad_group_id . '" target="_blank" class="' . $custom_class . '">
|
||||
'<div class="table-product-title" product_id="' . $product_id . '">
|
||||
<a href="/products/product_history/client_id=' . $client_id . '&product_id=' . $product_id . '&campaign_id=' . $history_campaign_id . '&ad_group_id=' . $history_ad_group_id . '" target="_blank" class="' . $custom_class . '">
|
||||
' . $row['name'] . '
|
||||
</a>
|
||||
<span class="edit-product-title" product_id="' . $row['product_id'] . '">
|
||||
<span class="edit-product-title" product_id="' . $product_id . '">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</span>
|
||||
</div>',
|
||||
@@ -1111,14 +1144,15 @@ class Products
|
||||
round( $row['conversions'], 2 ),
|
||||
\S::number_display( $row['conversions_value'] ),
|
||||
$roasCellHtml,
|
||||
'<input type="text" class="form-control min_roas" product_id="' . $row['product_id'] . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
|
||||
'<input type="text" class="form-control custom_label_1" product_id="' . $row['product_id'] . '" value="' . $custom_label_1 . '" style="' . $custom_label_1_color . '">',
|
||||
'<input type="text" class="form-control custom_label_4" product_id="' . $row['product_id'] . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
|
||||
'<input type="text" class="form-control min_roas" product_id="' . $product_id . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
|
||||
'<input type="text" class="form-control custom_label_1" product_id="' . $product_id . '" value="' . $custom_label_1 . '" style="' . $custom_label_1_color . '">',
|
||||
'<input type="text" class="form-control custom_label_4" product_id="' . $product_id . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
|
||||
'<div class="btn-group btn-group-sm products-row-actions" role="group">'
|
||||
. '<button type="button" class="btn btn-primary assign-product-scope" product_id="' . $row['product_id'] . '" title="Dodaj produkt do kampanii/grupy"><i class="fa-solid fa-diagram-project"></i></button>'
|
||||
. '<button type="button" class="btn btn-secondary view-merchant-logs" product_id="' . $row['product_id'] . '" title="Pokaż logi synchronizacji Merchant"><i class="fa-solid fa-clock-rotate-left"></i></button>'
|
||||
. '<button type="button" class="btn btn-danger delete-product" product_id="' . $row['product_id'] . '" title="Usuń produkt"><i class="fa-solid fa-trash"></i></button>'
|
||||
. '</div>'
|
||||
. '<button type="button" class="btn btn-primary assign-product-scope" product_id="' . $product_id . '" title="Dodaj produkt do kampanii/grupy"><i class="fa-solid fa-diagram-project"></i></button>'
|
||||
. '<button type="button" class="btn btn-secondary view-merchant-logs" product_id="' . $product_id . '" title="Pokaż logi synchronizacji Merchant"><i class="fa-solid fa-clock-rotate-left"></i></button>'
|
||||
. '<button type="button" class="btn btn-danger delete-product" product_id="' . $product_id . '" title="Usuń produkt"><i class="fa-solid fa-trash"></i></button>'
|
||||
. '</div>',
|
||||
$row_meta
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user