Programming in Zen Cart Way
Template programming
See Zen Cart Template Customization
Front side programming
Create a sidebox
A sidebox consists of these three files:
include/modles/sideboxes/YOUR_TEMPLATE/xxx.php
include/languages/english/extra_definitions/YOUR_TEMPLATE/xxx_defines.php
include/templates/YOUR_TEMPLATE/sideboxes/tpl_xxx.php
Html Form
<?php echo zen_draw_form('FORM_NAME', zen_href_link(FILENAME, '', 'SSL'), 'post', 'onsubmit="return check_form(FORM_NAME);"'); ?>
<?php echo zen_draw_hidden_field('action', 'process'); ?>
<fieldset>
<legend><?php echo ......; ?></legend>
<label class="inputLabel" for="field1"><?php echo ......; ?></label>
<?php echo zen_draw_input_field('field1', '', zen_set_field_length(TABLE_NAME, 'field1', '40') . ' id="company"'); ?>
<br class="clearBoth" />
<?php echo zen_draw_radio_field('field2', 'value1'); ?>
<label class="radioButtonLabel" for="field2-value1">
<?php echo zen_draw_radio_field('field2', 'value2'); ?>
<label class="radioButtonLabel" for="field2-value2">
<br class="clearBoth" />
<label for="field3"><?php echo ......; ?></label>
<?php echo zen_draw_textarea_field('field3', 30, 5, '', 'id="field3"'); ?>
<br class="clearBoth" />
</fieldset>
<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SUBMIT, BUTTON_SUBMIT_ALT); ?></div>
</form>
Query single data
$query = "SELECT * FROM " . TABLE_NAME . " WHERE ......";
$result = $db->Execute($query);
if ($result->RecordCount() > 0) {
echo $result->fields['field_name'];
}
Querying datas
$query = "SELECT * FROM " . TABLE_PRODUCTS . " WHERE ......";
$products = $db->Execute($query);
while (!$products->EOF) {
echo $products->fields['field1'];
$products->MoveNext();
}
General API
zen_href_link($page = ”, $parameters = ”, $connection = ‘NONSSL’)
The HTML href link wrapper.
zen_not_null($value)
Check if a value is empty or null.
zen_output_string($string)
Returns a string with conversions for security.
Database API
zen_get_file_directory($check_directory, $check_file)
Find template or default file.
zen_redirect($url)
Redirect to another page or site.
$_SESSION['cart']->get_products()
return details of all products in the cart.
shipping
quote($method = ”, $module = ”)
Return the shipping methods array:
array(3) {
["id"]=>
string()
["module"]=>
string()
["methods"]=>
array(1) {
[0]=>
array() {
["id"]=>
string()
["title"]=>
string()
["cost"]=>
string()
}
}
}
……
Admin side programming
Html Form
<?php echo zen_draw_form('PAGE', FILENAME_PAGE, 'action=update', 'post', 'onsubmit="return check_form(PAGE);"', true); ?>
<?php echo zen_hide_session_id(); ?>
......
<?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE); ?>
</form>