Sanket Posted March 21, 2014 Share Posted March 21, 2014 Hello everyone, I want to import products from my company's framework into prestashop.I am using web service of company's framework and it is giving me JSON and i successfully converted to array. Now I want to add that array into database. SO please help me in adding it.I am not getting where to put my code. and which method to use for that. 1. Do i need to use Db::getInstance() method with insert()? 2. How to call a method having the insertion code from my module.?and also tell me how to define that method? Can i just add my code into hook? In my module.tpl file i have a save button. so what i need to place in _saveContent() method?can i place my insertion code into this function?Thanks in advance... Link to comment Share on other sites More sharing options...
NemoPS Posted March 21, 2014 Share Posted March 21, 2014 Can you briefly described what kind of module you created? You used a tpl for the back office, and not the getContent method? Link to comment Share on other sites More sharing options...
Sanket Posted March 21, 2014 Author Share Posted March 21, 2014 (edited) Can you briefly described what kind of module you created? You used a tpl for the back office, and not the getContent method? Yes here is my getContent method and saveContent method public function getContent() { $message = ''; if (Tools::isSubmit('submit_'.$this->name)) { $message = $this->_saveContent(); $message = $this->displayConfirmation($this->l('msg in response')); } $this->_displayContent($message); return $this->display(__FILE__, 'settings.tpl'); } private function _saveContent() { $message = ''; if (!$message) { $message = $this->displayConfirmation($this->l('Your settings have been saved from')); } else $message = $this->displayError($this->l('There was an error while saving your settings')); return $message; } And i have a buuton in my settings.tpl file it is: <fieldset> <legend>Importing from framework</legend> <form method="post"> <p> <label>Click this to import</label> <input id="submit_{$module_name}" name="submit_{$module_name}" type="submit" value="Save" class="button" /> </p> </form> </fieldset> Edited March 21, 2014 by Sanket (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted March 21, 2014 Share Posted March 21, 2014 Ah well in this case in your saveContent method you only need to use Db::getInstance()->insert... as you correctly pointed out You can simply use that like private function _saveContent() { $message = ''; $data = array('''your data here!! one key for each column); if(Db::getInstance()->insert($data)) $message = $this->displayConfirmation($this->l('Your settings have been saved from')); else $message = $this->displayError($this->l('There was an error while saving your settings')); return $message; } Link to comment Share on other sites More sharing options...
Sanket Posted March 21, 2014 Author Share Posted March 21, 2014 Thanks a lot.. for your valuable time. I will try and get back to you soon if i find any difficulty. Link to comment Share on other sites More sharing options...
chary Posted July 21, 2015 Share Posted July 21, 2015 hello sir, how to insert records into database using prestashop . please give me example step by step Link to comment Share on other sites More sharing options...
selectshop.at Posted July 21, 2015 Share Posted July 21, 2015 Use the native csv import function on yur back-office -> Tab "advanced parameters" -> csv import on right bottom box you will find samples of csv import files. csv files you process with Excel. Tutorials: http://doc.prestashop.com/display/PS16/CSV+Import+Parameters Link to comment Share on other sites More sharing options...
Recommended Posts