Jump to content

Bouton Details backoffice lliste des produits


Recommended Posts

Bonjour,

 

Le code ci-dessous génère l'imprim écran fourni avec ce post :

//Affichage des boutons
    public function renderList() {
        $this->addRowAction('edit');
        $this->addRowAction('duplicate');
        $this->addRowAction('delete');
        $this->addRowAction('details');

        return parent::renderList();
    }

    /**
     * method call when ajax request is made with the details row action
     * @see AdminController::postProcess()
     */
    public function ajaxProcessDetails() {

        if (($id = Tools::getValue('id'))) {//récupère l'id_product afin de l'utiliser dans la requête $query
            //requête query récupérant l'id_activite, le nom de l'activité et sa position en fonction du circuit (id_product) et triée en DESC en fonction de la position
            $this->_query = 'SELECT ps_activite.id_activite, name, position
FROM ps_activite, ps_activiteproduct
WHERE ps_activite.id_activite = ps_activiteproduct.id_activite
AND ps_activiteproduct.id_product =' . ((int) $id) . '
ORDER BY position DESC';

            $query = $this->_query;

            //affichage du résultat de la requête query
            echo Tools::jsonEncode(array(
                'data' => Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query),
                'fields_display' => $this->fieldsDisplay = array(
            'id_activite' => array('title' => $this->l('ID')),
            'name' => array('title' => $this->l('Nom')),
            'position' => array('title' => $this->l('Position')),
                )
            ));
        }

        die();
    }

Cet imprim écran vient de la liste des produits (dans mon cas des circuits) du backoffice c'est-à-dire le controller AdminProducts. Je souhaite afficher sous la liste de mes circuits : les activités correspondantes au circuit lors du clic sur le bouton Détails tout à droite. Avec mon code ci-dessus j'ai bien ce que je veux mais pas dans un helperList. Je n'arrive pas à afficher les informations d'une autre table que la table ps_product avec le code suivant :

 

ajaxProcessDetails() :

if (($id = Tools::getValue('id')))
      {
      $this->table = 'product';
      $this->className = 'Product';
      $this->identifier = 'id_product';
      $this->lang = true;

      /*if (!Validate::isLoadedObject($obj = new AttributeGroup((int)$id)))
      $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
     */
    $this->fields_list = array(
      'id_product' => array(
      'title' => $this->l('ID'),
      'width' => 40,
      'align' => 'center'
      ),
      'name' => array(
      'title' => $this->l('Value'),
      'width' => 'auto',
      'filter_key' => 'b!name'
      )
      );

      /*if ($obj->group_type == 'color')
      $this->fields_list['color'] = array(
      'title' => $this->l('Color'),
      'width' => 40,
      'filter_key' => 'b!color'
      );

      $this->fields_list['position'] = array(
      'title' => $this->l('Position'),
      'width' => 40,
      'filter_key' => 'a!position',
      'position' => 'position'
      ); */

    $this->addRowAction('edit');
      $this->addRowAction('delete');

      // override attributes
      $this->display = 'list';
      $this->tpl_folder = 'attributes/';

      //$this->_where = 'AND a.`id_attribute_group` = '.(int)$id;
      //$this->_orderBy = 'position';

      // get list and force no limit clause in the request
      $this->getList($this->context->language->id, null, null, 0, false);

      // Render list
      $helper = new HelperList();
      $helper->actions = $this->actions;
      $helper->override_folder = $this->tpl_folder;
      $helper->no_link = true;
      $helper->shopLinkType = '';
      $helper->identifier = $this->identifier;
      $helper->toolbar_scroll = false;
      //$helper->orderBy = 'position';
      //$helper->orderWay = 'ASC';
      $helper->currentIndex = self::$currentIndex;
      $helper->token = $this->token;
      $helper->table = $this->table;
      $helper->simple_header = true;
      $helper->show_toolbar = false;
      $helper->bulk_actions = $this->bulk_actions;
      //$helper->position_identifier = 'id_attribute';
      $content = $helper->generateList($this->_list, $this->fields_list);

      die (Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)));
      }

Quand je remplace product par activite je n'obtiens rien quand je clique sur le bouton, en gros ça fonctionne que pour la table correspondant au controller. Ici je suis dans le controller Products et je ne peux afficher que des informations de la table ps_product.

 

Merci.

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