Dashboard Product Stats

I'm trying to add product stats that were removed from earilier versions. I am having trouble getting the correct product totals. Any ideas?

                        {if !empty($general_stats.products)}
                            
                                
                            
                            
                                
                            
                            
                                
                            
                            
                                
                            
                            
                                
                            
                        {/if}
                    
                    

[attachment=10275:product_stats.jpg]

product_stats.jpg

How are you generating $general_stats? Would assume the issue is in your inbound data.

You can add a:


to your page and ensure that $general_stats is what you expect it to be. Just look at the page in view_source or in the html debugger in your browser (right click - Inspect Element).

$general_stats is default CSC code so I was assuming it would work for other stats.?

Edit: This is the index template for admin that I am working with.

Using the code you posted only returns the array of what is default. Where is CSC pulling this data from is basically what I am asking because $general_stats.products.total_products is what needs to be pulled but I do where/if it exists for other stats.

app/controllers/backend/index.php

Thanks Tony. Looks like I will need to add the extras in that file.

Well that was a little tricky. If anyone else wants this, below are the changes.

/app/controllers/backend/index.php - Find /* Products */ and replace that section with:

    /* Products - The Tool */
    if (fn_check_view_permissions('products.manage', 'GET')) {
        $general_stats['products'] = array();
    $params = array(
        'only_short_fields' => true, // NOT NEEDED AT ALL BECAUSE WE DONT USE RESULTING $FIELDS
        'extend' => array('companies', 'sharing'),
        'status' => 'A',
        'get_conditions' => true,
    );

    list($fields, $join, $condition) = fn_get_products($params);

    db_query('SELECT SQL_CALC_FOUND_ROWS 1 FROM ?:products AS products' . $join . ' WHERE 1 ' . $condition . 'GROUP BY products.product_id');
    $general_stats['products']['total_products'] = db_get_found_rows();
    
    $params = array(
        'only_short_fields' => true, // NOT NEEDED AT ALL BECAUSE WE DONT USE RESULTING $FIELDS
        'extend' => array('companies', 'sharing'),
        'status' => 'D',
        'get_conditions' => true,
    );

    list($fields, $join, $condition) = fn_get_products($params);

    db_query('SELECT SQL_CALC_FOUND_ROWS 1 FROM ?:products AS products' . $join . ' WHERE 1 ' . $condition . 'GROUP BY products.product_id');
    $general_stats['products']['disabled_products'] = db_get_found_rows();

    $params = array(
        'amount_to' => 0,
        'tracking' => array(
            ProductTracking::TRACK_WITHOUT_OPTIONS, ProductTracking::TRACK_WITH_OPTIONS,
        ),
        'get_conditions' => true,
    );

    $params['extend'][] = 'companies';

    if (fn_allowed_for('ULTIMATE')) {
        $params['extend'][] = 'sharing';
    }
    list($fields, $join, $condition) = fn_get_products($params);

    db_query('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . ' FROM ?:products AS products' . $join . ' WHERE 1 ' . $condition . ' GROUP BY products.product_id');
    $general_stats['products']['out_of_stock_products'] = db_get_found_rows();
    
    $params = array(
        'amount_from' => 0,
        'tracking' => array(
            ProductTracking::TRACK_WITHOUT_OPTIONS, ProductTracking::TRACK_WITH_OPTIONS,
        ),
        'get_conditions' => true,
    );

    $params['extend'][] = 'companies';

    if (fn_allowed_for('ULTIMATE')) {
        $params['extend'][] = 'sharing';
    }
    list($fields, $join, $condition) = fn_get_products($params);

    db_query('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . ' FROM ?:products AS products' . $join . ' WHERE 1 ' . $condition . ' GROUP BY products.product_id');
    $general_stats['products']['all_products'] = db_get_found_rows();
    
    $params = array(
        'amount_from' => 1,
        'tracking' => array(
            ProductTracking::TRACK_WITHOUT_OPTIONS, ProductTracking::TRACK_WITH_OPTIONS,
        ),
        'get_conditions' => true,
    );

    $params['extend'][] = 'companies';

    if (fn_allowed_for('ULTIMATE')) {
        $params['extend'][] = 'sharing';
    }
    list($fields, $join, $condition) = fn_get_products($params);

    db_query('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . ' FROM ?:products AS products' . $join . ' WHERE 1 ' . $condition . ' GROUP BY products.product_id');
    $general_stats['products']['in_stock_products'] = db_get_found_rows();
}
//* Products - The Tool *//

/design/backend/templates/addons/my_changes/hooks/index/index.override.tpl - Add the following:

{hook name="index:index"}

            {hook name="index:finance_statistic"}
            {if !empty($orders_stat.orders)}
                
            {/if}
            {if !empty($orders_stat.orders_total)}
                
            {/if}
            {if !empty($orders_stat.taxes)}
                
            {/if}
            {if !empty($orders_stat.abandoned_cart_total)}
                
            {/if}
            {/hook}
        
{__("orders")}

{if $user_can_view_orders} {$orders_stat.orders|count} {else} {$orders_stat.orders|count} {/if}

{$orders_stat.prev_orders|count}, {if $orders_stat.diff.orders_count > 0}+{/if}{$orders_stat.diff.orders_count}
{__("sales")}

{include file="common/price.tpl" value=$orders_stat.orders_total.totally_paid}

{include file="common/price.tpl" value=$orders_stat.prev_orders_total.totally_paid}, {if $orders_stat.orders_total.totally_paid > $orders_stat.prev_orders_total.totally_paid}+{/if}{$orders_stat.diff.sales nofilter}%
{__("taxes")}

{include file="common/price.tpl" value=$orders_stat.taxes.subtotal}

{include file="common/price.tpl" value=$orders_stat.taxes.prev_subtotal}, {if $orders_stat.taxes.subtotal > $orders_stat.taxes.prev_subtotal}+{/if}{$orders_stat.taxes.diff nofilter}%
{__("users_carts")}

{$orders_stat.abandoned_cart_total|default:0}

{$orders_stat.prev_abandoned_cart_total|default:0}, {if $orders_stat.abandoned_cart_total > $orders_stat.prev_abandoned_cart_total}+{/if}{$orders_stat.diff.abandoned_carts nofilter}%
{function name="get_orders" limit=5} {$params = ['status' => $status, 'time_from' => $time_from, 'time_to' => $time_to, 'period' => 'C']} {$orders = $params|fn_get_orders:$limit} {foreach from=$orders.0 item="order"} {foreachelse} {/foreach}
{$order_statuses[$order.status].description} {__("order")} #{$order.order_id} {__("by")} {if $order.user_id}{/if}{$order.lastname} {$order.firstname}{if $order.user_id}{/if} {$order.timestamp|date_format:"`$settings.Appearance.date_format`, `$settings.Appearance.time_format`"}

{include file="common/price.tpl" value=$order.total}

{__("no_data")}
{/function}
{if !empty($order_statuses)}

{__("recent_orders")}

{get_orders status=""}
{foreach from=$order_statuses item="status"}
{get_orders status=$status.status}
{/foreach}
{/if} {if !empty($graphs)}

{__("statistics")}

{capture name="chart_tabs"}
{hook name="index:chart_statistic"} {/hook} {/capture}
{include file="common/tabsbox.tpl" content=$smarty.capture.chart_tabs}
{/if}
{if !empty($general_stats.products)} {/if} {if !empty($general_stats.customers)} {/if} {if !empty($general_stats.categories)} {/if} {if !empty($general_stats.companies)} {/if} {if !empty($general_stats.pages)} {/if}
{hook name="index:order_statistic"} {/hook} {if $user_can_view_orders}

{__("order_by_status")}

{__("status")} {__("qty")} {__(total)} {__("shipping")}
{foreach from=$order_by_statuses item="order_status"} {$url = "orders.manage?is_search=Y&period=C&time_from=`$time_from`&time_to=`$time_to`&status[]=`$order_status.status`"|fn_url} {/foreach}
{$order_status.status_name} {$order_status.count} {include file="common/price.tpl" value=$order_status.total} {include file="common/price.tpl" value=$order_status.shipping}
{/if}
{if "logs.manage"|fn_check_view_permissions:"GET"}

{__("recent_activity")}

{function name="show_log_row" item=[]} {if $item}
{hook name="index:recent_activity"} {$_type = "log_type_`$item.type`"} {$_action = "log_action_`$item.action`"} {__($_type)}{if $item.action} ({__($_action)}){/if}: {if $item.type == "users" && "profiles.update?user_id=`$item.content.id`"|fn_url|fn_check_view_permissions:"GET"} {if $item.content.id}{/if}{$item.content.user}{if $item.content.id}{/if}
{elseif $item.type == "orders" && "orders.details?order_id=`$item.content.id`"|fn_url|fn_check_view_permissions:"GET"} {$item.content.status}
{__("order")} {$item.content.order}
{elseif $item.type == "products" && "products.update?product_id=`$item.content.id`"|fn_url|fn_check_view_permissions:"GET"} {$item.content.product}
{elseif $item.type == "categories" && "categories.update?category_id=`$item.content.id`"|fn_url|fn_check_view_permissions:"GET"} {$item.content.category}
{/if} {hook name="index:recent_activity_item"}{/hook} {$item.timestamp|date_format:"`$settings.Appearance.date_format`, `$settings.Appearance.time_format`"} {/hook}
{/if} {/function}
{foreach from=$logs item="item"} {show_log_row item=$item} {/foreach}
{/if}

{/hook}

product_stats_2.jpg

Any way to use my_changes for the controller?

Maybe add a hook at each of your db_get_found_rows(). But really have no idea how much of this you've changed.

Providing a screenshot of the results would be nice too.

The screenshot is posted. I think I will just leave as is. I sure hope CSC puts back the modified files difference for upgrades. I've got too many modifications that can't be hooked.

Supposed to...