Page 1 of 2

I hate osCommerce

Posted: Tue Aug 01, 2006 1:13 pm
by Benjamin
I have never EVER seen code just quit working. No code changes, no server changes, nothing. Every damn insert_id is failing. I hate this store. I will no longer accept clients who use this store. I would really like to start swearing a lot right now.

Code: Select all

$sql_data_array = array('customers_firstname' => $firstname,
                              'customers_lastname' => $lastname,
                              'customers_email_address' => $email_address,
                              'customers_telephone' => $telephone,
                              'customers_fax' => $fax,
                              'customers_newsletter' => $newsletter,
                              'customers_password' => tep_encrypt_password($password));

      if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
      if (ACCOUNT_DOB == 'true') $sql_data_array['customers_dob'] = tep_date_raw($dob);

      tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);

      $customer_id = tep_db_insert_id(); //<-- is failing now, was working yesterday

      $sql_data_array = array('customers_id' => $customer_id,
                              'entry_firstname' => $firstname,
                              'entry_lastname' => $lastname,
                              'entry_street_address' => $street_address,
                              'entry_postcode' => $postcode,
                              'entry_city' => $city,
                              'entry_country_id' => $country);

      if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
      if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
      if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
      if (ACCOUNT_STATE == 'true') {
        if ($zone_id > 0) {
          $sql_data_array['entry_zone_id'] = $zone_id;
          $sql_data_array['entry_state'] = '';
        } else {
          $sql_data_array['entry_zone_id'] = '0';
          $sql_data_array['entry_state'] = $state;
        }
      }

      tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);

      $address_id = tep_db_insert_id(); //<-- is failing now, was working yesterday..

Code: Select all

<?php
/*
  $Id: database.php,v 1.1.1.1 2004/03/04 23:40:48 ccwjr Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
    global $$link;

    if (USE_PCONNECT == 'true') {
      $$link = mysql_pconnect($server, $username, $password);
    } else {
      $$link = mysql_connect($server, $username, $password);
    }

    if ($$link) mysql_select_db($database);

    return $$link;
  }

  function tep_db_close($link = 'db_link') {
    global $$link;

    return mysql_close($$link);
  }

  function tep_db_error($query, $errno, $error) {
    die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
  }

  function tep_db_query($query, $link = 'db_link') {
    global $$link;
    /////////////////////////////////////////////////////////////////////
    //echo '<div style="border-width: 1px; border-style: solid; border-color: #ff0000;">' . $query . '</div>';

    //if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
    //  error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    // }

    $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());

    //if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
    //   $result_error = mysql_error();
    //   error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    //}

    return $result;
  }

  function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
    reset($data);
    if ($action == 'insert') {
      $query = 'insert into ' . $table . ' (';
      while (list($columns, ) = each($data)) {
        $query .= $columns . ', ';
      }
      $query = substr($query, 0, -2) . ') values (';
      reset($data);
      while (list(, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= 'now(), ';
            break;
          case 'null':
            $query .= 'null, ';
            break;
          default:
            $query .= '\'' . tep_db_input($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ')';
    } elseif ($action == 'update') {
      $query = 'update ' . $table . ' set ';
      while (list($columns, $value) = each($data)) {
        switch ((string)$value) {
          case 'now()':
            $query .= $columns . ' = now(), ';
            break;
          case 'null':
            $query .= $columns .= ' = null, ';
            break;
          default:
            $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
            break;
        }
      }
      $query = substr($query, 0, -2) . ' where ' . $parameters;
    }

    return tep_db_query($query, $link);
  }

  function tep_db_fetch_array($db_query) {
    return mysql_fetch_array($db_query, MYSQL_ASSOC);
  }

  function tep_db_num_rows($db_query) {
    return mysql_num_rows($db_query);
  }

  function tep_db_data_seek($db_query, $row_number) {
    return mysql_data_seek($db_query, $row_number);
  }

  function tep_db_insert_id($link) {
    return mysql_insert_id($link);
  }

  function tep_db_free_result($db_query) {
    return mysql_free_result($db_query);
  }

  function tep_db_fetch_fields($db_query) {
    return mysql_fetch_field($db_query);
  }

  function tep_db_output($string) {
    return htmlspecialchars($string);
  }

  function tep_db_input($string) {
    return addslashes($string);
  }

  function tep_db_prepare_input($string) {
    if (is_string($string)) {
      return trim(tep_sanitize_string(stripslashes($string)));
    } elseif (is_array($string)) {
      reset($string);
      while (list($key, $value) = each($string)) {
        $string[$key] = tep_db_prepare_input($value);
      }
      return $string;
    } else {
      return $string;
    }
  }
?>

Posted: Tue Aug 01, 2006 1:24 pm
by Luke
os_commerce beats MIVA haha that's what we use. The only cool thing about MIVA is that if i learn MIVA script I'm somewhat irreplaceable here.

Posted: Tue Aug 01, 2006 2:57 pm
by RobertGonzalez
I say you rewrite their codebase and make it better. It sounds like it is riddled with issues.

Posted: Tue Aug 01, 2006 3:12 pm
by patrikG
Everah wrote:I say you rewrite their codebase and make it better. It sounds like it is riddled with issues.
Rewrite OsCommerce? And keeping anything remotely backward-compatible? No, Everah, that's not just a plumbing job, that's a highly complex operation. It's a bit like trying turn a VW Beetle into a Formula 1 racing car. With enough resources it could be achieved, but why? Rather write a shop that's better than OsCommerce (which is not that hard) and write an import-filter for OsCommerce data. That's cleaner all around.

Posted: Tue Aug 01, 2006 4:09 pm
by RobertGonzalez
OK, I'll go with that. I was kinda talking out of my rump when I said. Of course, given the nature of the problems astions is having with the app, I might be inclined to either reinstall it or use another app.

Posted: Tue Aug 01, 2006 4:14 pm
by Benjamin
I'm going to rewrite it. From the ground up. It might take me a year, but I am going to do it.

I'll make it OO too.

Posted: Tue Aug 01, 2006 4:16 pm
by Luke
Shopping carts are actually kind of fun. First thing I built was a shopping cart (procedural). I wouldn't mind building an oop shopping cart / merchant admin system. The part that sucked was reports and that kind of junk.

Posted: Tue Aug 01, 2006 4:20 pm
by RobertGonzalez
astions wrote:I'm going to rewrite it. From the ground up. It might take me a year, but I am going to do it.

I'll make it OO too.
Well maybe I wasn't talking out of my rump then, eh?

Posted: Tue Aug 01, 2006 4:20 pm
by Benjamin
You wanna help me?

Posted: Tue Aug 01, 2006 4:21 pm
by Luke
I'd be interested in helping... but I just don't know when I'd get the time.

Posted: Tue Aug 01, 2006 4:24 pm
by Benjamin
Ok, I'll set something up in the next few weeks or so on a server. Spare time project.

Posted: Tue Aug 01, 2006 4:24 pm
by Luke
Sounds cool... I'm developing a crap-load of classes right now... for just about anything, so maybe they would be of some use

Posted: Tue Aug 01, 2006 5:10 pm
by RobertGonzalez
If I can swing it you got it. I am behind in two client projects at the moment, as well as behind on one volunteer assigment and four personal projects. But if I can squeak anything in, I'll do what I can.

Posted: Tue Aug 01, 2006 5:31 pm
by jayshields
I've worked with much worse code. I redesigned/added features to a clients website which was from ecommercetemplates.com (although some files claimed to be copyrighted by Internet Business Solutions SL), and it was the worst ever. Every page on the website was a seperate file, using include() like some sort of chain, nothing was commented, and worst of all, when I just wanted to change simple words on the website, if it was echo'd in the code somewhere, you can stuff using find&replace in your editor, oh no, it wasn't that easy, everything was a variable (mostly ones which had no/little correlation to the word it represents in english) which lead to language files, which were included about 4 files deep.

I think the whole website consisted of around 200 php files (each of around 50kb), and the end product was far from impressive... I'm gunna find a snippet.

Code: Select all

<?php		}
		}
?>
			  <tr>
				<td width="25%" align="right"><strong><?php print $yyAddSec?>:</strong></td>
                <td colspan="4" align="left">
<?php		if(! $simpleSections){
				print '<select size="1" name="pNumSections" onChange="setprodsections();"><option value="0">' . $yyNone . '</option>';
				for($rowcounter=1;$rowcounter <= $maxprodsects; $rowcounter++)
					print "<option value='" . $rowcounter . "'>" . $rowcounter . "</option>";
				print "</select>";
			} ?>&nbsp;</td>
			  </tr>
<?php	if($simpleSections){
			for($index=0;$index < $maxprodsects; $index++){
				if(($index % 2)==0) print "<tr>";
				print '<td align="right">' . $yyPrdSec . ' ' . ($index+1) . ':</td><td><select size="1" id="pSection' . $index . '" name="pSection' . $index . '"><option value="0">' . $yyNone . '</option>';
				for($rowcounter=0;$rowcounter < $nallsections;$rowcounter++){
					print '<option value="' . $allsections[$rowcounter]["sectionID"] . '"';
					if($index < $nprodsections){
						if($prodsections[$index][0]==$allsections[$rowcounter]["sectionID"]) print " selected";
					}
					print ">" . $allsections[$rowcounter]["sectionWorkingName"] . "</option>";
				}
				print "</td>";
				if(($index % 2) != 0) print "</tr>\n";
			}
			if(($index % 2)==0)
				print "</tr>\n";
			else
				print "<td colspan=\"2\">&nbsp;</td></tr>\n";
		}else{ ?>
No templating, no proper indentation, no consistent spacing, no comments, breaks in and out of PHP every 10 lines, stupid SQL query implementation. That's just 30/1500 lines in that file.

I had to practically redo most of the website just to break the HTML from the PHP so I could get my head around it.

Posted: Tue Aug 01, 2006 5:36 pm
by Luke
that sucks