Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Thank you @JNeuhoff. Got it.JNeuhoff wrote: ↑Sat Jan 30, 2021 8:16 pmTake a look at this forum post which should answer your question.kestas wrote: ↑Sat Jan 30, 2021 5:40 pm
All sounds good, but if I correctly understand there no possibility, using events, add to the twig files particular code... For example if I need additional column in order list (admin) to display which shipping method was used for the order... If it is possible to add specific code to twig files using events, can anyone give an example of how to do this properly?
Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
Would be fine .. but is not true.straightlight wrote: ↑Sun Jan 31, 2021 9:33 amcatalog/controller/extension/advertise/google.php provides all the /after events where multiple examples shows how to call a TWIG file from the controller as well.
Don't know why your are posting such nonsens - maybe it's sunday and you have nothing to do?
That file is adding only a few data to the $data array, and then adding only simple javascript code to the template by replacing the body tag.
This has nothing to do with replacements inside a twig template when someone wants to add some new code fragments, remove or change.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
If a file has more identical lines how you can search and replace only 1 line?OSWorX wrote: ↑Sat Jan 30, 2021 7:02 pmA simplewill do that (of course $search & $replace defined before).Code: Select all
$tpl = str_replace( $search, $replace, $tpl );
In ocmod is search index=x
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
OSWorX wrote: ↑Sun Jan 31, 2021 9:51 pmWould be fine .. but is not true.straightlight wrote: ↑Sun Jan 31, 2021 9:33 amcatalog/controller/extension/advertise/google.php provides all the /after events where multiple examples shows how to call a TWIG file from the controller as well.
Don't know why your are posting such nonsens - maybe it's sunday and you have nothing to do?
That file is adding only a few data to the $data array, and then adding only simple javascript code to the template by replacing the body tag.
This has nothing to do with replacements inside a twig template when someone wants to add some new code fragments, remove or change.
And, no, it's not because it's sunday but because it's Sunday. People can still add new codes regardless if they want to replace or add new variables. The total and free e.gs are showing in there.$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_searchresults', $data);
// Insert the snippet after the output
$output = str_replace('</body>', $snippet . '</body>', $output);
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Seems nobody here is reading!xxvirusxx wrote: ↑Sun Jan 31, 2021 11:23 pmIf a file has more identical lines how you can search and replace only 1 line?OSWorX wrote: ↑Sat Jan 30, 2021 7:02 pmA simplewill do that (of course $search & $replace defined before).Code: Select all
$tpl = str_replace( $search, $replace, $tpl );
In ocmod is search index=x
OpenCart 4.x DOES NOT HAVE ANY OCMod further!
And we are talking here about the (new) possibilities you will have with the (new) Events system - while still possible also now in 3.x
Conclusion of this: whatever was possible until now with OCMod like file, operation, search, add IS NOT anymore.
The only left from former ocmods is the install.xml with the header lines only (code, name, author etc.) and the upload folder.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Here we have a chance for a clean reset with regards to an improved quality of future OC extensions, no more dirty OCMod XML scripts for modifying code or PHP templates! Though I am afraid people will find new ways of writing poor quality extensions, especially for web themes.OpenCart 4.x DOES NOT HAVE ANY OCMod further!
And we are talking here about the (new) possibilities you will have with the (new) Events system - while still possible also now in 3.x
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
I have read. That's why I asked.
For example in the model there are 3 lines identical.
line 1. <filter_id=2>
line 45. <filter_id=2>
line 67. <filter_id=2>
And using event I want to add some code after line 45.
How event know, in particular this command to add my code after line 45?
Code: Select all
$tpl = str_replace( $search, $replace, $tpl );
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Okay, what about we are talking here?xxvirusxx wrote: ↑Mon Feb 01, 2021 3:43 amFor example in the model there are 3 lines identical.
line 1. <filter_id=2>
line 45. <filter_id=2>
line 67. <filter_id=2>
And using event I want to add some code after line 45.
How event know, in particular this command to add my code after line 45?in this case $search will not search all <filter_id=2> ? then my code will by added after/before all lines?Code: Select all
$tpl = str_replace( $search, $replace, $tpl );
You are mentioning a "model" ..
One is the controller in which the event function is stored - and called later see below).
The event itself can be triggered by several points (= events):
1. controller
2. model
3. template
1. & 2. have only the route (= string) and the data (= array) as arguments.
3. has also the parsed template - called here $output or whatever else (= string).
Cases 1. & 2 can be called by before and/or after, means before = raw, after = manipulated.
Case 3 only with after (because with before we have no template).
Which means - and that about this discussion here started - whenever you want to "manipulate" the raw template code, you have to get it currently with a custom function.
As JNeuhoff decribed and what he wanted to have in the core code with his pull request (see GitHub).
When you fetched the template code, you can edit any code and any line(s).
Just to mention finally: when the event is called, he could also return a complete new template, not only manipulating the $route, $data and $output by reference.
And any controller and model can be called inside this events - exisiting and new (custom).
p.s.: should I am wrong in one point, please post it .. thx.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Seriously, that only takes a few seconds to find an answer via a Google search.And using event I want to add some code after line 45.
How event know, in particular this command to add my code after line 45?
E.g. using the search term 'php string replace nth occurrence' comes up with these hits:
https://stackoverflow.com/questions/199 ... n-a-string
https://gist.github.com/VijayaSankarN/0 ... 7d276b72bd
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Tks for explanations
@JNeuhoff
I didn't think last night
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Code: Select all
public function install()
{
$this->model_setting_event->addEvent(
'module_dflighteventmanager_changetwig',
'catalog/view/theme/default/template/common/success/before',
'extension/module/dflighteventmanager/modify_twig'
);
}
wherease, following some examples in the thread, here is the code which should be fired by the event (in catalog/controller/extension/module/dflighteventmanager.php):
public function modify_twig(&$route, &$data) {
// $this->session_start('24e32bdb7a143d1c302882f519');
$this->log->debug("NEW ORDER EVENT MANAGER TRIGGERED! - SUCCESS");
$this->log->debug('route: '. json_encode($route));
$this->log->debug('data: ' . json_encode($data));
$route = str_replace('common/success', 'extension/module/dflighteventmanager', $route);
} // end function
But the trigger doesn't seem to be fired. What I'm doing wrong :-?
Thanks for help :-)
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Code: Select all
public function modify_twig(&$route, &$data, &$output) {
Code: Select all
$output = $this->load->view('YOUR_TEMPLATE_HERE', $data);
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
That path in the installer is also wrong. Please refer to the install/opencart.sql > oc_event table for more information.catalog/view/theme/default/template/common/success/before
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
The path itself would be correct - if not used for events.straightlight wrote: ↑Fri Mar 04, 2022 4:04 amThat path in the installer is also wrong. Please refer to the install/opencart.sql > oc_event table for more information.catalog/view/theme/default/template/common/success/before
Should be more like this:
Code: Select all
catalog/view/common/success/after
Using this, it will work with all templates.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
It's under the addEvent method in this context. Therefore, the user is not using the path correctly.OSWorX wrote: ↑Fri Mar 04, 2022 5:03 amThe path itself would be correct - if not used for events.straightlight wrote: ↑Fri Mar 04, 2022 4:04 amThat path in the installer is also wrong. Please refer to the install/opencart.sql > oc_event table for more information.catalog/view/theme/default/template/common/success/before
Should be more like this:or /before when he really wants that ..Code: Select all
catalog/view/common/success/after
Using this, it will work with all templates.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Yes, with this representation, that would be correct.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 23 guests