Jump to content

how to store db using model ad canvas example


Recommended Posts

hi i'm triying to lear prestachopd, and i now know :

 

  1. make main modulename.php file and minimal structure
  2. make a modulenameController.php controller and display a form

now i need two things: HOW CAN I DO THAT?:

  • capture data from the form
  • store the data fields in db 

i used the example in https://github.com/PrestaEdit/Canvas-Module-Prestashop-15 with some reading from prestashop documentation in english

 

but: DOCUMENTATION IN PRESTASHOP ITS A CRAP, sh*t, very incomplete and minimal basic.. 

 

also its tedoius read the source of prestashop (very complicated) to try to make a stupid little module..

Link to comment
Share on other sites

  • 1 month later...

i solve it using https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/rWlD-5PrpJg so the model must have all the fields to stored already defined in the form helper list..  the model of the camvas exampel are incomplete ... that's why the confusion...

 

1) define the model fiels must be with a public variable, a entry in the array definition and a entri in the sql table definition, lest see:

class Examplecup extends ObjectModel
{
	public $id_cup;                   // id pk key of the table
	public $name_of_this_cup;
	public $date_creacion;		// cuando ingresa o se crea la orden de taller
	public $date_modifica;		// cuando se altero este registro por ultima vez
	public $id_employee;			// ultimo empleado que modifica la orden

	public static $definition = array(
		'table' => 'mycups',
		'primary' => 'id_cup',
		'fields' => array(
			'name_of_this_cup' =>	array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true,'size' => 255),
			'date_creacion' =>	array('type' => self::TYPE_DATE, 'validate' => 'isDate'), // cuando ingresa o se crea
			'date_modifica' =>	array('type' => self::TYPE_DATE, 'validate' => 'isDate'), // cuando se altera
			'id_employee' =>	array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true,'size' => 255),
		),
	);
}

The sql table definition must have the entries as declared in the model

CREATE TABLE `'._DB_PREFIX_.'mycups`(
			`id_cup` int(10) unsigned NOT NULL auto_increment ,
			`name_of_this_cup` text,
			`date_creacion` text NULL ,
			`date_modifica` text NULL ,
			`id_employee` int(10) unsigned NULL ,
			PRIMARY KEY (`id_tallermarca`)
			) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;

now the list of the fields in the form helper must be

public function renderForm()
	{
		$this->fields_form = array(
			'legend' => array(
				'title' => $this->l('My stored names of cups),
				'icon' => 'icon-envelope-alt'
			),
			'input' => array(
				array('type' => 'text','label' => $this->l('name of the cup'),'name' => 'name_of_this_cup'),
				array('type' => 'hidden','name' => 'date_modifica'),
				array('type' => 'hidden','name' => 'date_creacion'),
				array('type' => 'hidden','name' => 'id_employee'),
			),
			'submit' => array('title' => $this->l('Save'),'name' => 'submit'.$this->className)
		);
        $this->fields_value['date_modifica'] = date("Y-m-d");
	$this->fields_value['id_employee'] = (int)Tools::getValue('id_employee', $this->id_employee);
	return parent::renderForm();
	}

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