Developers - Porting modules from osC
Overview
Many contributions for osCommerce have been ported to Zen Cart™. There are a few general rules for converting osCommerce code to Zen Cart™ v1.2.x or v1.3.x code. If you are attempting to convert to v1.5.x code, you will need to follow the additional instructions for converting addons to the v1.5 format. Writing for v2.x.x requires a complete rewrite of the addon using the much simpler new OOP architecture in the v2 framework.
tep_db_query and tep_db_fetch_array
Replace code like
$my_var_query = tep_db_query("query stuff");
$my_var = tep_db_fetch_array($my_var_query);
by
$my_var = $db->Execute("query stuff");
tep_db_query and tep_db_fetch_array in if
Replace code like
$my_var_query = tep_db_query("query stuff");
if ($my_var = tep_db_fetch_array($my_var_query)) {
by
$my_var = $db->Execute("query stuff");
if (!$my_var->EOF) {
tep_db_query and tep_db_fetch_array in while
Replace code like
$my_var_query = tep_db_query("query stuff");
while ($my_var = tep_db_fetch_array($my_var_query)) {
do_stuff;
}
by
$my_var = $db->Execute("query stuff");
while (!$my_var->EOF) {
do_stuff;
$my_var->MoveNext();
}
Referencing query fields
In situations like the following:
$my_var_query = tep_db_query("query stuff");
$my_var = tep_db_fetch_array($my_var_query);
$i = $my_var['db_key'];
replace the line
$i = $my_var['db_key'];
by
$i = $my_var->fields['db_key'];
tep_db_num_rows
Replace code like
tep_db_num_rows($my_var)
by
$my_var->RecordCount()
tep_db_insert_id
Replace code like
tep_db_insert_id()
by
$db->Insert_ID()
Add global $db
Add global $db; to all functions that now reference $db as a result of these changes.
Remaining tep_ functions
Replace tep_ prefix in remaining functions with zen_.
$osCsid
Replace references to
$osCsid
by
zen_session_id()
session_register
The use of tep_session_register() function calls is entirely deprecated. PHP 5.3 and 5.4 no longer support session_register() and session_unregister() and session_is_registered() function calls, and will trigger fatal errors if used.
Zen Cart™ does not use registered globals (there is no zen_session_is_registered, etc). Instead, Zen Cart uses the $_SESSION superglobal.
Registered globals
References to registered globals $var should be replaced by $_SESSION['var'].
$HTTP_x_VARS
These variables are a result of the deprecated register_long_arrays setting in VERY old versions of PHP. As of PHP 5.3 they are deprecated, and as of PHP 5.4 they will trigger a fatal error. Thus they must be converted. A simple search-and-replace is usually sufficient.
Replace
$HTTP_x_VARS
by
$_x
For example: $HTTP_POST_VARS becomes $_POST.
Also, remove any global $HTTP_x_VARS; lines inside functions; the new versions are superglobals and do not need to be declared global.
Article with references to PHP 5.4 deprecation: http://mcglockenshire.com/blog/posts/waiting-for-php-5-4-death-to-prehistoric-cruft.html