Post by jane3144fitzgibbon » Fri Nov 15, 2024 4:05 pm

Hi everyone,

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;
    }
}
I've checked the following:

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.

edu financial



Posts

Joined
Fri Nov 15, 2024 4:00 pm

Post by JNeuhoff » Fri Nov 15, 2024 11:12 pm

try this file in your extension's catalog/controller/setting/api.php:

Code: Select all

<?php
namespace Opencart\Catalog\Controller\Extension\Rest\Setting;

class Api extends \Opencart\System\Engine\Controller {

	public function eventModelSettingApiGetApiTokenAfter(string &$route, array &$args, mixed &$output): void {
		$token = $args[0];
        $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) . "'");
        $output = $query->row;
    }
}

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by khnaz35 » Sun Nov 17, 2024 1:26 am

Maybe we should share some example from the opencart itself , may be from on catalog/model/account/customer/editCode/after

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member
Online

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia
Who is online

Users browsing this forum: Semrush [Bot] and 11 guests