jemmeli Posted June 4, 2013 Share Posted June 4, 2013 (edited) hello I am wondering how to set up an detail action in back-office for helper view I have already create a controller that extend from "ModuleAdminController" and have all the functions needed like renderList, ajaxProcessDetails, renderForm and also I search about this topic in documentation of prestashop 1.5 and I did some google search i succed to show the button but when I click it nothing happen it normally expand another list but it didin't do that, I just want to know what's wrong please. the button "details " generated by the views helper in the controller admin is cercled by the red stroke in the following image : this is my controller for back-office: <?php /* * the admin controller */ class AdminBlockPersoController extends ModuleAdminController { public function __construct() { $this->table = 'blockpersoadmintexture'; $this->className = 'BlockPerso'; $this->lang = false; //$product = new Product($this->id_product); //View Helpers dans le constructeur $this->fields_list = array( 'id_blockpersoadmintexture' => array( 'title' => '#' ), 'id_product' => array( 'title' => 'id_produit' ), 'reference' => array( 'title' => 'Réf' ), 'nom' => array( 'title' => 'Nom' ), 'description' => array( 'title' => 'Description' ) ); /* end of fields_list */ // This adds a multiple deletion button $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?') ) ); //for the image treatment $this->fieldImageSettings = array( 'name' => 'yyy', 'dir' => 'texture' ); //echo _PS_MODULE_DIR_.'blockpersoadmin/pattern'; /* this in postprocess $this->postImage($new_carrier->id);*/ parent::__construct(); //$this->actions = array('delete'); } // This method generates the list of results public function renderList() { // Adds an Edit button for each result $this->addRowAction('edit'); // Adds a Delete button for each result $this->addRowAction('delete'); // Adds a Delete button for each result $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'))) { // override attributes $this->display = 'list'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->_select = '* FROM ps_blockpersoadmintexture'; // get list and force no limit clause in the request $this->getList($this->context->language->id); // Render list $helper = new HelperList(); $helper->actions = $this->actions; $helper->list_skip_actions = $this->list_skip_actions; $helper->no_link = true; $helper->shopLinkType = ''; $helper->identifier = $this->identifier; $helper->imageType = $this->imageType; $helper->toolbar_scroll = false; $helper->show_toolbar = false; //$helper->orderBy = 'position'; //$helper->orderWay = 'ASC'; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->position_identifier = $this->position_identifier; // Force render - no filter, form, js, sorting ... $helper->simple_header = true; $content = $helper->generateList($this->_list, $this->fields_list); echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); } die; } // This method generates the Add/Edit form public function renderForm() { // Building the Add/Edit form $this->fields_form = array( 'legend' => array( 'title' => $this->l('Test') ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('product'), 'name' => 'id_product', 'required' => true, 'desc' => $this->l('nom du produit associé'), 'options' => array( 'query' => Product::getProducts(1, 1, 1000, "id_product", "DESC"), 'id' => 'id_product', 'name' => 'name', 'value' => 'id_product' ) ), array( 'type' => 'text', 'label' => $this->l('Réference:'), 'name' => 'reference', 'size' => 33, 'required' => true, 'desc' => $this->l('le référence'), ), array( 'type' => 'text', 'label' => $this->l('Nom:'), 'name' => 'nom', 'size' => 33, 'required' => true, 'desc' => $this->l('le nom'), ), array( 'type' => 'text', 'label' => $this->l('Description:'), 'name' => 'description', 'size' => 33, 'required' => true, 'desc' => $this->l('la Description'), ), array( 'type' => 'file', 'label' => $this->l('Texture :'), 'name' => 'yyy', 'desc' => $this->l('Upload a texture from your computer .gif, .jpg, .jpeg .png') ) ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } Edited August 29, 2013 by jemmeli (see edit history) Link to comment Share on other sites More sharing options...
jemmeli Posted June 5, 2013 Author Share Posted June 5, 2013 no one know about this in prestashop 1.5 Link to comment Share on other sites More sharing options...
jemmeli Posted June 5, 2013 Author Share Posted June 5, 2013 i found the solution i must put all the call database and treatment in ajaxProcess() function i hope this would be helpfull for somebody else look at this code : <?php /* * the admin controller */ class AdminBlockPersoController extends ModuleAdminController { public function __construct() { $this->table = 'blockpersoadmintexture'; $this->className = 'BlockPerso'; $this->lang = false; //$product = new Product($this->id_product); //View Helpers dans le constructeur $this->fields_list = array( 'id_blockpersoadmintexture' => array( 'title' => '#' ), 'id_product' => array( 'title' => 'id_produit' ), 'reference' => array( 'title' => 'Réf' ), 'nom' => array( 'title' => 'Nom' ), 'description' => array( 'title' => 'Description' ) ); /* end of fields_list */ // This adds a multiple deletion button $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?') ) ); //for the image treatment $this->fieldImageSettings = array( 'name' => 'yyy', 'dir' => 'texture' ); //echo _PS_MODULE_DIR_.'blockpersoadmin/pattern'; /* this in postprocess $this->postImage($new_carrier->id);*/ parent::__construct(); //$this->actions = array('delete'); } // This method generates the list of results public function renderList() { // Adds an Edit button for each result $this->addRowAction('edit'); // Adds a Delete button for each result $this->addRowAction('delete'); // Adds a Delete button for each result $this->addRowAction('details'); return parent::renderList(); } //Sample Ajax request code: public function ajaxProcess() { $query = 'SELECT * FROM ps_blockpersoadmintexture'; echo Tools::jsonEncode(array( 'data' => Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query), 'fields_display' => $this->fieldsDisplay = array( 'id_blockpersoadmintexture' => array('title' => $this->l('ID')), 'id_product' => array('title' => $this->l('#')), 'reference' => array('title' => $this->l('ref')), 'nom' => array('title' => $this->l('Nom')), 'description' => array('title' => $this->l('Nom')) ) )); die(); } // This method generates the Add/Edit form public function renderForm() { // Building the Add/Edit form $this->fields_form = array( 'legend' => array( 'title' => $this->l('Test') ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('product'), 'name' => 'id_product', 'required' => true, 'desc' => $this->l('nom du produit associé'), 'options' => array( 'query' => Product::getProducts(1, 1, 1000, "id_product", "DESC"), 'id' => 'id_product', 'name' => 'name', 'value' => 'id_product' ) ), array( 'type' => 'text', 'label' => $this->l('Réference:'), 'name' => 'reference', 'size' => 33, 'required' => true, 'desc' => $this->l('le référence'), ), array( 'type' => 'text', 'label' => $this->l('Nom:'), 'name' => 'nom', 'size' => 33, 'required' => true, 'desc' => $this->l('le nom'), ), array( 'type' => 'text', 'label' => $this->l('Description:'), 'name' => 'description', 'size' => 33, 'required' => true, 'desc' => $this->l('la Description'), ), array( 'type' => 'file', 'label' => $this->l('Texture :'), 'name' => 'yyy', 'desc' => $this->l('Upload a texture from your computer .gif, .jpg, .jpeg .png') ) ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } /***********************************************************************************************************/ class BlockPerso extends ObjectModel { public $id_blockpersoadmintexture; public $id_product; public $reference; public $nom; public $description; // /* * @see ObjectModel::$definition => (this is the Model) */ public static $definition = array( 'table' => 'blockpersoadmintexture', 'primary' => 'id_blockpersoadmintexture', 'fields' => array( 'id_blockpersoadmintexture' => array('type' => ObjectModel::TYPE_INT), 'id_product' => array('type' => ObjectModel::TYPE_INT), 'reference' => array('type' => ObjectModel::TYPE_STRING), 'nom' => array('type' => ObjectModel::TYPE_STRING), 'description' => array('type' => ObjectModel::TYPE_STRING) ), ); } 2 Link to comment Share on other sites More sharing options...
jemmeli Posted June 5, 2013 Author Share Posted June 5, 2013 (edited) or by using this : public function ajaxProcess() { if (($id = Tools::getValue('id'))) { // override attributes $this->display = 'list'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->_select = 'a.*'; //$this->_select = 'b.*'; //$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'tab_lang` b ON (b.`id_tab` = a.`id_tab` AND b.`id_lang` = '.$this->context->language->id.')'; //$this->_where = 'AND a.`id_parent` = '.(int)$id; //$this->_orderBy = 'position'; // get list and force no limit clause in the request $this->getList($this->context->language->id); // Render list $helper = new HelperList(); $helper->actions = $this->actions; $helper->list_skip_actions = $this->list_skip_actions; $helper->no_link = true; $helper->shopLinkType = ''; $helper->identifier = $this->identifier; $helper->imageType = $this->imageType; $helper->toolbar_scroll = false; $helper->show_toolbar = false; //$helper->orderBy = 'position'; $helper->orderWay = 'ASC'; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->position_identifier = $this->position_identifier; // Force render - no filter, form, js, sorting ... $helper->simple_header = true; $content = $helper->generateList($this->_list, $this->fields_list); echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); } die; } Edited June 5, 2013 by jemmeli (see edit history) Link to comment Share on other sites More sharing options...
Mohamadou Ndiaye Posted June 24, 2014 Share Posted June 24, 2014 thanks i resolved my problem 1 Link to comment Share on other sites More sharing options...
beginner1 Posted November 27, 2017 Share Posted November 27, 2017 On 6/5/2013 at 8:44 PM, jemmeli said: or by using this : public function ajaxProcess() { if (($id = Tools::getValue('id'))) { // override attributes $this->display = 'list'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->_select = 'a.*'; //$this->_select = 'b.*'; //$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'tab_lang` b ON (b.`id_tab` = a.`id_tab` AND b.`id_lang` = '.$this->context->language->id.')'; //$this->_where = 'AND a.`id_parent` = '.(int)$id; //$this->_orderBy = 'position'; // get list and force no limit clause in the request $this->getList($this->context->language->id); // Render list $helper = new HelperList(); $helper->actions = $this->actions; $helper->list_skip_actions = $this->list_skip_actions; $helper->no_link = true; $helper->shopLinkType = ''; $helper->identifier = $this->identifier; $helper->imageType = $this->imageType; $helper->toolbar_scroll = false; $helper->show_toolbar = false; //$helper->orderBy = 'position'; $helper->orderWay = 'ASC'; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->position_identifier = $this->position_identifier; // Force render - no filter, form, js, sorting ... $helper->simple_header = true; $content = $helper->generateList($this->_list, $this->fields_list); echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); } die; } How does delete action work? I have added the delete button but I don't know which function to call or implement the functionality in! For example for edit we use renderForm() then which function for delete? 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