dwojod Posted May 4, 2016 Share Posted May 4, 2016 Hi, I want to extend category controller of a field of type "switch" - [value = 1 or 0] My questions: 1. Can I create new table in database with id, id_category, value, do I have to unconditionally enter additional values to the table ps_category ? 2. If I can make it through another table, how can I save these values using overwriting the controller ? Link to comment Share on other sites More sharing options...
tuk66 Posted May 4, 2016 Share Posted May 4, 2016 Consider also to use a module http://addons.prestashop.com/en/blocks-tabs-banners/18173-category-fields.html http://addons.prestashop.com/en/search?id_category=0&search_query=fields 1 Link to comment Share on other sites More sharing options...
dwojod Posted May 4, 2016 Author Share Posted May 4, 2016 Thanks a lot, but It could be better If I know how to do this other thing is use these values to display left column depends to value Link to comment Share on other sites More sharing options...
jllramos Posted May 4, 2016 Share Posted May 4, 2016 You can add new attribute table in ps_category by using phpmyadmin and adding this line in SQL: ALTER TABLE `ps_category` ADD `switch` TINYINT NOT NULL DEFAULT '0' Then go to classes/category.php and in "public static $definition" add new element in fields: 'switch' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), and save it in override/classes/category.php Now you can use it. For example when save category you can use: $myCategory = new Category(...); $myCategory->switch = 1; $myCategory->add(); Also you can create a new table but it have to save values independtly. E.g $myCategory = new Category(..); $switch = 1; dB::getInstance()->insert('my_table_created', array( 'id_category' => $myCategory->id, 'switch' => $switch )); 1 Link to comment Share on other sites More sharing options...
dwojod Posted May 4, 2016 Author Share Posted May 4, 2016 Thanks alot for a very useful information - now I can start work with my module there is something insistent - what happens to the original table when I do update the shop ? Link to comment Share on other sites More sharing options...
jllramos Posted May 4, 2016 Share Posted May 4, 2016 Normally database data have no change when prestashop update. Your tables and columns created will have no changes. But to avoid problems is good practice save database and files before update it. There are some problems to files. If you override Category.php file. Changes will no affect to that file and some error could appear. You have to override it again will your specific changes. Link to comment Share on other sites More sharing options...
dwojod Posted May 6, 2016 Author Share Posted May 6, 2016 (edited) I decided to create a new table. I added a new field to the category controller, and in the main file adds data to the database method "hookActionCategoryAdd" public function hookActionCategoryAdd($params) { $switch = Tools::getValue( 'switch' ); $insertData = array( 'id_category' => $params['category']->id, 'value' => $switch ); DB::getInstance()->insert('pmcategorylast', $insertData); } The question is: how to display the saved data when I edit category, I mean how can I edit in the back office ? Edited May 9, 2016 by dwojod (see edit history) Link to comment Share on other sites More sharing options...
dwojod Posted May 12, 2016 Author Share Posted May 12, 2016 My module is already finished. To edit and display saved data I used hookDisplayBackOfficeCategory. All functionality has been written using the appropriate hooks. jllramos thank for your help Link to comment Share on other sites More sharing options...
jasonbsmith Posted June 28, 2016 Share Posted June 28, 2016 Consider also to use a module http://addons.prestashop.com/en/blocks-tabs-banners/18173-category-fields.html http://addons.prestashop.com/en/search?id_category=0&search_query=fields Thanks you just saved me lots of time! I was looking all over for such an module and searched the addons and didn't find it, I even asked prestashop support 3 times and they didn't come across that gem! I was actually looking to change a standard template based on the category, but this seems like you can setup each category by itself, which is fine. I was about to try doing this instead. http://digitaldisseny.com/en/blog/195-prestashop-different-layouts-per-category 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