mckaygerhard Posted August 22, 2017 Share Posted August 22, 2017 (edited) in a model of prestashop i have only string fields, if i want to made arrays for made comboboxes <select>? how? i mean: in that code how can i put the id emloyer selection in form and model and the id_services (a table of my) class TallerModel extends ObjectModel { public $id; /** @var string Name of the taller*/ public $name; /** @var string id of the responsable of a taller */ public $id_employer; /** @var array services_id what service kind offers this taller */ow? public $array_service; // <<--- this how? /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'taller', 'primary' => 'id', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGeneric'), /* how can i represent the id_employer join!?*/ /* and id_services (services it my own table without lang ??? */ ), ); Edited August 22, 2017 by mckaygerhard (see edit history) Link to comment Share on other sites More sharing options...
prestahero.com Posted August 23, 2017 Share Posted August 23, 2017 (edited) in a model of prestashop i have only string fields, if i want to made arrays for made comboboxes <select>? how? i mean: in that code how can i put the id emloyer selection in form and model and the id_services (a table of my) class TallerModel extends ObjectModel { public $id; /** @var string Name of the taller*/ public $name; /** @var string id of the responsable of a taller */ public $id_employer; /** @var array services_id what service kind offers this taller */ow? public $array_service; // <<--- this how? /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'taller', 'primary' => 'id', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGeneric'), /* how can i represent the id_employer join!?*/ /* and id_services (services it my own table without lang ??? */ ), ); This is data object, it's where you define physical fields of the data and the validations for data inserted..., it's not where you define html input type (select, text, radio...) to have select field you need to defines it when rendering the form, below is an example when I render a form in my custom module public function renderConfigForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Configuration'), 'icon' => 'icon-envelope' ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Use cronjob'), 'name' => 'AS_FILTER_ENABLE_CRON_JOB', 'desc' => '<p><b>Http url:</b> http://'.$this->context->shop->domain.$this->context->shop->getBaseURI().'modules/ets_autoseo/cronjob.php</p><p><b>'. $this->l('Physycal path: ').'</b>'.dirname(__FILE__).'/cronjob.php</p><i>'.$this->l('Make a cronjob for this url to automatically generate tags on your Prestashop website.').'</i>', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class'=>'as_config_save', ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $this->fields_form = array(); $helper->module = $this; $helper->override_folder = '/'; $helper->id = (int)Tools::getValue('id_carrier'); $helper->identifier = $this->identifier; $helper->submit_action = 'btnSubmitConfig'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } "Type" in the definition is the type of html input (text, radio, select...) For more information of how to use form helper you can check here: http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class Edited August 23, 2017 by ets-soft (see edit history) Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 2, 2017 Author Share Posted September 2, 2017 This is data object, it's where you define physical fields of the data and the validations for data inserted..., it's not where you define html input type (select, text, radio...) to have select field you need to defines it when rendering the form, below is an example when I render a form in my custom module For more information of how to use form helper you can check here: http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class Hi ets-soft thanks for answer but PLEASE read carefully; i already know how to put a "radio" or "select" fiel from custom data.. my problem its how to specify put a select field for employeers, i already done for Zones and Country's easyle Country have a model that provide a "getCountries" but for Employeers i dont have or how can i made that!? this are was i made for countries: 1) in controller firs made: $countries = Country::getCountries($this->context->language->id); foreach ($countries as $country) { $this->countries_array[$country['id_country']] = $country['name']; } 2) in the render form then made for the "country" input field: 'country' => array( 'title' => $this->l('Country'), 'type' => 'select', 'list' => $this->countries_array, ), Link to comment Share on other sites More sharing options...
webmasterroot Posted September 3, 2017 Share Posted September 3, 2017 (edited) en un modelo de prestashop solo tengo campos de cadena, si quiero hacer arrays para hacer comboboxes <select>? Como quiero decir: en ese código ¿cómo puedo poner la selección de id de emloyer en forma y modelo y el id_services (una tabla de mi) Es urgente: solo me falta eso para 1) asignaciones, 2) quien recibe, 3) quien entrega Edited September 3, 2017 by webmasterroot (see edit history) Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 22, 2017 Author Share Posted September 22, 2017 i found the solution, due in this "forum comunity" there's no "comunity" only "forum sales" THE COMPLETE CODE AND ALL THE STEPS ARE AT: https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/z8vfPsvFFjk here i put only the most important parts.. as mentioned int he previous link, added a new fiel in the model definition, class and the table sql this method permits to stored in the db as "1,2,3" so you can use only a single field to relation that multiple selected values, a better could be using groupbox but its quite difficult, take a look to the AdminCustomers controller class in the controllers directory of the prestachop, this has a multiselect group that used a realtional table event stored in single field then in the helper form list array of inputs define a select as: array( 'type' => 'select', 'label' => $this->l('Select and employee'), 'name' => 'id_employee_tech', 'required' => false, 'col' => '6', 'default_value' => (int)Tools::getValue('id_employee_tech'), 'options' => array( 'query' => Employee::getEmployees(true), // el true es que solo los que estan activos 'id' => 'id_employee', 'name' => 'firstname', 'default' => array( 'value' => '', 'label' => $this->l('ninguno') ) ) ), an then override the post process too public function postProcess() { if (Tools::isSubmit('submitTallerOrden')) { $_POST['id_employee'] = implode(',', Tools::getValue('id_employee')); } parent::postProcess(); } this make stored in the db as "1,2,3" 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