Matte01990 Posted August 29, 2016 Share Posted August 29, 2016 Hi everybody. I'm trying to add to my db some data, and I want to manage languages as well. I've seen how prestashop default tables (i.e. 'tax') work - two 'twin' tables, one of the them with the '_lang' suffix. This table has 3 fields, 'id_tax', 'id_lang' and 'name'. I would like to create a table like that but I am having some issues. 1) each item "occupies" two rows: id_tax id_lang name 1 1 english name 1 2 other lang. name 2 1 english name 2 2 other lang. name How can I manage this kind of scheme from code? Here it is a code snippet from my controller: //add form public function renderForm() { if (!($obj = $this->loadObject(true))) return; $this->fields_form = array( 'legend' => array( 'title' => $this->l('Add/Edit Box') ), 'input' => array( array( 'type' => 'text', 'label' => 'Nome', 'lang' => true, 'name' => 'nome' ), array( 'type' => 'textarea', 'label' => 'Description', 'name' => 'desc', 'lang' => true, 'autoload_rte' => 'rte' //Enable TinyMCE editor for short description ), array( 'type' => 'textarea', 'label' => 'Abstract', 'name' => 'abstract', 'lang' => true, 'autoload_rte' => 'rte' //Enable TinyMCE editor for short description ), array( 'type' => 'text', 'label' => 'Button Text', 'name' => 'button_text' ), array( 'type' => 'file', 'label' => 'File url', 'name' => 'file_url' ), array( 'type' => 'text', 'label' => 'Link', 'name' => 'link' ), array( 'type' => 'switch', 'label' => $this->l('Enable'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, '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'), 'name' => 'submit_form' ) ); return parent::renderForm(); } public function postProcess() { //checks if submit if (Tools::isSubmit('submit_form')) { //insert data into my_block_content $insertData = array( 'active' => Tools::getValue('active'), 'link' => Tools::getValue('link'), 'file_url' => Tools::getValue('file_url') ); Db::getInstance()->insert("my_block_content", $insertData); //insert data into my_block_content_lang $insertData2 = array( 'name' => Tools::getValue('nome'), 'desc' => Tools::getValue('desc'), 'abstract' => Tools::getValue('abstract'), 'button_text' => Tools::getValue('button_text') ); Db::getInstance()->insert("my_block_content_lang", $insertData2); } } thank you. 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