Hy,
I want to know how i can override existing ajax handler function exp: ''onUpdateTrackingInfo" existing in “OFFLINE\Mall\Controllers\Orders”.
Thanks
Hy,
I want to know how i can override existing ajax handler function exp: ''onUpdateTrackingInfo" existing in “OFFLINE\Mall\Controllers\Orders”.
Thanks
Hi @ridha82 ,
Can you try this in your boot() method in Plugin.php ? I’m not sure if it will overwrite or no.
public function boot() {
\Offline\Mall\Controllers\Orders::extend(function($controller) {
$controller->addDynamicMethod('onUpdateTrackingInfo', function() use ($controller) {
return '...';
});
});
}
Hmm…
I checked and there is no event fired on this method.
Would this work? Listening when the ajax call is fired and redirect the call to your own method.
addEventListener('ajax:before-send', function(event) {
if(event.detail.context.handler === "???::onUpdateTrackingInfo") {
// 1. cancel the current call
// 2. call your method
oc.ajax('onCalculate', {
success: function() {
console.log('Finished!');
}
})
}
});
Maybe ajax:setup could be more appriopriate? Not sure.
EDIT: looking into your network tab, you should be able to identify the handler
HI @apinard
I will try this solution, but I find it strange that October CMS does not offer a way to override this type of function.
Thanks
Hey @ridha82
I think it is more that the plugin doesn’t allow extension at a high level, however, you can achieve it at a low level.
Documented here: Rich Editor / WYSIWYG Field - October CMS - 3.x
Here’s how to override an AJAX handler for any backend controller:
Event::listen('backend.ajax.beforeRunHandler', function ($controller, $handler) {
if ($controller instanceof ... && $handler === 'onLoadPopup') {
// Do stuff and return to override
}
});
Keep in mind this is a low-level override and will need maintenance in line with the plugin, and will confuse any developer who doesn’t know about it (make sure you document it well!).
We recommend contacting the author to provide a first-party event to cover your requirements.