Difference between revisions of "Developers - Porting modules from osC"

From Zen Cart(tm) Wiki
Jump to: navigation, search
m (Reverted edits by Allcanadiansearch.ca (Talk); changed back to last version by DrByte)
Line 1: Line 1:
 +
{{Template:menuBarDevelopers}}
 +
= Overview =
  
 +
Many contributions for osCommerce have been ported to Zen Cart™. There are a few general rules for converting osCommerce code to Zen Cart™ code.
 +
 +
 +
== tep_db_query and tep_db_fetch_array ==
 +
 +
Replace code like
 +
<pre>$my_var_query = tep_db_query("query stuff");
 +
$my_var = tep_db_fetch_array($my_var_query);</pre>
 +
 +
by
 +
 +
<pre>$my_var = $db->Execute("query stuff");</pre>
 +
 +
 +
== tep_db_query and tep_db_fetch_array in if==
 +
 +
Replace code like
 +
<pre>$my_var_query = tep_db_query("query stuff");
 +
if ($my_var = tep_db_fetch_array($my_var_query))  {</pre>
 +
 +
by
 +
 +
<pre>$my_var = $db->Execute("query stuff");
 +
if (!$my_var->EOF)  {</pre>
 +
 +
 +
== tep_db_query and tep_db_fetch_array in while ==
 +
 +
Replace code like
 +
<pre>$my_var_query = tep_db_query("query stuff");
 +
while ($my_var = tep_db_fetch_array($my_var_query)) {
 +
do_stuff;
 +
}</pre>
 +
 +
by
 +
 +
<pre>$my_var = $db->Execute("query stuff");
 +
while (!$my_var->EOF) {
 +
do_stuff;
 +
$my_var->MoveNext();
 +
}</pre>
 +
 +
 +
== Referencing query fields ==
 +
 +
In situations like the following:
 +
<pre>$my_var_query = tep_db_query("query stuff");
 +
$my_var = tep_db_fetch_array($my_var_query);
 +
$i = $my_var['db_key'];</pre>
 +
 +
replace the line
 +
<pre>$i = $my_var['db_key'];</pre>
 +
 +
by
 +
 +
<pre>$i = $my_var->fields['db_key'];</pre>
 +
 +
 +
== tep_db_num_rows ==
 +
 +
Replace code like
 +
<pre>tep_db_num_rows($my_var)</pre>
 +
 +
by
 +
 +
<pre>$my_var->RecordCount()</pre>
 +
 +
 +
== tep_db_insert_id ==
 +
 +
Replace code like
 +
<pre>tep_db_insert_id()</pre>
 +
 +
by
 +
 +
<pre>$db->Insert_ID()</pre>
 +
 +
 +
== Add global $db ==
 +
 +
Add <em style="font-family:Courier;font-style:normal;font-weight:600;">global $db;</em> to all functions that now reference <em style="font-family:Courier;font-style:normal;font-weight:600;">$db</em> as a result of these changes.
 +
 +
 +
== Remaining tep_ functions ==
 +
 +
Replace <em style="font-family:Courier;font-style:normal;font-weight:600;">tep_</em> prefix in remaining functions with <em style="font-family:Courier;font-style:normal;font-weight:600;">zen_</em>.
 +
 +
 +
== $osCsid ==
 +
 +
Replace references to
 +
<pre>$osCsid</pre>
 +
 +
by
 +
 +
<pre>zen_session_id()</pre>
 +
 +
 +
== Registered globals ==
 +
 +
Zen Cart&trade; does not use registered globals (there is no <em style="font-family:Courier;font-style:normal;font-weight:600;">zen_session_is_registered</em>, etc). Instead, Zen Cart uses the <em style="font-family:Courier;font-style:normal;font-weight:600;">$_SESSION</em> superglobal.
 +
 +
References to registered globals <em style="font-family:Courier;font-style:normal;font-weight:600;">$var</em> should be replaced by <em style="font-family:Courier;font-style:normal;font-weight:600;">$_SESSION['var']</em>.
 +
 +
 +
== $HTTP_x_VARS ==
 +
 +
Replace
 +
<pre>$HTTP_x_VARS</pre>
 +
 +
by
 +
<pre>$_x</pre>
 +
 +
For example: <em style="font-family:Courier;font-style:normal;font-weight:600;">$HTTP_POST_VARS</em> becomes <em style="font-family:Courier;font-style:normal;font-weight:600;">$_POST</em>.
 +
 +
Also, remove any <em style="font-family:Courier;font-style:normal;font-weight:600;">global $HTTP_x_VARS;</em> lines inside functions; the new versions are superglobals and do not need to be declared global.

Revision as of 01:48, 5 December 2007

Overview

Many contributions for osCommerce have been ported to Zen Cart™. There are a few general rules for converting osCommerce code to Zen Cart™ code.


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()


Registered globals

Zen Cart™ does not use registered globals (there is no zen_session_is_registered, etc). Instead, Zen Cart uses the $_SESSION superglobal.

References to registered globals $var should be replaced by $_SESSION['var'].


$HTTP_x_VARS

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.