Well, as a forum moderator, what you are also implying at this point is that forum users are rather encouraged to post on your Github repository than they should on the Opencart Forum.OSWorX wrote: ↑Sat Mar 19, 2022 2:04 amForgot completely, that I have enabled the Discussion board here:
https://github.com/osworx/opencart-even ... iscussions
Guess for true interested devs that this should fit more than this forum here (which is basically a "user" forum).
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Well, I am sure your can read:straightlight wrote: ↑Sat Mar 19, 2022 2:49 amWell, as a forum moderator, what you are also implying at this point is that forum users are rather encouraged to post on your Github repository than they should on the Opencart Forum.
Guess for true interested devs that this should fit more than this forum here (which is basically a "user" forum).
Devs = Developer
This forum here is for users (like you).
A ususal "user" has no interest how the code is working, it has to work.
So stop complaining.
And it does no matter if mine, yours or someone else!
You can participate, or let it.
Last time I write this.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
viewtopic.php?f=202&t=227654&start=20#p839322
The solution with event only.
Fields for the database (table event) where a new entry has to be made:
code: admin_limit_images
trigger: admin/view/catalog/product_form/after
action: extension/module/product_images/eventViewTemplateCatalogProductFormAfter
And the event code itself:
Code: Select all
/**
* code: admin_limit_images
* trigger: admin/view/catalog/product_form/after
* action: extension/module/product_notification/eventViewTemplateCatalogProductFormAfter
*/
public function eventViewTemplateCatalogProductFormAfter( &$route, &$args, &$output ) {
preg_match_all( '/onclick="\$\(\'#image-row.\'\)\.remove\(\);/', $output, $matches );
if( $matches[0] ) {
foreach( $matches[0] as $match ) {
$output = str_replace( $match, $match . ' myFunction();', $output );
}
}
$search = 'function addImage() {';
$replace = '
if (image_row < 5 ) {';
$output = str_replace( $search, $search . $replace, $output );
$search = 'image_row++;';
$replace = '
} else {
html = \'<tfoot><tr><td colspan="3"><h2>You have already reached the limit of 5 images.</h2></td></tr></tfoot>\';
$(\'#images tfoot\').replaceWith(html);
}';
$output = str_replace( $search, $search . $replace, $output );
$search = <<<JS
onclick="$(\'#image-row' + image_row + '\').remove();
JS;
$replace = <<<JS
onclick="$(\'#image-row' + image_row + '\').remove(); myFunction();
JS;
$output = str_replace( $search, $replace, $output );
$search = '</body>';
$replace = <<<JS
<script>
function myFunction() {
html = '<tfoot><tr><td colspan="2"></td><td class="text-left"><button type="button" onclick="addImage();" data-toggle="tooltip" title="{{ button_image_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td></tr></tfoot>';
$('#images tfoot').replaceWith(html);
image_row--;
}
</script>
JS;
$output = str_replace( $search, $replace . $search, $output );
}
}
product_notification.php
which has to be stored in the folder:
../admin/controller/extension/module/
A complete solution would be, to create a whole extension which is installable by the commin OpenCart installer.
And with that, the event could be easely en- and disabled, as well as permission can be set (for user groups).
Note: this is only one way to reach the "goal" (at least 3 are possible).
But maybe another one here has a better solution, then don't hasitate to post it.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Sorry for the delay in answering, too much work ..by mona wrote: ↑Thu Mar 17, 2022 9:49 amSo my first question![]()
For the sake of argument you need to add something to system/framework.php
For simplicity lets say you need to addCode: Select all
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); $response->addHeader('Pragma: no-cache');
Counter-questions:
1. when shall these headers be added
2. and what for
Guess has to do with the caching issue mentioned earlier somewhere ..
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Short quotes from my article (2.3, 3.x, 4.x). If you see some errors in translation, write in PM.
Features when using events
- Events can only be added from admin controllers. The most convenient way to do this is when installing the module, in the install function.
- The paths of all triggers begin with the name of the desired section, admin, catalog or library. The admin and catalog sections contain the controller, view, language, and config.
- You can use "*" in trigger paths to assign triggers by mask. For example catalog/view/theme/*/template/common/header/after.
- To change the data in the config and language event handlers, use $this->config->set(), $this->language->set() respectively.
- Data received from event handlers can be stored within the class and used in other handlers that are run later.
Features for different versions of Opencart
- The event code for version 2.3 must be no longer than 32 characters. For versions 3.x and 4.x no more than 64.
- In version 2.3, events (registration, deletion, etc.) are handled by the extension/event model, in 3.x and 4.x setting/event.
- In version 2.3, in the catalog section, the before/after view trigger paths will be different. For example, catalog/view/common/header/before, catalog/view/default/template/common/header/after. This is due to the use of themes in the catalog section and assigned events.
- Since version 3.x, the sort order of events has been added.
- Since version 4.x each event must have a description.
- Triggers for libraries (library) are available only from version 4.x.
Arguments
Arguments are passed to event handlers by reference. This means that you can change the values of the arguments without worrying about passing the result somewhere else.

Return Values
In addition to changing data through arguments, event handlers can also return values using return. For example, if the controller/common/home/before event handler returns the generated html code via return, then the entire output of the common/header controller will be replaced by it, and the common/header controller itself will not be executed, but the after event will be fired. Those. it is possible to replace the execution data of functions without executing them.

Original article has important comment from opencartforum.com user @Vladzimir:
I will add from myself that event triggers eat up 10-20% of the page generation time.
The reason is banal - the implementation is made through the gluteal muscle.
Attached is the system/engine/event.php file for 2.3, which allows you to significantly speed up this moment (and even reduce PeakMemory)
Attachments
My FREE extensions in marketplace. [ security | flexibility | speedup ]
Hardcoded language which limits the knowledge of language packs to be used with Events. Besides, there's no need to add black slashes nor the need to use: <<<JS at the beginning of replacements.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Your're really a funny guy.straightlight wrote: ↑Sat Mar 19, 2022 9:30 pmHardcoded language which limits the knowledge of language packs to be used with Events. Besides, there's no need to add black slashes nor the need to use: <<<JS at the beginning of replacements.
First check the original script (OCMod file) and then you may post here further.
The script from me was only the answer to the question (challenge).
And the original had a similiar line in it.
Having "Programmer" in his signature and does not know what <<<JS stands for or why the backslashes are at that positions.
But you can try it without ..
The only argument from you - which is valid, that "hardcoded language strings" should be avoided.
But as "Programmer" you could join this topic and present your better solution of all.
Instead of posting useless comments!
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Then, based on my last post, that's all we need to know.OSWorX wrote: ↑Sat Mar 19, 2022 10:05 pmYour're really a funny guy.straightlight wrote: ↑Sat Mar 19, 2022 9:30 pmHardcoded language which limits the knowledge of language packs to be used with Events. Besides, there's no need to add black slashes nor the need to use: <<<JS at the beginning of replacements.
First check the original script (OCMod file) and then you may post here further.
The script from me was only the answer to the question (challenge).
And the original had a similiar line in it.
Having "Programmer" in his signature and does not know what <<<JS stands for or why the backslashes are at that positions.
But you can try it without ..
The only argument from you - which is valid, that "hardcoded language strings" should be avoided.
But as "Programmer" you could join this topic and present your better solution of all.
Instead of posting useless comments!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Well I did that in my Mod - Its hardly OSWorX is it. OSWorX has gone out of his way to do this and I am extremely grateful to OSWorX and halfhope for the information they are providing and the help being given. OSWorX conversion is how I would have gone about it also at this stage and I have been reading the method of views manipulation by J Neuhoff here viewtopic.php?f=144&t=221533&hilit=even ... de#p807696.straightlight wrote: ↑Sat Mar 19, 2022 9:30 pmhtml = \'<tfoot><tr><td colspan="3"><h2>You have already reached the limit of 5 images.</h2></td></tr></tfoot>\';
Hardcoded language which limits the knowledge of language packs to be used with Events.
We are called DEVELOPERS for a reason - You start off with something that is NOT PERFECT usually. Then you DEVELOP during testing etc etc.
The hardcoded lines are ONLY in the initial development of what I do. If the CONCEPT proves worthy and worth FURTHER DEVELOPMENT these things then get FIXED as we go. If the CONCEPT is NOT worthy or went in the wrong direction then NO NEEDLESS time is wated.
Thanks again.
While JNeuhoff does indeed not use <<<JS nor back slashes in his Event code on that post, he doesn't seem to use the $this->load->view either but this dismissal isn't critical based on the concept to show how the core extensions' are already coded.mikeinterserv wrote: ↑Sat Mar 19, 2022 10:54 pmWell I did that in my Mod - Its hardly OSWorX is it. OSWorX has gone out of his way to do this and I am extremely grateful to OSWorX and halfhope for the information they are providing and the help being given. OSWorX conversion is how I would have gone about it also at this stage and I have been reading the method of views manipulation by J Neuhoff here viewtopic.php?f=144&t=221533&hilit=even ... de#p807696.straightlight wrote: ↑Sat Mar 19, 2022 9:30 pmhtml = \'<tfoot><tr><td colspan="3"><h2>You have already reached the limit of 5 images.</h2></td></tr></tfoot>\';
Hardcoded language which limits the knowledge of language packs to be used with Events.
We are called DEVELOPERS for a reason - You start off with something that is NOT PERFECT usually. Then you DEVELOP during testing etc etc.
The hardcoded lines are ONLY in the initial development of what I do. If the CONCEPT proves worthy and worth FURTHER DEVELOPMENT these things then get FIXED as we go. If the CONCEPT is NOT worthy or went in the wrong direction then NO NEEDLESS time is wated.
Thanks again.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
You can be so frustrating straightlight. You comments are nearly ALLWAYS destructive rather than constructive. If you switched this around you would get a lot more respect.straightlight wrote: ↑Sat Mar 19, 2022 11:08 pmWhile JNeuhoff does indeed not use <<<JS nor back slashes in his Event code on that post, he doesn't seem to use the $this->load->view either but this dismissal isn't critical based on the concept to show how the core extensions' are already coded.
As said on the above, it isn't a big deal in another words which means that demonstration is fine.mikeinterserv wrote: ↑Sat Mar 19, 2022 11:16 pmYou can be so frustrating straightlight. You comments are nearly ALLWAYS destructive rather than constructive. If you switched this around you would get a lot more respect.straightlight wrote: ↑Sat Mar 19, 2022 11:08 pmWhile JNeuhoff does indeed not use <<<JS nor back slashes in his Event code on that post, he doesn't seem to use the $this->load->view either but this dismissal isn't critical based on the concept to show how the core extensions' are already coded.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Attachments
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
No problem for the delay, I have quite a lot on both work and personally, there is no rush.
I used it as a simple issue that has arisen where a system file is required to be edited, essential rather than cosmetic. My question is can/how would it be done using Events exclusively today in OC3?
Currently in OCMOD
Code: Select all
<file path="system/framework.php">
<operation>
<search><![CDATA[$response->addHeader('Content-Type: text/html; charset=utf-8');]]></search>
<add position="after"><![CDATA[
$response->addHeader('Cache-Control: public, max-age=1, no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');
]]></add>
</operation>
</file>
To answer your question when. That is part of the question because there is no function in the system/framework.php to add it before or after.
To answer question why. In the case above it is caching, it is the simplest thing I can think of to request a simplest example to follow. On a Varnish Server and other issues without it Opencart is rendered useless, the cart simply will not function correctly.
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
I doubt anyone is going to purchase a module just to learn how Events work

Anyway, I created a simple "how to add a custom css stylesheet using Events only".
https://www.opencart.com/index.php?rout ... n_id=43491
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
halfhope wrote: ↑Sat Mar 19, 2022 5:50 pmArguments
Arguments are passed to event handlers by reference. This means that you can change the values of the arguments without worrying about passing the result somewhere else.
Return Values
In addition to changing data through arguments, event handlers can also return values using return. For example, if the controller/common/home/before event handler returns the generated html code via return, then the entire output of the common/header controller will be replaced by it, and the common/header controller itself will not be executed, but the after event will be fired. Those. it is possible to replace the execution data of functions without executing them.
![]()

great reference table - thank you
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
Correct, but to be honest: creating only "paid" extensions is also not the way it should be.
Maybe some see people OpenCart to make money only, but those should also not forget that they benefit from OpenCart itself - which is free (in every sense).
So, creating also "free" extensions (even if they are small) and share/publish should be the minimum (for a good developer).
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Well, because adding headers are done before any output is made, means it should (and can) be done whenever the common header is called.by mona wrote: ↑Sun Mar 20, 2022 8:32 amI used it as a simple issue that has arisen where a system file is required to be edited, essential rather than cosmetic. My question is can/how would it be done using Events exclusively today in OC3?
Currently in OCMODCode: Select all
<file path="system/framework.php"> <operation> <search><![CDATA[$response->addHeader('Content-Type: text/html; charset=utf-8');]]></search> <add position="after"><![CDATA[ $response->addHeader('Cache-Control: public, max-age=1, no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); $response->addHeader('Pragma: no-cache'); ]]></add> </operation> </file>
Therefore:
Code: Select all
<?php
/**
* @version $Id: event.php 6487 2022-03-20 13:13:00Z mic $
* @package Event
* @author mic - https://osworx.net
* @copyright 2022 OSWorX
* @license MIT
*/
class ControllerExtensionModuleEvent extends Controller {
public $version = '1.0.0';
/**
* code: ox_catalog_header
* trigger: catalog/view/common/header/after
* action: extension/module/event/eventCatalogViewCommonHeaderAfter
*/
public function eventCatalogViewCommonHeaderAfter( &$route, &$args, &$output ) {
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
}
}
Folder: ../catalog/controller/extension/module/
It' s what I thought (caching) - saw some discussions here or at GH about it.by mona wrote: ↑Sun Mar 20, 2022 8:32 amTo answer your question when. That is part of the question because there is no function in the system/framework.php to add it before or after.
To answer question why. In the case above it is caching, it is the simplest thing I can think of to request a simplest example to follow. On a Varnish Server and other issues without it Opencart is rendered useless, the cart simply will not function correctly.
But adding such header via any method (does no matter which one) should be avoided primary.
Better if the core would have a method to add custom headers - e.g. via the system config (settings page).
While I have never seen such an issue in all the years (and have many clients over the whole world at different hosters and servers), making a PR at GH is free for everyone.
And I am sure that Daniel - when provided with enough details why and what for - will not decline such a request.
Attachments
catalog/controller/extension/module/event.php
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
In part it is a new way of thinking and approach. I am sure we will get used to it, or not ..
The example was just for simplicity. I am pretty sure for OC4 Daniel has added it already.
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
I do and did offer the example posted above for freeOSWorX wrote: ↑Sun Mar 20, 2022 7:26 pmCorrect, but to be honest: creating only "paid" extensions is also not the way it should be.
Maybe some see people OpenCart to make money only, but those should also not forget that they benefit from OpenCart itself - which is free (in every sense).
So, creating also "free" extensions (even if they are small) and share/publish should be the minimum (for a good developer).

I was answering why I did not previously post links to my modules that use Events !
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
Users browsing this forum: No registered users and 3 guests