Jump to content

[SOLVED] how to setup a "detail" action for helper view ?


jemmeli

Recommended Posts

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 :

 

details_button.jpg

 

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 by jemmeli (see edit history)
Link to comment
Share on other sites

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 :ph34r: 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)
       ),
   );

}




  • Like 2
Link to comment
Share on other sites

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 by jemmeli (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...
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

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