Jump to content

Filtering for bestproducts module

Recommended Posts

Hi everybody,


I need to add filtering for: Back Office -> Statistics -> Stats -> Best products (can be little different because of translation)


I have PS 1.6 and I'm editing this file: modules/statsbestproducts/statsbestproducts.php


The module itself shows best products for selected date period. What I want is to show best products just for one selected customer (I'm selling just several kinds of goods again to only 10 permanent clients). This way I want to get all items the customer have bought in selected month (I haven't found any module which can do that).


Having inspiration from similar stats modules, I just modified hookAdminStatsModules method and changed little SQL query:


See line 124, lines 142-159:

    public function hookAdminStatsModules($params)
    $id_category = (int)Tools::getValue('id_category'); // - this is NEW LINE
        $engine_params = array(
            'id' => 'id_product',
            'title' => $this->displayName,
            'columns' => $this->columns,
            'defaultSortColumn' => $this->default_sort_column,
            'defaultSortDirection' => $this->default_sort_direction,
            'emptyMessage' => $this->empty_message,
            'pagingMessage' => $this->paging_message

        if (Tools::getValue('export'))

        return '<div class="panel-heading">'.$this->displayName.'</div>
        <a class="btn btn-default export-csv" href="'.Tools::safeOutput($_SERVER['REQUEST_URI'].'&export=1').'">
            <i class="icon-cloud-upload"></i> '.$this->l('CSV Export').'
    <form action="#" method="post" id="categoriesForm" class="form-horizontal"> <!-- this FORM is NEW -->
                <div class="row row-margin-bottom">
                    <label class="control-label col-lg-3">
                        <span title="" data-toggle="tooltip" class="label-tooltip">
              Set Customer
                    <div class="col-lg-3">
                        <select name="id_category" onchange="$(\'#categoriesForm\').submit();">
                            <option value="0">All</option>
                <option value="2"'.($id_category == 2 ? ' selected="selected"' : '').'>Customer 1</option>
                <option value="3"'.($id_category == 3 ? ' selected="selected"' : '').'>Customer 2</option>
                <option value="4"'.($id_category == 4 ? ' selected="selected"' : '').'>Customer 3</option>



See line 188:

LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order ' . ((Tools::getValue('id_category')) ? 'AND o.id_customer = '.(Tools::getValue('id_category')) : '' ) .'


You can see all in attached file.


The thing is the form actually works (options are selected after form is posted).

The SQL query works only if I hardcode id_customer, for example:

LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order AND o.id_customer = 2'


But it does not work "together". Do you know what is wrong?


Thank you very very much!


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More