Reputation: 11797
I am extending opencart and I am building a custom controller for catalog for uploading products via CSV. I am getting this error when I try and view catalog/upload You do not have permission to access this page, please refer to your system administrator.
.
I figured I would need to change the permissions in the db, and found a function to do so
$this->model_user_user_group->addPermission($this->user->getId(), 'access', 'catalog/upload');
$this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'catalog/upload');
I put this in a module built for the sole purpose of addiing these permissions when it installs
<?php
class ControllerModuleInstl extends Controller {
public function install() {
$this->load->model('user/user_group');
$this->model_user_user_group->addPermission($this->user->getId(), 'access', 'catalog/upload');
$this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'catalog/upload');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('instl', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
}
}
?>
I click install, I get a success message (no page redirect however), when I check the DB the permissions have not been changed.
I find this hard to debug because when usually debugging Ill use echo and such, but obviously you can't do this kind of thing with an application of this size (I usually just write small scripts), what is the best way to debug opencart, step through it, and also can anyone tell me why my permissions are not being changed?
Thanks!
Upvotes: 0
Views: 8979
Reputation: 41
You know function "addPermission" of Opencart, it set params with "user group id" not about "user id" you set it above. So:
You can get user group id with:
$user_group_id = $this->user->getGroupId();
After that, you addPermission "access/modify" for this user group of user.
$this->model_user_user_group->addPermission($user_group_id, 'access', 'catalog/upload');
$this->model_user_user_group->addPermission($user_group_id, 'modify', 'catalog/upload');
Upvotes: 0
Reputation: 36
To answer your simpler question you can use:
$this->log->write('message');
in place of echo.
It will send the message to the admin panel's error log in Opencart.
Upvotes: 1
Reputation: 13525
Here is how i fixed this problem when i faced it. Opencart stores it permission by serializing a php array to the database. write a small utility to grab that record and deserialize it and then add your permissions to it then serialize and write it back.
Upvotes: 1