traja Posted April 4, 2016 Share Posted April 4, 2016 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')) $this->csvExport($engine_params); return '<div class="panel-heading">'.$this->displayName.'</div> '.$this->engine($engine_params).' <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').' </a> <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 </span> </label> <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> </select> </div> </div> </form>'; } ___ 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! statsbestproducts.php Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now