Baudo Posted March 3, 2015 Share Posted March 3, 2015 (edited) Hi everyone, I want that when I install my module is added a new group for users. I try this: $sql = array(); $sql[] = 'INSERT INTO `'._DB_PREFIX_.'group` (reduction,price_display_method,show_prices) VALUES (0.00, 0, 1)'; $idgroup = Db::getInstance()->getValue("SELECT MAX(id) FROM `"._DB_PREFIX_."group`"); foreach ($sql as $query) if (Db::getInstance()->execute($query) == false) return false; in $idgroup I have the id of my group, now I have to put the names in the ps_group_lang with the id of the language, is correct? Edited March 3, 2015 by Baudo (see edit history) Link to comment Share on other sites More sharing options...
Tuni-Soft Posted March 3, 2015 Share Posted March 3, 2015 (edited) Don't use sql queries when you can use PrestaShop classes $languages = Language::getLanguages(); $group_names = array( 'en' => 'new group', 'fr' => 'nouveau groupe' //.... ); $group = new Group(); $group->reduction = 5.00; //% $group->price_display_method = PS_TAX_EXC; // or PS_TAX_INC $group->show_prices = false; $group->name = array(); foreach ($languages as $lang) { $id_lang = $lang['id_lang']; $iso_lang = $lang['iso_code']; $group->name[$id_lang] = isset($group_names[$iso_lang]) ? $group_names[$iso_lang] : $group_names['en']; } $group->save(); Edited March 3, 2015 by Tuni-Soft (see edit history) 1 Link to comment Share on other sites More sharing options...
Baudo Posted March 3, 2015 Author Share Posted March 3, 2015 (edited) Thanks for the suggestion, I have another question, if I want to assign a new user to that category, as do the id of the right category? Work? function hookCreateAccount($params) { $customer = $params['newCustomer']; $idcategory = Configuration::get("MY_MODULE_ID-GROUP") $customer->addGroups($idcategory); } public function install() { $languages = Language::getLanguages(); $group_names = array( 'en' => 'New Group' ); $group = new Group(); $group->reduction = 20.00; $group->price_display_method = PS_TAX_INC; // or PS_TAX_EXC $group->show_prices = true; $group->name = array(); foreach ($languages as $lang){ $id_lang = $lang['id_lang']; $iso_lang = $lang['iso_code']; $group->name[$id_lang] = isset($group_names[$iso_lang]) ? $group_names[$iso_lang] : $group_names['en']; } $group->save(); Configuration::updateValue('MY_MODULE_ID-GROUP', $group->id); //work after save? return parent::install() && $this->registerHook('createAccount'); } Edited March 3, 2015 by Baudo (see edit history) Link to comment Share on other sites More sharing options...
Baudo Posted March 6, 2015 Author Share Posted March 6, 2015 another question, when I create the group have all modolu deactivated for that group, how do I turn them all? 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