How to (and NOT to) develop a Zen-Cart™ module.

Throughout my journey in this Zen-Cart development realm, I have come across modules with various qualities and capabilities. There are definitely some really powerful modules out there, and some others were craps.

In order to aid new module developers, in this article I will describe guidelines I followed to make agood Zen-Cart™ modules. It is not an official guidelines (well there is no official guidelines yet by the time I wrote this), but I believe by having these characteristics it would make it way easier for your users to use your modules.

1. Try your best not to touch the core files.

I used to not following this guideline with my early modules. That, until I upgraded my Zen-Cart™.

By upgrading your Zen-Cart, you are basically replacing all the core files, and some of them might have been edited prior to the upgraded version.

The problems may arise in this scenario are:

  1. Your edited core files are definitely going to be wiped out.
  2. If the module users just copy the core files again after they upgraded, they might lose the edited codes from the newer version, since your module core files came from the older version.
These are the best practices I always follow for my modules.
  1. A no-brainer: Always use Overrides whenever possible.
  2. Put your constants inside includes/languages/extra_definitions/
  3. If you need to use database or create your own page, add the information inside includes/extra_datafiles/
  4. If you ever need to change anything inside tpl_[page_name]_display.php files, add the changes to tpl_modules_[module_name].php and put an include function from these tpl_[page_name]_display.php files.
  5. If you need to use your own classes instead of the core classes, you can edit the order of classes to be loaded.
  6. If you need to add things to do before or after a certain action done, use Observer Classes.

2. If you really, really need to edit the core files, Let users know clearly which files you edited.

I followed this guideline by:

  1. Putting all version specific files - core files of specific Zen-Cart version in a separate folder: ex. v138_specific_files.
  2. On all modules I coded, whenever I edit a core file, I added comments before and after the lines I edited with this format: //[bof / eof] - [comment information] - [module name] - [creator name]. This way readers know exactly which to which line I added my code into. Ex. //bof - Setting up Sliderview - Sliderview Donation - Jaycode.

3. If you use a third party Javascript / CSS library, let users know.

By library I mean scripts that are not specific to a certain module. For example, I put my scriptaculous library inside a Scriptaculous_on_[page name] folder. Doing it this way could prevent that library from being loaded twice.

For example if I have two modules using Scriptaculous library, one module is active on main page, and the other one is active only on product_info page, it would be better to load the library globally and delete the library inside product_info page.

4. Always put an identification name in front of your global constants, variables, and functions, and html attributes.

By doing this, you saved your and other developer's constants, variables, or functions from being overwritten, making your users' site a better place for the modules she might install in the future.

Ex: ais_product_sizes.





Home
Home

Zen-Cart Mods
Zen-Cart Mods

My Services
My Services

About Me
About Me

Contact Me
Contact Me

Request Quote
Request Quote