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.
Hey @ridha82 ,
Did you find a way to do this. I am looking for same. If you can share your solution here it would be great.
Thanks
I overridden the file (.htm) that contains the call to the function, and I created a new function that I called from my override.
Thanks
Can you show me the steps or so? And also the function to handle the tracking info
Thanks alot
1 - In your plugin, in the boot function of your plugin.php file, add:
OFFLINE\Mall\Controllers\Orders::extend(function ($controller) {
list($author, $plugin) = explode('\\', strtolower(get_class()));
$partials_path = sprintf('$/%s/%s/controllers/orders', $author, $plugin);
$controller->addViewPath($partials_path);
$controller->addDynamicMethod('onUpdateTrackingData', function() use ($controller) {
// write your logic here
});
}
2- Copy the file from plugins/offline/mall/controllers/orders/_tracking_modal.htm to plugins/{your_author}}/{your_plugin}/controllers/orders/_tracking_modal.htm
3- change the function onUpdateTrackingInfo with your new function onUpdateTrackingData in plugins/{your_author}}/{your_plugin}/controllers/orders/_tracking_modal.htm