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

From Zen Cart(tm) Wiki
Jump to: navigation, search
m (Reverted edits by Torke (Talk); changed back to last version by Allcanadiansearch.ca)
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 00:25, 5 December 2007