Jump to content

Using HelperList in configuration module page


orney21d

Recommended Posts

Hi, i'm new in prestashop, i'm from Cuba so sorry for my english. The fact is that i want to use the HelperList class in configuration page of a developed module , i have the next code in getContent function, the list is rendered but records of db table i want to show are not.

 

public function getContent() {
$helperList = new HelperList();
	$helperList->table = 'product_promoted_form_list';
	$helperList->bulk_actions = array('delete'=>array('text'=>$this->l('Delete selected'), 'confirm'=>$this->l('Delete selected items?')));
	$helperList->_select = 'id_product, url_product, url_product_image';


	$helperList->module = $this;
	$helperList->title = $this->l('Lista de productos promocionados');
	$helperList->token = Tools::getAdminTokenLite('AdminModules');
	$helperList->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;

	$helperList->show_toolbar = true;
	$helperList->toolbar_scroll = true;
	$helper->toolbar_btn = array(
		'back' => array(
			'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
			'desc' => $this->l('Back to list')
		)
	);


	$helperList->_defaultOrderBy = 'id_product';
       $fields_list = array(
		'id_product' => array(
			'title' => $this->l('ID'),
			'align' => 'center',
			'width' => 25
		),
		'url_product' => array(
			'title' => $this->l('Url product'),
			'width' => 'auto'
		),
		'url_product_image' => array(
			'title' => $this->l('Url image product'),
			'width' => 'auto'
		)
	);


	return $helperList->generateList($helperList->_select, $fields_list);
}

 

 

 

I'll appreciate any help.

Regards.

Link to comment
Share on other sites

  • 1 month later...

Bueno, estuve buscando y ya consegui que aparezca información:

 

En tu llamada a la funcion

$helperList->generateList($helperList->_select, $fields_list);

 

 

$fields_list tiene que ser un array con los campos que se mostraran, es decir por ejemplo:

 

$fields_list= array(
  'id' => array('title' => $this->l('id'), 'align' => 'left','width' => 70),
  'name' => array('title' => $this->l('name'), 'type' => 'price', 'align' => 'left'),
  'description' => array('title' => $this->l('description'), 'align' => 'left'),
  'active' => array('title' => $this->l('active'), 'align' => 'left', 'width' => 70)
);

 

 

$helperList->_select tiene que ser un array, que posiblemente sea el resultado de una consulta a tu base de datos, por ejemplo un array valido seria el resultado de:

Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql1);

 

Con eso que te he dicho, se muestran resultados por pantalla. Ahora solo falta que funcione la ordenacion, eliminacion, etc...

 

Si lo consigues, no dudes en ponerte en contacto conmigo :)

 

Saludos

Link to comment
Share on other sites

Hola, gracias por tus respuestas, la verdad que yo encontré la solución hace tiempo y es la que comentas, he posteado esto hace mas de un mes y nadie respondía jaja, típico de aquí, lo que hice fue acceder a la definición del método del helper y vi que efectivamente recivía un array, yo llamé a mi modelo que es el que accede a DDBB y me devuelve el array que es el que le paso al método de generación del html del listado del Helper. Lo que he visto también es que para usar el helper de la manera que inicialmente comentaba a traves de la definición de un select , hay que usarlo mediante un controlador que sea el que llame a la Vista (un .tpl por ejemplo). Saludos y gracias, te escribiré a tu correo y así tienes el mío por si quieres contactar.

Link to comment
Share on other sites

  • 1 month later...

Gracias por tu aporte, me ha servido de mucho, simplemente comentar que te falta declarar estos atributos porque si no salen Warnings:

$helperList->shopLinkType = '';
$helperList->identifier = 'id_product';

tambén decir que el listado de items no tiene porque ser resultado de una consulta mysql, tambien puede ser un listado extraido directamente de una clase:

$products = Product::getProducts($this->context->language->id, 0, '','id_product','ASC');
return $helperList->generateList($products, $fields_list);

Edited by jartau (see edit history)
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...