I'm working on an OpenCart customization and running into an issue with setting up an event to redirect the getApiByToken method. My goal is to modify the behavior of the catalog/model/setting/api.getApiByToken method by creating a custom version in extension/rest/setting/api.getApiByToken. However, despite setting everything up, it doesn’t seem to work as expected, and I’m not sure if there are restrictions or if I’m missing something.
Here’s my setup:
Database Event Configuration
In the oc_event table:
Trigger: catalog/model/setting/api.getApiByToken/after
Action: extension/rest/setting/api.getApiByToken
Custom Method Code:
Code: Select all
<?php
namespace Opencart\Catalog\Model\Extension\Rest\Setting;
class Api extends \Opencart\System\Engine\Model {
public function getApiByToken(string $token): array {
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "api` a LEFT JOIN `" . DB_PREFIX . "api_session` `as` ON (a.`api_id` = `as`.`api_id`) LEFT JOIN `" . DB_PREFIX . "api_ip` ai ON (a.`api_id` = ai.`api_id`) WHERE a.`status` = '1' AND `as`.`session_id` = '" . $this->db->escape((string)$token) . "'");
return $query->row;
}
}
Event registration in oc_event seems correct.
The namespace and class structure match the folder location.
I've tried both before and after triggers without success.
Error logs don’t provide any information related to this event.