Kamod Engine

What is KaMod 

KaMod is a technology for Opencart 3/4-based stores to make modifications in php and twig files without changing their code. It is distributed as a part of free Ka Extensions library. This engine generates a cache (in the storage directory) basing on files placed in your extension directory. For Opencart 4 it is extension/<your extension>/kamod directory. That cache is activated at the very beginning of Opencart bootup and therefore the most of standard Opencart files can be adjusted with kamod.

Kamod differs from OCMod3/Events in principle but it is smoothly integrated to the existing Opencart environment therefore standard ocmod extensions are compatible with it. KaMod works fine with Opencart events system and with the official VQMod package. Probably it is not compatible with Override engine (and similar solutions heavily modifying Opencart ). But we did not have a chance to test it yet. Maybe we can make it work after investigation. Please contact us if you experience any issues with kamod changes.

All karapuz team modules for Opencart 4 are based on kamod. If you need to make chagnes to our modules we encourage you to build modifications with KaMod files, but it is not obligatary. VQMod changes will be applied to the code as usual.

Why we made KaMod

In general, it allows us to create robust modifications of existing functionality. Development of custom chagnes with kamod files is simple and natural. The size of Kamod changes to an original file does not matter for other modifications because their code is in a separate file.

Kamod can also patch files similar to vqmod/ocmod3 changes, but that functionality is very limited and we try to minimize its usage. Extensions made with Kamod technology in mind should be easily modified by other extensions without any direct code patches.

How it works under the hood

Kamod manager generates a cache for php files and twig files and uses that cache for autoloading modified classes. Twig cache is provided to its own loader (ChainLoader replaces the standard loader) with higher priority and therefore twig takes files from that cache when it finds them there. The cache is generated on module installation/uninstallation. But for developer purposes it is possible to force cache generation on each page load.

php files inherit each other with native php class support. In your module file you specify which class you would like to override and kamod manager builds the cache keeping this information in mind. 

twig files use extend/block methods to implement parent to child inheritance.

KaMod creates a new 'cache.kamod' directory inside the storage directory. Child classes of the same parent are stored in the same directory and they can be easily browsed to examine the code.

Can Kamod be used in your projects

Kamod is a new techonlogy. Some parts of it might change in the future. But the basis should work for a quite long. So if you like that technology you are free to use it in your projects. Especially we encourage you to make changes in our modules with kamod files because they can be maintained easily. In order to start using KaMod a customer will have to install 'Ka Extensions' library. Kamod is an essential part of that library and we do not have intention to split it in near future.

Unfortuantely there is no detailed documentation on Kamod yet. We will collect it here:

https://www.ka-station.com/tickets/kb/faq.php?cid=30

Powered By OpenCart
Ka-Station © 2022