Post by OSWorX » Thu Mar 17, 2022 12:54 am

What are Events?
Events are introduced with OpenCart 2.x, enhanced with OpenCart 3.x.
And will (and should) be the only method for file manipulation when OpenCart 4.x will be published.

Please read here about Events: https://github.com/opencart/opencart/wiki/Events-System
And the announcement about disabling OCMod: https://github.com/opencart/opencart/wi ... ion-System
(valid as well for VQMod).

This topic should give answers to questions about Events.
Ask whatever you want, wether you are a developer or a "normal" user.
Or you are looking for a solution - post it.
Or have a solution - then help others, maybe they are searching for an snwer.

And we here try to answer as good as possible.

Below are a few links to already existing discussions/questions and sometimes also solutions.

Sending Email Confirmation to Customer Created in Admin
viewtopic.php?f=202&t=227654#p839058

OC 3.0.x Events System: How to modify twig template file?
viewtopic.php?f=144&t=221533

OpenCart Events
viewtopic.php?f=144&t=221534

How can I get in header.twig (Opencart 3.0.3.6) the product's images urls in order to add rel="preload" ?
viewtopic.php?f=202&t=227618&start=40#p839519

As a "starter package" I have created here 2 installable packages (OpenCart 2.x & 3.x) at GitHub:
https://github.com/osworx/opencart-event-boilerplate
The files include many comments, are ready for php 8.1.x and can be installed as standard extension.
They are accessable as Module (via the default Menu), have a settings page to en-/disable the module (and therefore also the event).
The event is installed automatically at module installation (and also deleted at uninstall).
Esay to adopt for own modules based on Events.
More samples will follow.

Beside this, this topic can be used also to link to the OpenCart Marketplace to extensions using only events.
This, because it was discussed earlier, and the Marketplace has currently no option to select and filter after extensions working only with events.

Example:
Order Copy Free
Robots noindex PRO

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by by mona » Thu Mar 17, 2022 9:49 am

:good: & Thank you OSWorX

So my first question ::)

For the sake of argument you need to add something to system/framework.php
For simplicity lets say you need to add

Code: Select all

$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');

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


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Thu Mar 17, 2022 11:47 am

OSWorX wrote:
Thu Mar 17, 2022 12:54 am
Or you are looking for a solution - post it.
Or have a solution - then help others, maybe they are searching for an snwer.
As long as it doesn't involve a paid license from the Marketplace, or a third party website publishing licensed extensions, since there's already a forum rule on that one whereas users needs to get in touch with extension developers during those times.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by OSWorX » Thu Mar 17, 2022 4:08 pm

straightlight wrote:
Thu Mar 17, 2022 11:47 am
OSWorX wrote:
Thu Mar 17, 2022 12:54 am
Or you are looking for a solution - post it.
Or have a solution - then help others, maybe they are searching for an snwer.
As long as it doesn't involve a paid license from the Marketplace, or a third party website publishing licensed extensions, since there's already a forum rule on that one whereas users needs to get in touch with extension developers during those times.
Time to speak (again) about one myth!

It does no matter under which license an extension is published, as long as OpenCart is licensed under the GNU/GPL every extension is automatically licensed under the same.

The license itself has nothing to do if paid or not - the GNU/GPL does not forbid to "sell" software (the opposite is true).
The only requirement für software published under the GNU/GPL is: it must be Open Source - which means: the program is not allowed to be encrypted.

The more, the GNU/GPL encourage people to edit and modify if needed.
And distributed - always under the rules of the GNU/GPL
https://www.gnu.org/licenses/gpl-3.0.en.html
https://en.wikipedia.org/wiki/GNU_Gener ... ic_License

THE restrictions under the GNU/GPL are:
1. if edited and distributed, the author is not allowed to modify or remove the headers (if existing)
2. sell it as his own work

Which means, if someone needs an advice or help, he can ask anyone.
To ask the original author is only a recommandation, because he should know his software.

>> There is no forum rule whereas users needs to get in touch with extension developers <<

While a recommandation IS, to use the Commercial Section of this Forum whenever a developer is required.

But questions about the license had been discussed many times here, so it's is useless to "warm it up" again.

And to write it again: this topic shall not be misused to solve common troubles/problems/questions about extensions!
It's only here to discuss the possibilities and the "fields of application" how events shall and can be used.
Anything else will be deleted without further comment.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Thu Mar 17, 2022 9:04 pm

OSWorX wrote:
Thu Mar 17, 2022 4:08 pm
>> There is no forum rule whereas users needs to get in touch with extension developers <<
If you have either downloaded a free extension or purchased one and are encountering issues with it, please follow this list:

Contact the developer either by using a provided email, developer ticketing system or a clickable link within the extension in the Admin
If not successful with 1, and you have purchased the extension, open a ticket with the Marketplace Support and let them handle it for you (Mon to Fri)
If 1 and 2 are not successful (like on a Weekend or public Holiday), you can always try the forum
Source: viewtopic.php?f=176&t=215777

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DigitCart » Thu Mar 17, 2022 9:06 pm

OSWorX wrote:
Thu Mar 17, 2022 12:54 am
Beside this, this topic can be used also to link to the OpenCart Marketplace to extensions using only events.
Many of my extensions are written based on the event system, A few examples:
Remember Active Tabs In Admin
Load More Products on Scroll
Custom Text Instead Of Price
Contact Form Builder
Custom Checkout Success Page
Admin User Activity Log
Last edited by DigitCart on Thu Mar 17, 2022 11:57 pm, edited 1 time in total.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by straightlight » Thu Mar 17, 2022 9:10 pm

The latest I did provided feedback to (free): Clearpay Extension Plug-In

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by OSWorX » Thu Mar 17, 2022 10:09 pm

straightlight wrote:
Thu Mar 17, 2022 9:04 pm
OSWorX wrote:
Thu Mar 17, 2022 4:08 pm
>> There is no forum rule whereas users needs to get in touch with extension developers <<
If you have either downloaded a free extension or purchased one and are encountering issues with it, please follow this list:

Contact the developer either by using a provided email, developer ticketing system or a clickable link within the extension in the Admin
If not successful with 1, and you have purchased the extension, open a ticket with the Marketplace Support and let them handle it for you (Mon to Fri)
If 1 and 2 are not successful (like on a Weekend or public Holiday), you can always try the forum
Source: viewtopic.php?f=176&t=215777
Okay, last time!
This - you highlighted - is only a recommendation, nothing else.
No obligation to ask the developer only, instead the buyer can ask someone else - it's his money.

And to close this question/comment: this thread here is ONLY for events and questions around.
Either you start to be constructive, or further comments will be deleted.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by OSWorX » Thu Mar 17, 2022 10:25 pm

straightlight wrote:
Thu Mar 17, 2022 9:10 pm
The latest I did provided feedback to (free): Clearpay Extension Plug-In
I really don't know why you are participating here ..
As written in my first post, events only
Now you are presenting an extension which use both: OCMod and Events.
Clear a misleading sample which does not fit into this category - but I let it here to show "how it should NOT be done".

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by OSWorX » Thu Mar 17, 2022 10:27 pm

DigitCart wrote:
Thu Mar 17, 2022 9:06 pm
Many of my extensions are written based on the event system, A few examples:
...
Thanks for providing, but rather making too much promotion, it would be really great if you could also show us a sample (or more) which is/are not paid.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by DigitCart » Fri Mar 18, 2022 12:01 am

OSWorX wrote:
Thu Mar 17, 2022 10:27 pm
Thanks for providing, but rather making too much promotion, it would be really great if you could also show us a sample (or more) which is/are not paid.
Thank you, I edited my previous post and added a free example to my list.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by straightlight » Fri Mar 18, 2022 3:23 am

OSWorX wrote:
Thu Mar 17, 2022 10:25 pm
straightlight wrote:
Thu Mar 17, 2022 9:10 pm
The latest I did provided feedback to (free): Clearpay Extension Plug-In
I really don't know why you are participating here ..
As written in my first post, events only
Now you are presenting an extension which use both: OCMod and Events.
Clear a misleading sample which does not fit into this category - but I let it here to show "how it should NOT be done".
I wasn't aware that restriction would apply even though Events are included among other Engines. I just thought it was well coded with the Events in the first place as being provided by another forum moderator in the meantime. However, since you're looking to use Events only without publication of other extensions, I'll specifically focus on the Events in the future as part as packages are concerned.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Cue4cheap » Fri Mar 18, 2022 3:47 am

As mentioned by others it would be good to have an example or two. Something simple we could all use to register the event and how to do something like replace some code. i.e. OCMOD/VQMOD function.
VQMOD and OCMOD are simple and I feel the reason it made Opencart widely used. A lot of people, and I count myself among them, wish to run a business selling things not spending a large amount of time working on the backend.
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by straightlight » Fri Mar 18, 2022 6:36 am

Cue4cheap wrote:
Fri Mar 18, 2022 3:47 am
As mentioned by others it would be good to have an example or two. Something simple we could all use to register the event and how to do something like replace some code. i.e. OCMOD/VQMOD function.
VQMOD and OCMOD are simple and I feel the reason it made Opencart widely used. A lot of people, and I count myself among them, wish to run a business selling things not spending a large amount of time working on the backend.
Mike
Something simple is already showed on the wiki documentation in Github Opencart. It is not much different than creating an extension module but a bit differed.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by OSWorX » Fri Mar 18, 2022 6:02 pm

Cue4cheap wrote:
Fri Mar 18, 2022 3:47 am
As mentioned by others it would be good to have an example or two. Something simple we could all use to register the event and how to do something like replace some code. i.e. OCMOD/VQMOD function.
VQMOD and OCMOD are simple and I feel the reason it made Opencart widely used. A lot of people, and I count myself among them, wish to run a business selling things not spending a large amount of time working on the backend.
Mike
As straightlight already wrote, basically Events are the same as the current widely used VQMods and OCMods.
The sample (and explainations) in the OpenCart Wiki are not the best - unfortunenately.
See a full working sample in the intital post (link to GH).
It's an installable package using an event.
More samples will follow - would be fine, if other developers would participate in this topic too.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Fri Mar 18, 2022 10:54 pm

OSWorX wrote:
Fri Mar 18, 2022 6:02 pm
Cue4cheap wrote:
Fri Mar 18, 2022 3:47 am
As mentioned by others it would be good to have an example or two. Something simple we could all use to register the event and how to do something like replace some code. i.e. OCMOD/VQMOD function.
VQMOD and OCMOD are simple and I feel the reason it made Opencart widely used. A lot of people, and I count myself among them, wish to run a business selling things not spending a large amount of time working on the backend.
Mike
As straightlight already wrote, basically Events are the same as the current widely used VQMods and OCMods.
The sample (and explainations) in the OpenCart Wiki are not the best - unfortunenately.
See a full working sample in the intital post (link to GH).
It's an installable package using an event.
More samples will follow - would be fine, if other developers would participate in this topic too.
It doesn't have to be the best. As part of an introduction level, it's more than enough to begin with.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by by mona » Fri Mar 18, 2022 11:40 pm

I was under the impression this was going to be an exclusive topic about Events with examples and hopefully iron out any limitations to avoid reinstallation of OCMOD / VQMOD .. I would be happy to provide some simple examples and some of my extensions on the marketplace are also solely events, however, so far this thread has become mostly chatter and already shows the critique level you will have to endure for being willing and able to assist ..

Maybe it would be better to have two independent threads - one for chatter and one exclusively fit for purpose ?

No offence to anyone - not directed at anyone - just an observation. Feel free to delete this post and carry on camping O0

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


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by OSWorX » Sat Mar 19, 2022 1:12 am

by mona wrote:
Fri Mar 18, 2022 11:40 pm
I was under the impression this was going to be an exclusive topic about Events with examples and hopefully iron out any limitations to avoid reinstallation of OCMOD / VQMOD .. I would be happy to provide some simple examples and some of my extensions on the marketplace are also solely events, however, so far this thread has become mostly chatter and already shows the critique level you will have to endure for being willing and able to assist ..

Maybe it would be better to have two independent threads - one for chatter and one exclusively fit for purpose ?

No offence to anyone - not directed at anyone - just an observation. Feel free to delete this post and carry on camping O0
No problem wit such a comment.
Examples will follow, just started this topic and as usual in each forum, some like to post also stuff where is shall not be.
Think that I have wrote about that clearly.

On the other side, if more developers would participate and ask or tell others what they think, and how they solved a "problem", I think this would help more.
You wrote that you have already some extensions working with Events only.
Why not link to some of them here (no extensive promotion!).

I for myself have absolutely no problem in sharing knowledge (just have to find more time beside the "normal" work).

But when I look at the OpenCart Marketplace and those ten thousands of extensions, and compare the amount of posts here, I assume that many of the so called "developers" are only here to make money - and nothing else.
Seems that many proceed with their lousy written extensions, finding ways to elude the limitations OC 3.x and 4.x have - just to install their own crap.

Nobody will and can steal anything when we all can improve the way Events are proper used.
And how they can replace VQMod and OCMod based extensions.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by OSWorX » Sat Mar 19, 2022 2:02 am

Cue4cheap wrote:
Fri Mar 18, 2022 3:47 am
As mentioned by others it would be good to have an example or two. Something simple we could all use to register the event and how to do something like replace some code.
Currently Events are based on having a Controller which must have the logic - as function - included.

Based on the sample in the OpenCart Wiki (https://github.com/opencart/opencart/wi ... fore-event):

Code: Select all

class ControllerExtensionModuleProductNotification extends Controller {
    // admin/model/catalog/product/addProduct/before
    public function addProduct(&$route, &$args) {
        .. here the manipulation (editing see below) is done ..
    }
}
A "normal" controller (file) which every extension has.

Store the new file as product_notification.php inside the folder:

Code: Select all

../admin/controller/extension/module/
Here included the function for the event:

Code: Select all

public function addProduct(&$route, &$args)
which is triggered by:

Code: Select all

admin/model/catalog/product/addProduct/before
The code, trigger and the action has currently to be stored in the database table events manually (as long as the controller has no install function).
Code: admin_product_notify
Trigger: admin/model/catalog/product/addProduct/before
Action: extension/module/product_notification/addProduct
Status: 1
Sort Order: 1 or other (if several equal events are called, the sort order is important, otherwise does no matter which value is used here.

With OC 4.x there will be be more field: Description (to show what's the purpose of the event)

Means: whenever a (new) product is created in the backend, an additional action (the event) is called.
Important to see, that the event is called with before, which means the actions are defined in the event function are all handled before the product is added (to the database).

Let's look at the variable $args which is handled as a reference (means, all what I do here with it, is later on available).
It is therefore also possible here to "manipulate" values - so be careful!

Here you will find all values the user submitted when he hit the Save button to store the new product.

Code: Select all

Array
(
    [0] => Array
        (
            [product_description] => Array
                (
                    [2] => Array
                        (
                            [name] => test2
                            [description] => &lt;p&gt;beschreibung DE&lt;br&gt;&lt;/p&gt;
                            [meta_title] => metatitel
                            [meta_description] => metabeschreibung
                            [meta_keyword] => metaschlüsselwort
                            [tag] => suchbegriff
                        )

                    [1] => Array
                        (
                            [name] => test2
                            [description] => &lt;p&gt;desc test 2&lt;br&gt;&lt;/p&gt;
                            [meta_title] => metatitle
                            [meta_description] => metadesc
                            [meta_keyword] => metakeyword
                            [tag] => searchitem
                        )

                )

            [model] => test002
            [sku] => 
            [upc] => 
            [ean] =>
And so on ..

As we can see, there is one (1) array containing all values [0]
Now, when we want to manipulate the model (to keep it simple), we can do it that way:

Code: Select all

$args[0]['model'] = 'newmodel';
So, we have now instead the former value test002 > newmodel

This can be done with every value.
We could call also another template to view that instead, or (as the original example suggests), to notify someone ..

Inside the event function every other/additonal controller or model can be called and additional actions be made.
Cue4cheap wrote:
Fri Mar 18, 2022 3:47 am
Something simple we could all use to register the event ..
Sorry, but such a function (or extension) does not exits (currently).
I have suggested to create a "general" Module in the backend which can be used for exactly such purpose.
It would be good to have such a functionalitity in the core, because currently Events can be used only when - at least - a controller exists.
But maybe I create such - thought already by myself to have it, because currently it is not so easy (like it was done by adding a simple (or obstruse) xml-file).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by OSWorX » Sat Mar 19, 2022 2:04 am

by mona wrote:
Fri Mar 18, 2022 11:40 pm
Maybe it would be better to have two independent threads - one for chatter and one exclusively fit for purpose ?
Forgot 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).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 23 guests