Jump to content

Recommended Posts

Bonjour,

 

Tout d'abord voici mon code :

class AdminActiviteControllerCore extends AdminController {

    public function __construct() {
        $this->table = 'activite';
        $this->className = 'Activite';

        $this->addRowAction('view');
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->allow_export = true;

        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));

        //count pour le nombre de circuits --> AS products pour réutiliser dans fiels_list
        $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_activite` ps ON (a.`id_activite` = ps.`id_activite`)';
        $this->_group = 'GROUP BY a.`id_activite`';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'act');

        $this->fields_list = array(
            'id_activite' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
            'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'act', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->l('Name'), 'width' => 'auto'),
            'typeactivite_id' => array('title' => $this->l('Type d\'activité'), 'width' => 'auto'),
            'products' => array('title' => $this->l('Nombre de circuits'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
        );

        parent::__construct();
    }

ma table activite :

 

id_activite name lat lng duree_visite tarif date_add date_upd active typeactivite_id

 

et ma table typeactivite :

 

id_typeactivite name date_add date_upd active

 

Les 2 tables sont bien liées.

 

Mon problème est que je voudrai afficher le nom du type d'activité au liue de l'id c'est pourquoi j'ai besoin d'une requête sql mais débutant sous prestashop je ne vois absolument pas comment faire.

 

J'ai essayé avec ceci mais rien n'y fait :

$query = new DbQuery();
        $query->select('name');
        $query->from('typeactivite');
        $query->where('id_typeactivite = 12');
        $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);

        $this->fields_list = array(
            'id_activite' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
            'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'act', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->l('Name'), 'width' => 'auto'),
            $res => array('title' => $this->l('Type d\'activité'), 'width' => 'auto'),
            'products' => array('title' => $this->l('Nombre de circuits'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
        );

Merci à vous.

 

Link to comment
Share on other sites

Avec ce code j'ai bien mon type d'activité qui s'affiche :

        $this->_select = 'ta.`name` AS name_typeactivite';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'typeactivite` ta ON (a.`typeactivite_id` = ta.`id_typeactivite`)';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'act');

        $this->fields_list = array(
            'id_activite' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
            'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'act', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->l('Name'), 'width' => 'auto'),
            'name_typeactivite' => array('title' => $this->l('Type d\'activité'), 'width' => 'auto'),
            'duree_visite' => array('title' => $this->l('Durée de la visite'), 'width' => 'auto'),
            'description_activite' => array('title' => $this->l('Description'), 'width' => 'auto'),
            'tarif' => array('title' => $this->l('Tarif (€)'), 'width' => 'auto'),
            'products' => array('title' => $this->l('Nombre de circuits'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
        );

Donc ça ok , mais comment afficher plusieurs données provenant de plusieurs tables, j'ai essayé comme ça mais ça me prend que la dernière valeur c'est-à-dire le type d'activité, et non le nombre de produits et la description :

$this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_activite` ps ON (a.`id_activite` = ps.`id_activite`)';
        //$this->_group = 'GROUP BY a.`id_activite`';
        
        $this->_select = 'al.`description` AS description_activite';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'activite_lang` al ON (a.`id_activite` = al.`id_activite`)';
        
        $this->_select = 'ta.`name` AS name_typeactivite';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'typeactivite` ta ON (a.`typeactivite_id` = ta.`id_typeactivite`)';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'act');

        $this->fields_list = array(
            'id_activite' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
            'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'act', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->l('Name'), 'width' => 'auto'),
            'name_typeactivite' => array('title' => $this->l('Type d\'activité'), 'width' => 'auto'),
            'duree_visite' => array('title' => $this->l('Durée de la visite'), 'width' => 'auto'),
            'description_activite' => array('title' => $this->l('Description'), 'width' => 'auto'),
            'tarif' => array('title' => $this->l('Tarif (€)'), 'width' => 'auto'),
            'products' => array('title' => $this->l('Nombre de circuits'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
        );
Link to comment
Share on other sites

  • 2 months later...

Bonjour,

 

c'est peut-être un peu tard, mais j'avais trouvé ce bout de code qu'il faut adapter u peu pour répondre à ce type de besoin:

ca fonctionne coté BO je n'en suis pas encore à la partie front office :wacko: (PS 1.5.4)

    public function renderList()
    {
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->addRowAction('details');
        
        ... / ...

            'id_customer' => array(
                'title' => $this->l('Customer Name'),
                'width' => 100,
                'callback'     => 'getCustomerName'
            ),            
        );
    .../...
    }	

public function getCustomerName($echo, $row) {
		$id_customer = $row['id_customer'];
		$customer = new Customer($id_customer);
		return $customer->firstname . ' ' . $customer->lastname;
	    }
Edited by MonVinDirect (see edit history)
  • Like 1
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...