Yes and please don't use caps when posting.madimar wrote: ↑Tue Dec 22, 2020 2:04 amDO YOU MEAN OCMOD ?!?straightlight wrote: ↑Mon Dec 21, 2020 8:40 amDirectly into the install.xml file to search for lines and alter them.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Well, thanks for your confirmation. Regarding the caps it was just a few words and in this specific case they were used intentionally to shout my wonder!straightlight wrote: ↑Tue Dec 22, 2020 2:15 amYes and please don't use caps when posting.madimar wrote: ↑Tue Dec 22, 2020 2:04 amDO YOU MEAN OCMOD ?!?straightlight wrote: ↑Mon Dec 21, 2020 8:40 amDirectly into the install.xml file to search for lines and alter them.
So besides that, the point is, removing any ocmod/vqmod support in next releases, it will be necessary and accepted to have some extra queries in order to work with events. It can be ok, just to know.
Said that, in general, about extending Opencart by events, I still think it will be quite a mess to troubleshoot any possible problem/conflict, due to code fragmentation in several files. Is my concern correct according to your opinion?
Regards and thanks for your participation to this topic.
M
-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------
1. https://github.com/opencart/opencart/wi ... ion-System
Read there:
2. Ongoing discussion (closed by Daniel)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.
https://github.com/opencart/opencart/issues/8992
3. Based on 1. & 2.
OC 3.1.1.0 will be OC 4.x (nearly, OC 4.x replace 3.1.x)
From OC 4.x on, wether OC- nor VQMods are possible anymore, Events shall be handle everything in future.
The file modification.php is removed, which means: no replacements as we know them from OC- or VQMods are possible.
Looking at all of that, it makes me wonder why a replacement via the install.xml (which still exists and is used further) is recommended, because it won't work anymore.
While I am sure that some "clever codie boy" will introduce something and create a "modification" as already exists to eleminate the directory limit introduced with OC 3.x
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
I think all the install.xml will do is to describe the extension, e.g. name, version, author, and link. No more core file modifications.Looking at all of that, it makes me wonder why a replacement via the install.xml (which still exists and is used further) is recommended, because it won't work anymore.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Which is why you were being asked why not to use the caps still.Well, thanks for your confirmation. Regarding the caps it was just a few words and in this specific case they were used intentionally to shout my wonder!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Correct, see: https://github.com/opencart/opencart/bl ... r.php#L217
Those infos are needed and stored:
Code: Select all
'extension_id' => 0,
'extension_download_id' => 0,
'name' => $name,
'code' => basename($filename, '.ocmod.zip'),
'version' => $version,
'author' => $author,
'link' => $link
Unfortunetaly no version check is made.
Beside the already known install.xml, there is the folder upload [optional] which can contain several subfolders like system, admin, etc.
See: https://github.com/opencart/opencart/bl ... r.php#L289
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
I do not understand something... @Straightlight always talking to use events everywhere and what is it? OCMOD again? And OCMOD has been removed from OC4.x.x.x... Can anybody explain. I'm confusedmadimar wrote: ↑Tue Dec 22, 2020 2:04 amDO YOU MEAN OCMOD ?!?straightlight wrote: ↑Mon Dec 21, 2020 8:40 amDirectly into the install.xml file to search for lines and alter them.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here
Removed, niente, nothing, nichts, rien ne va plus ..OCMod (therefore also the function modification(..) as sometimes used since OC 2.x) is OBSOLETE!
From the new Version on - 4.x (3.1.x was planned, but too many changes, therefore 4.0.x) - only events are allowed and possible.
Daniel has screwed that up to replace to old "modification" system with OCMod (and VQMod should be also not be allowed anymore).
But what is true is, that to upload new Extensions, you will use furthermore the well know package.
Including:
a. install.xml
b. upload folder
Infos inside the .xml are used only to store the infos (see the header inside) in the database (currently install.xml is not needed, only the upload folder - maybe Daniel will change that).
The tags as we know, file, path, etc. are not used anymore.
Extension package files will have the same convention as now:
my-extension-v.1.0.0-OC-4.0.1.ocmod.zip
Unfortunetaly I suggested to use another extension (not ocmod furthermore), but Daniel declined.
That's all.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Simple. That's because an Event is not OCMod whereas Events is rather an Engine handled by the core.I do not understand something... @Straightlight always talking to use events everywhere and what is it? OCMOD again? And OCMOD has been removed from OC4.x.x.x... Can anybody explain. I'm confused
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
One more: while you are a "developer", all Informations about what is an "Event" and why it is not a "OCMod" and why Events are used in future only and not OCMods (or other derivats), can be read in many postings here in this Forum and in the current code at GitHub - read there also the pull requests and discussions.kestas wrote: ↑Sat Jan 30, 2021 9:35 pmI do not understand something... @Straightlight always talking to use events everywhere and what is it? OCMOD again? And OCMOD has been removed from OC4.x.x.x... Can anybody explain. I'm confusedmadimar wrote: ↑Tue Dec 22, 2020 2:04 amDO YOU MEAN OCMOD ?!?straightlight wrote: ↑Mon Dec 21, 2020 8:40 amDirectly into the install.xml file to search for lines and alter them.![]()
As already written, it will confuse many people in future, because the extension package names are only accepted by the system (to install), when they are named xyz.ocmod.zip
From OpenCart 4.0.x on, the already known OCMod is dead.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
I came up with a simpler solution (I think) than what's been posted here. It works in the same principal as some of the other posts online but it has the nice added bonus that the only thing you need to worry about is finding the html line of what you want to either find / replace ($find var below).
For this we need to create a module / modification .twig file for whatever we are injecting into the target .twig file.
For example, for simplicity sake, if you want to add..
Code: Select all
{% if exel %}
<div class="test">{{ exel }}</div>
{% else %}
<div class="test">No</div>
{% endif %}
I've seen some people do this inline with the template buffer posted in the OP but we can take advantage of the already included $this->load->view().
This way it's a lot cleaner to read and maintain.
We also need to pass whatever variables are needed to this .twig file.
In this instance, I am targeting: admin/view/catalog/product_form/after
My function looks something like this:
Code: Select all
public function injectView(&$route, &$data, &$output) {
$module_twig = $this->load->view('extension/crafted/shipping/craftedanomalies', $data);
$find = '<legend>Specification</legend>';
$replace = '<legend>Specification</legend>' . $module_twig;
$output = str_replace($find, $replace, $output);
}
Where:
$module_twig = This is loading the .twig file / content you want to inject, merging the php / html / twig content and passing the $data to it.
extension/crafted/shipping/craftedanomalies = directory to the .twig file / content you want to inject
$find = The fully converted html string that you want your content to either replace, append to, etc. In my instance, You can see I just appended my .twig to this as it lined up perfectly to where I wanted it.
$replace = This is where you'll either replace or append data.
$output = We are using the /after event $output to push the data.
The nice added bonus of this is you can use the exact same $find for multiple modifications, etc and they will all output from different event calls.
What you describe here, is the usual way to "manipulate/edit" existing HTML output (stored in the $output variable).Exel wrote: ↑Sat Feb 13, 2021 5:30 pmI've been looking into code injection into the template files and came across this thread. Lots of good ideas and talk here.
I came up with a simpler solution (I think) than what's been posted here. It works in the same principal as some of the other posts online but it has the nice added bonus that the only thing you need to worry about is finding the html line of what you want to either find / replace ($find var below).
This can be only achived, when after is used to call the function (only then you will get the parsed HTML code).
But when before is used, the $output variable does not exist, so when this method is used (and has some valid reasons to do so), the template must be fetched before.
This is what JNeuhoff tries to explain ..
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Correct .. but who is reading it?straightlight wrote: ↑Fri Mar 04, 2022 1:04 amThe /before and /after triggers are already explained on the Wiki documentation on anyhow.
And (btw.), this "Wiki" must be found to be able to read it.
And "error free" is something else, also wether complete nor easy to understand sometimes ..
Just for those, who want to read more: https://github.com/opencart/opencart/wiki/Events-System
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Simple, it's to those who can. That's what true developers are about.OSWorX wrote: ↑Fri Mar 04, 2022 1:33 amCorrect .. but who is reading it?straightlight wrote: ↑Fri Mar 04, 2022 1:04 amThe /before and /after triggers are already explained on the Wiki documentation on anyhow.
And (btw.), this "Wiki" must be found to be able to read it.
And "error free" is something else, also wether complete nor easy to understand sometimes ..
Just for those, who want to read more: https://github.com/opencart/opencart/wiki/Events-System
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Yes (who can read), but don't forget, this here aims to be a user forum, not a developers discussion board (that's what GH is for).straightlight wrote: ↑Fri Mar 04, 2022 3:31 amSimple, it's to those who can. That's what true developers are about.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Sadly, the only official documentation available from Opencart to show in details how Events works is on Github. In addition, there are also available free extensions on the Marketplace where extension developers were also able to achieve this, including one of my extensions that does show how to use Events on the same location. At this point, reading becomes secondary.OSWorX wrote: ↑Fri Mar 04, 2022 4:55 amYes (who can read), but don't forget, this here aims to be a user forum, not a developers discussion board (that's what GH is for).straightlight wrote: ↑Fri Mar 04, 2022 3:31 amSimple, it's to those who can. That's what true developers are about.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
thank you for the code..JNeuhoff wrote: ↑Fri Dec 11, 2020 8:55 pmIt can be done with a before-event handler, though it's a bit convoluted:
The basic idea is to use a simple str_replace call in the event handler.Code: Select all
// event handler for admin/view/catalog/product_form/before public function eventViewCatalogProductFormBefore( &$route, &$data, &$template_code=null ) { $template_buffer = $this->getTemplateBuffer( $route, $template_code ); $search = '{% if customer_group.customer_group_id == product_special.customer_group_id %}'; $replace = '{% if customer_group.customer_group_id == product_special.customer_group_id and some_new_variable_equal_true %}'; $template_buffer = str_replace( $search, $replace, $template_buffer ); $template_code = $template_buffer; return null; } // return template file contents as a string protected function getTemplateBuffer( $route, $event_template_buffer ) { // if there already is a modified template from view/*/before events use that one if ($event_template_buffer) { return $event_template_buffer; } // load the template file (possibly modified by ocmod and vqmod) into a string buffer if ($this->isAdmin()) { $dir_template = DIR_TEMPLATE; } else { if ($this->config->get('config_theme') == 'default') { $theme = $this->config->get('theme_default_directory'); } else { $theme = $this->config->get('config_theme'); } $dir_template = DIR_TEMPLATE . $theme . '/template/'; } $template_file = $dir_template . $route . '.twig'; if (file_exists( $template_file ) && is_file( $template_file )) { $template_file = $this->modCheck( $template_file ); return file_get_contents( $template_file ); } if ($this->isAdmin()) { trigger_error("Cannot find template file for route '$route'"); exit; } $dir_template = DIR_TEMPLATE . 'default/template/'; $template_file = $dir_template . $route . '.twig'; if (file_exists( $template_file ) && is_file( $template_file )) { $template_file = $this->modCheck( $template_file ); return file_get_contents( $template_file ); } trigger_error("Cannot find template file for route '$route'"); exit; } protected function isAdmin() { return defined( 'DIR_CATALOG' ) ? true : false; } protected function modCheck( $file ) { // return a PHP file possibly modified by OpenCart's system/storage/modification, // and then possibly modified by vqmod (see also https://github.com/vqmod/vqmod) // Use OpenCart's modified file is available $original_file = $file; if (defined('DIR_MODIFICATION')) { if ($this->startsWith($file,DIR_APPLICATION)) { if ($this->isAdmin()) { if (file_exists( DIR_MODIFICATION . 'admin/' . substr($file,strlen(DIR_APPLICATION)) )) { $file = DIR_MODIFICATION . 'admin/' . substr($file,strlen(DIR_APPLICATION)); } } else { if (file_exists( DIR_MODIFICATION . 'catalog/' . substr($file,strlen(DIR_APPLICATION)) )) { $file = DIR_MODIFICATION . 'catalog/' . substr($file,strlen(DIR_APPLICATION)); } } } else if ($this->startsWith($file,DIR_SYSTEM)) { if (file_exists( DIR_MODIFICATION . 'system/' . substr($file,strlen(DIR_SYSTEM)) )) { $file = DIR_MODIFICATION . 'system/' . substr($file,strlen(DIR_SYSTEM)); } } } // Don't use VQmod 2.3.2 or earlier if available if (array_key_exists('vqmod', get_defined_vars())) { trigger_error( "You are using an old VQMod version '2.3.2' or earlier, please upgrade your VQMod!" ); exit; } // Use modification through VQmod 2.4.0 or later if available if (class_exists('VQMod',false)) { if (VQMod::$directorySeparator) { if (strpos($file,'vq2-')!==FALSE) { return $file; } if (version_compare(VQMod::$_vqversion,'2.5.0','<')) { trigger_error( "You are using an old VQMod version '".VQMod::$_vqversion."', please upgrade your VQMod!" ); exit; } if ($original_file != $file) { return VQMod::modCheck($file,$original_file); } return VQMod::modCheck($original_file); } } // no VQmod return $file; } protected function startsWith( $haystack, $needle ) { if (strlen( $haystack ) < strlen( $needle )) { return false; } return (substr( $haystack, 0, strlen($needle) ) == $needle); }
I have tried, it's working but I need it to work with opencart extention folder
Please, have any idea for opencart version 4.x ??
Code: Select all
// event handler for admin/view/catalog/product_form/before
public function eventViewCatalogProductFormBefore( string &$route, array &$data, string &$template_code ): void {
// ....
$code = $this->getTemplateCode($route,$code);
// .... modify $code
$template_code = $code;
}
protected function getTemplateCode( $route, &$code ) {
if (!empty($code)) {
return $code;
}
$file = DIR_TEMPLATE . $route . '.twig';
if (is_file($file)) {
$code = file_get_contents( $file );
} else {
trigger_error("Cannot find template file for route '$route'");
exit;
}
return $code;
}
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Users browsing this forum: No registered users and 1 guest