Jump to content

AdminTab and custom SQL Query


Recommended Posts

Hi to all, i've two questions :)

 

Number one!

I'm writing a Tab for prestashop that lists the customers with the country of origin. So far it's ok, but I would like to filter the query or table by country so I would like to add something like: WHERE iso_code = 'IT' Apparently prestashop will not let me, how could I do? This is my code:

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
   public function __construct()
   {
    $this->table = 'customer';
  $this->className = 'Customer';
  $this->lang = false;
  $this->edit = false;
  $this->view = true;
  $this->delete = false;
 $this->deleted = false;
 $this->requiredDatabase = true;
 global $cookie;
 $id = $cookie->id_employee;
 $select_cc = mysql_fetch_assoc(mysql_query("SELECT country_code FROM ps_employee WHERE id_employee='$id'"));
 $current_country_code = $select_cc['country_code']; //it's a custom field created by me.

 $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code=\'IT\') AS iso_code';
 $this->fieldsDisplay = array(
 'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
 'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
 'firstname' => array('title' => $this->l('First name'), 'width' => 60),
 'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
 'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false, 'filter_key'=>'a!iso_code'));

 $this->optionTitle = "Prova";
    parent::__construct();
   }
   public function postProcess()
   {
    // This function is executed when the Submit button is clicked
    // Use it to store the value of text fields in the database
    parent::postProcess();
   }
   public function displayForm($token=NULL)
   {
 echo '<h1>Clienti per Nazione</h1>';
    // This function can be used to create a form with text fields
   }
}
?>

 

Here, however, I try to add the WHERE clause, with no results:

 

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminCustomersCountries extends AdminTab
{
   public function __construct()
   {
    $this->table = 'customer';
    $this->className = 'Customer';
    $this->lang = false;
    $this->edit = false;
    $this->view = true;
    $this->delete = false;
    $this->deleted = false;
    $this->requiredDatabase = true;
    $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code=\'IT\') AS iso_code';
    $this->fieldsDisplay = array(
    'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
    'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
    'firstname' => array('title' => $this->l('First name'), 'width' => 60),
    'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
    'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
    'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false),
    'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false));
    $this->optionTitle = "Prova";
    parent::__construct();
   }
   public function postProcess()
   {
    // This function is executed when the Submit button is clicked
    // Use it to store the value of text fields in the database
    parent::postProcess();
   }
   public function displayForm($token=NULL)
   {
    // This function can be used to create a form with text fields
   }
}
?>

 

Number Two!

 

If, however, I can not create a filter so clean, can I create a query that is not necessarily changed by Prestashop?

But always displayed with table as generated by:

$this->fieldsDisplay = array(
       'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
       'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
       'firstname' => array('title' => $this->l('First name'), 'width' => 60),
       'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
       'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false, 'filter_key'=>'a!iso_code'));

 

 

Thank you guys :)

Mirko

Link to comment
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...