Skip to content

Instantly share code, notes, and snippets.

@halfhope
Created April 10, 2023 01:29
Show Gist options
  • Save halfhope/8bd0871244ae4fa54f62aaceb66d5945 to your computer and use it in GitHub Desktop.
Save halfhope/8bd0871244ae4fa54f62aaceb66d5945 to your computer and use it in GitHub Desktop.
Opencart check for the existance of a function in the model
// opencart 2.3, 3.x
private $_route = 'extension/module/pmp';
private $_model = 'model_extension_module_pmp';
$class_name = preg_replace('/[^a-zA-Z0-9]/', '', $this->_model);
if (is_callable([$class_name, 'getCachePrecomputedParams'])) {
$result = $this->{$this->_model}->getCachePrecomputedParams();
}
// opencart 4
private $_route = 'extension/pmp/module/pmp';
private $_model = 'model_extension_pmp_module_pmp';
$class_name = 'Opencart\\' . $this->config->get('application') . '\Model\\' . str_replace(['_', '/'], ['', '\\'], ucwords($this->_route, '_/'));
if (method_exists($class_name, 'getCachePrecomputedParams')) {
$result = $this->{$this->_model}->getCachePrecomputedParams();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment