Category Archives: functions

tips on how to change, improve how osCommerce-based cart functions

change number of records shown in admin

Problem: the number of orders displayed by default is a mere 20. You have to use a dropdown to see results 21-40.

Go to Admin > Configuration > Maximum Values and change the Search Results figure to something more useful, as shown in the screen below:

screenshot of cre loaded admin, configuration, max values, search results

The Search Results setting controls the number of results displayed on each page in several different areas of the Admin, including Countries listed, Customer accounts shown, products on Specials … handy to know about this well-hidden setting!

better rounding of prices including tax

The rounding function produces rounding errors of 1c in some cases – sure, no big deal, but why not get it right eh?

So after checking osCommerce I found a better rounding formula that might work for you too (esp on taxable products):

File : includes/functions/general.php

////
// Wrapper function for round()
  function tep_round($number, $precision) {
    if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
      $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);

      if (substr($number, -1) >= 5) {
        if ($precision > 1) {
          $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
        } elseif ($precision == 1) {
          $number = substr($number, 0, -1) + 0.1;
        } else {
          $number = substr($number, 0, -1) + 1;
        }
      } else {
        $number = substr($number, 0, -1);
      }
    }

    return $number;
  }

Replace with:

function tep_round($number, $round=2) {
   
   $tempd = $number*pow(10,$round);
   $tempd1 = round($tempd);
   $number = $tempd1/pow(10,$round);
   return $number;
}

change the length of the product name in Admin

Problem: product names can be up to 128 characters in length in the database (products_description table: products_name)

However the default limit on the number of characters displayed in the Categories & Products area in the Admin is only 64. If you have product titles that are longer than this, you need to change this default.

File: admin/categories.php

Line 1880
<td class="main"><?php echo tep_draw_input_field('products_name
[' . $languages[$i]['id'] . ']', $products_name_field, 'size="64"
maxlength="XXX"'); ?></td>

Change the ‘xxx’ value to any number of characters up to 129.

sort new products by date added

Problem: New Products are sorting alphabetically instead of by date added. How do you list by date added without affecting category product listing sort settings?

File: catalog/products_new.php

Line 103 
$sort_column = 'PRODUCT_LIST_NAME';

Replace with
$sort_column = 'LAST ADDED';

Line 110
$sort_order = 'a';

Replace with
$sort_order = 'd';

Line 136
case 'PRODUCT_LIST_PRICE':
      $listing_sql .= " order by final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
      break;
  }

After, add this
case 'LAST ADDED':
      $listing_sql .= " order by p.products_date_added " . ($sort_order == 'd' ? 'desc' : '');
      break;
  }

The New Products page will now list the most recent products starting at the top of the page.