Reputation: 16793
Is there a better way to check if a module has been installed in opencart. I am sure I must be missing something obvious for such a common task as this.
I want this to work in both the frontend (catalog) and admin area. This is the reason for checking if the method exists and if it is a multidimensional array.
$this->load->model('setting/extension');
$this->model_setting_extension = new ModelSettingExtension($this->registry);
if(method_exists($this->model_setting_extension, "getExtensions")){
$extensions = $this->model_setting_extension->getExtensions('module');
} else {
$extensions = $this->model_setting_extension->getInstalled('module');
}
$installed = false;
foreach($extensions as $extension){
if(is_array($extension) && $extension['code'] == "myfoo"){
$installed = true;
} elseif($extension == "myfoo") {
$installed = true;
}
}
if(!$installed){
exit('Error: Could not load module: myfoo!');
}
Upvotes: 2
Views: 4583
Reputation: 3485
Maybe not elegant solution, but I did not find another
$module_name = 'bla-bla-module';
$this->load->model('setting/extension');
$installed_modules = $this->model_setting_extension->getInstalled('module');
if(in_array($module_name, $installed_modules)) {
// Module installed
}
UPD: this is for 1.5.x
Upvotes: 2
Reputation: 15151
The easiest way is to simply check via a database query
$result = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `code` = 'myfoo'");
if($result->num_rows) {
// .. installed
} else {
// .. not installed
}
Upvotes: 5
Reputation: 7243
Does this work? (Source: http://forum.opencart.com/viewtopic.php?t=49724)
<?php
if ($this->config->get('modulename_status')) {
// ....do something
}
?>
Upvotes: 1