Any suggestions will be greatly appreciated,
OC Version:3.0.2.0
More information on how to properly create an event can be found on this documentation: https://github.com/opencart/opencart/wiki/Events-System . Otherwise, you can always create a new service request in the Commercial Support section of the forum or contact a reliable Opencart Partner from the top Resources link of this site to get this done as a custom job.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
I have tried what you have sugested but the after event seems dont work...straightlight wrote: ↑Sun Sep 27, 2020 2:40 amThe $this->session->data['error'] does not exist in the core from admin/controller/catalog/product.php file. You'd need to create this session super global name in your /before event. Then, in your /after event, to output the captured error into your $output referenced variable into your TWIG string or file and unset the error key from the session super global. This can also be accomplished without the $this->session->data by simply outputting the error message string into your $output from the /after once redirected.
More information on how to properly create an event can be found on this documentation: https://github.com/opencart/opencart/wiki/Events-System . Otherwise, you can always create a new service request in the Commercial Support section of the forum or contact a reliable Opencart Partner from the top Resources link of this site to get this done as a custom job.
I have create this before event and is working:
Code: Select all
$this->model_setting_event->addEvent("check_model_unique","admin/controller/catalog/product/add/before","extension/module/my_custom_settings/checkModelUnique");
Code: Select all
$this->model_setting_event->addEvent("check_model_uniquea","admin/controller/catalog/product/add/after","extension/module/my_custom_settings/checkModelUniquea");
Code: Select all
public function checkModelUniquea(&$route, &$args, &$output) {
$this->log->write("teste");
}
I want to stop before addProduct is executed and redirect to the add form product with the error.
I can do that with jquery before submit the form i call with ajax an method and return the error, but i want to do that with an event and without jquery/ajax.
As much as I prefer events, this can be done with ocmod on the validate method in few lines of code.
Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
All input carried back to the view with the error message needing to be unique it will be more nice for the user when adding product. In my case I dont have a lot of input, because i have disabled many of them, but if you fill all the input that come with opencart and you receive a message that the model need to be unique and you need to fill again those input , this will be in a nightmare..sw!tch wrote: ↑Tue Sep 29, 2020 10:03 amDo you want all input carried back to the view or just halt execution? Simple to just stop execution of the code, if you want an error message on model needing to be unique its more involved.
As much as I prefer events, this can be done with ocmod on the validate method in few lines of code.
What a learn after reading, if I want to stop the execution of the code is simple, just need to return $data on the event...
This is why I want to learn how we can use the event system without using ocmod, vqmod or edit "system" file of opencart.From https://github.com/opencart/opencart/wi ... ion-System
As of OpenCart 3.1.0.0+ OCMOD will be removed from the OpenCart source code. Only the event system will be used for modifications.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Simply replace:
Code: Select all
public function checkModelUniquea(&$route, &$args, &$output) {
Code: Select all
public function checkModelUniquea(&$route, &$args) {
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $route == 'model/catalog/product/addProduct') {
// Your action here.
}
}
In this scenario, if you want to use a /after, you could always pull the new $product_id added on your database from the model.
Code: Select all
public function checkModelUniquea(&$route, &$args, &$output) {
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $route == 'model/catalog/product/addProduct') {
// Last product ID.
$this->load->model('catalog/product');
$product_id = $this->model_catalog_product->addProduct($args);
}
}
Code: Select all
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $route == 'model/catalog/product/addProduct') {
Code: Select all
if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->get['route']) && $this->request->get['route'] == 'model/catalog/product/addProduct') {
Code: Select all
admin/controller/catalog/product/add/before
Code: Select all
admin/model/catalog/product/addProduct/before
Code: Select all
if ($route == 'model/catalog/product/addProduct') {
// Your action here.
}
Also assuming your extension module's filename is conformed to the one you entered on the database in your events table.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: Bing [Bot] and 224 guests