Jump to content

[BO] Besoin d'Aide - colonne Groupe à l'aide de $this->_select dans Admin Customers & Admin Orders


Recommended Posts

Bonjour à tous,

 

J'ai adapté un code pour afficher les groupes dans Admin Customers: (J'ai nommé la colonne Company car, j'utilise les groupes pour séparer des sociétés.

 

public function __construct()
{
  $this->table = 'customer';
  $this->className = 'Customer';
  $this->lang = false;
  $this->edit = true;
  $this->view = true;
  $this->delete = true;
 $this->deleted = true;
 $this->requiredDatabase = true;
 $this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(`birthday`, 5)) as age, (
  SELECT c.date_add FROM '._DB_PREFIX_.'guest g
  LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
  WHERE g.id_customer = a.id_customer
  ORDER BY c.date_add DESC
  LIMIT 1
 ) as connect';
 $this->_select = '(
  SELECT g.`name` FROM `'._DB_PREFIX_.'group_lang` g
  LEFT JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = g.`id_group`)
  WHERE g.`id_group` != 1 AND g.`id_lang`=1 AND cg.`id_customer` = a.id_customer
 ) as company';		
 $genders = array(1 => $this->l('M'), 2 => $this->l('F'), 9 => $this->l('?'));
  $this->fieldsDisplay = array(
 'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'company' => array('title' => $this->l('Company'), 'width' => 80),
 'id_gender' => array('title' => $this->l('Gender'), 'width' => 25, 'align' => 'center', 'icon' => array(1 => 'male.gif', 2 => 'female.gif', 'default' => 'unknown.gif'), 'orderby' => false, 'type' => 'select', 'select' => $genders, 'filter_key' => 'a!id_gender'),
 'company' => array('title' => $this->l('Company'), 'width' => 80),
 '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),
 'age' => array('title' => $this->l('Age'), 'width' => 30, 'search' => false),
 '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),
 'optin' => array('title' => $this->l('Opt.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printOptinIcon', 'orderby' => false),
 'date_add' => array('title' => $this->l('Registration'), 'width' => 30, 'type' => 'datetime', 'align' => 'right'),
 'connect' => array('title' => $this->l('Connection'), 'width' => 60, 'type' => 'datetime', 'search' => false));
 $this->optionTitle = $this->l('Customers options');
 $this->_fieldsOptions = array(
  'PS_PASSWD_TIME_FRONT' => array('title' => $this->l('Regenerate password:'), 'desc' => $this->l('Security minimum time to wait to regenerate the password'),'validation' => 'isUnsignedInt', 'cast' => 'intval', 'size' => 5, 'type' => 'text', 'suffix' => ' '.$this->l('minutes'))
 );
 parent::__construct();
}

 

J'ai donc essayé de le faire sur Admin Orders. Mais, je n'ai alors que les groupes qui s'affichent. Je pense qu'il faut intégrer le LEFT JOIN dans la balise mais un peu d'aide serait pas mal

 

Merci d'avance

 

 global $cookie;
  $this->table = 'order';
  $this->className = 'Order';
  $this->view = true;
 $this->colorOnBackground = true;
  $this->_select = '
  a.id_order AS id_pdf,
  CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
  osl.`name` AS `osname`,
  os.`color`,
  IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new,
  (SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';
 $this->_select = '(
  SELECT g.`name` FROM `'._DB_PREFIX_.'group_lang` g
  LEFT JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = g.`id_group`)
  WHERE g.`id_group` != 1 AND g.`id_lang`=1 AND cg.`id_customer` = a.id_customer
 ) as company';		
  $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
  LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`)
 LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
 LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')';
 $this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';
 $statesArray = array();
 $states = OrderState::getOrderStates((int)($cookie->id_lang));
 foreach ($states AS $state)
  $statesArray[$state['id_order_state']] = $state['name'];
  $this->fieldsDisplay = array(
 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),
 'company' => array('title' => $this->l('Company'), 'width' => 80),
 'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),
 'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),
 'payment' => array('title' => $this->l('Payment'), 'width' => 100),
 'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
 'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
 'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));
 parent::__construct();
}

Edited by aPlancon69 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 6 months later...

Autant de réponse de retour ça fait peur ^^

Je fais un petit deterrage de topic qui je pense est très utiles.

Espérons qu'il y ai plus de retour cette fois ^^

Merci d'avance.

 

J'essai en vain de récupérer le champ détails de la commande 'order_detail' mais rien y fait.

J'ai testé l'override car je suis sous prestashop 1.5.4.1 mais je galère un peu avec les jointure...

j'ai repris un bout de code choper ici mais je n'arrive pas à le modifier à ma sauce...

 

class AdminOrdersController extends AdminOrdersControllerCore
{
public function __construct()
{
 parent::__construct();
 $this->_select .= ', ca.name as carrier_name';
 $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'carrier` ca ON (ca.`id_carrier` = a.`id_carrier`)';
 $this->fields_list['carrier_name'] = array(
  'title' => $this->l('Transporteur'),
  'width' => 200,
  'callback' => 'transporteur'
 );
}
    public function processFilter()
{
 parent::processFilter();
 $this->_filter = str_replace('`carrier_name`', 'ca.name', $this->_filter);
}
public function transporteur($carrier_name)
{
 if (strpos(strtolower($carrier_name), 'colissimo') !== FALSE)
  return '<span style="color: #006a32;">' . $carrier_name . '</span>';
 else
  return $carrier_name;
}
}

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...