1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Wednesday, December 2, 2009

The Zen Cart Execution Process

The Zen Cart Execution Process

Zen Cart, like most open-source code, is a largly undocumented. Luckily for us, it also has a habit of mixing in much of it's program/application logic with it's actual HTML design, so it's not only undocumented, it's also hard to browse the HTML code. To top it off, it also has a dynamic template loader, which means that the program logic and HTML templates could be in any one of four different directories. Also undocumented, and of dubious usefullness.

The result is that it's not only difficult to browse through the program logic and HTML code, but you often don't even know which files are going to get loaded.

This document is an attempt to sort through the overarching structure of how Zen Cart tends to work.

index.php steps:

Here's where all of action begins.
  1. it loads 'includes/application_top.php'
  2. if $main_page isn't set, it gets set to 'index'
  3. if the directory 'includes/modules/pages/$main_page' doesn't exist, $main_page gets set to 'index'
  4. it loads all of the files starting with 'header_php' in 'includes/modules/pages/$main_page'
  5. now it loads 'html_header.php' from the first first place it finds it from the following directories
    1. includes/templates/mytemplate/$main_page/
    2. includes/templates/template_default/$main_page/
    3. includes/templates/mytemplate/common/
    4. includes/templates/template_default/common/
  6. now it does the same thing for finding and loading 'main_template_vars.php'
  7. now it does the same thing for finding and loading 'tpl_main_page.php'
  8. Finally it displays the '</html>' tag. Why display it here when the '<html>' tag is displayed somewhere else? Who knows.

application_top.php steps:

This file will load in all of general definitions used site-wide, initialize some site-wide classes ($template, $db) and do other general stuff.

html_header.php steps:

The default html_header.php file will simply create all of the HTML up to the </head> tag It loads 'includes/modules/meta_tags.php', which uses a bloated switch statement to figure out what the site's title, meta-keywords, and meta-description should be. It tries to find the css directory, and loads in it all stylesheets that begin with 'style' and end with '.css' It does the same thing for the jscript directory, and tries to load all files that begin with 'jscript_' and end with '.js'

main_template_vars.php steps:

it simply sets $body_code to the first of:
  1. includes/modules/pages/$main_page/main_template_vars.php
  2. includes/templates/mytemplate/$main_page/tpl_{$main_page}_default.php
  3. includes/templates/template_default/$main_page/tpl_{$main_page}_default.php
  4. includes/templates/mytemplate/templates/tpl_{$main_page}_default.php
  5. includes/templates/template_default/templates/tpl_{$main_page}_default.php
that's it.

tpl_main_page.php steps:

this file lays out the basic page.
  1. <body>
  2. loads the 'includes/modules/header.php' file
  3. if the left column is enabled, it loads 'includes/modules/column_left.php'
  4. it loads the file set in $body_code
  5. if the right column is enabled, it loads 'includes/modules/column_right.php'
  6. loads 'includes/modules/footer.php'
  7. </body>

includes/modules/pages/$main_page/main_template_vars.php steps:

this is where the meat of the actual content if loaded and displayed. it typically does all of the program logic first, sets all of the necessary variables, and then loads the template file. As usual, the template file is loaded from the first of the following:
  1. includes/templates/mytemplate/$main_page/
  2. includes/templates/template_default/$main_page/
  3. includes/templates/mytemplate/templates/
  4. includes/templates/template_default/templates/
The standard is that the template file will be named 'tpl_SOMENAME.php'. Note that it doesn't end with '_default.php'. The undocumented naming convention is that files that end with '_default.php' are files that get loaded with it can't find the 'includes/modules/pages/$main_page/main_template_vars.php' file.

tpl_{$main_page}_default.php steps:

If it doesn't find the above file and it instead finds a tpl_*_default.php file, then it means that all of the program logic and variables will be mixed up with the actual displayed HTML code. In Zen-Cart's defense, this generally means that there's not a lot of program logic to be had here, hardly any really, but it's still damn annoying to be mixing the program logic with design. No sir, I don't like it one bit.

Future Updates

Eventually this document will also cover the process by which the program loads in the language files, such as "english.php" and the content files like "privacy.php" and "conditions.php." The Zen Cart creators actually created these files with the idea that they would be a part of your custom template, which is a clear violation of the content/design seperation.

This document will also cover sideboxes (which requires a whole nother custom template directory). As an interesting sidenote, when you switch to a new template, all of the sideboxes get turned off. The level of user-unfriendliness of Zen Cart is amazing to me sometimes.

Zen Cart Database Schema

Developers - Database Schema - Zen Cart(tm) Wiki

address_book
address_format
admin
admin_activity_log
authorizenet
banners
banners_history
categories
categories_description
configuration *
configuration_group
counter
counter_history *
countries
coupons
coupons_description
coupon_email_track
coupon_gv_customer
coupon_gv_queue
coupon_redeem_track
coupon_restrict
currencies
customers
customers_basket
customers_basket_attributes
customers_info
customers_wishlist
db_cache
email_archive
ezpages
featured
files_uploaded
geo_zones
get_terms_to_filter
group_pricing
languages
layout_boxes
manufacturers
manufacturers_info
media_clips
media_manager
media_to_products
media_types
meta_tags_categories_description
meta_tags_products_description
music_genre
newsletters
orders *
orders_products *
orders_products_attributes *
orders_products_download *
orders_status
orders_status_history
orders_total *
paypal *
paypal_payment_status
paypal_payment_status_history *
paypal_session *
paypal_testing *
products *
products_attributes *
products_attributes_download *
products_description *
products_discount_quantity *
products_notifications
products_options *
products_options_types
products_options_values *
products_options_values_to_products_options *
products_to_categories *
product_music_extra *
product_types *
product_types_to_category *
product_type_layout *
project_version
project_version_history
query_builder *
record_artists *
record_artists_info *
record_company *
record_company_info *
reviews *
reviews_description *
salemaker_sales *
sessions *
specials *
tax_class *
tax_rates *
template_select *
upgrade_exceptions *
whos_online *
zones *
zones_to_geo_zones *

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...