kimokimo Posted January 9, 2020 Share Posted January 9, 2020 Dear Community, I was trying to create a module that activate the API and set the rights then it generate the key of this created API still i didn't found any documentation that matchs my needs. this need to be done from the module not manually from prestashop ( back-end code ). thanks PS: i am new to prestashop please help Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 On 1/13/2020 at 5:29 PM, ndiaga said: Hi, You have save the API KEY in a configuration value and call it where you need it in your module. could you please go further in details ? how do i save the API KEY in a configuraiton value ? Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 1 hour ago, ndiaga said: Can you please share your code? public function install() { $keyId = $this->getKeyId(); $wsKey = new WebserviceKey($keyId ? $keyId : null); $wsKey->active = true; $wsKey->description = self::KEY_DESCRIPTION_MARKER; do { $wsKey->key = $this->generateKey(self::KEY_LENGTH); } while (WebserviceKey::keyExists($wsKey->key)); $wsKey->add(); $permissions_file = "../modules/".$this->name."/data/permissions.json"; $jsonPermissions = file_get_contents($permissions_file); //TODO controlli sul file $permissions_to_set = json_decode($jsonPermissions,true); $wsKey->setPermissionForAccount($wsKey->id,$permissions_to_set); $configuration = new stdClass(); $configuration->soap_key = $wsKey->key; Configuration::updateValue('XXX_CONFIGURATION', json_encode($configuration)); return parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('displayBackOfficeHeader'); } i was trying this code that i found in this post https://www.prestashop.com/forums/topic/947964-how-to-set-up-permission-for-user-programmatically/?_fromLogin=1 but unfortunatly it dosn't seems to work its missing some parts i guess Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 24 minutes ago, ndiaga said: Just you did not put the configuration value in the right place. Configuration::updateValue('XXX_CONFIGURATION', json_encode($configuration)); //this should go inside the condition return parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('displayBackOfficeHeader'); // do this : return (parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('displayBackOfficeHeader') && Configuration::updateValue('XXX_CONFIGURATION', json_encode($configuration)) ); what about $keyId = $this->getKeyId(); ? is this predifined in prestashop ? Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 3 hours ago, ndiaga said: No, the PrestaShop function to save a configuration value is : Configuration::updateValue('Variable_Namae', 'Value t save here' ) i have tried changing what you propsed but unlucky. the problem isn't solved because the system dosn't recognize the key ID $keyId = $this->getKeyId(); can you please try running the code. Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 5 minutes ago, ndiaga said: Running it where? try to run the code on your machine ! Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 Just now, ndiaga said: From what I read in your code you don't even need to save data in the configuration. You can just call the json_encode($configuration) where you want it to be . i tried to forget about that part and leave only the rest of the code, but that didn't make it work. what i come to is that the problem is come to the first instruction wich is the one i mentioned earlier $keyId = $this->getKeyId(); do i have by deafault the $this->getKeyId() funciton in the install() function ? or in module ? or that i need to impliment some code to get it working ? Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Author Share Posted January 15, 2020 1 minute ago, ndiaga said: I see you just copy from here? yes, that's what i have done. i am trying to create a Module that activate the API by code like it will be automated. then i just found that code seems to be talking about what i wanna do so i just copy paste in install() function but that dosn't seems to be working. 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