Jan 22

how to upgrade oscommerce-based scripts from php 5.2.x to php 5.3.x

More and more hosting companies are upgrading their servers to run php 5.3. For most carts, this will mean an error log file full of deprecated error messages – warnings that one day, the functions being used will be removed entirely and the script will break.

If you’re running an older version of your oscommerce-based cart software (eg Cre Loaded 6.4.1, Oscommerce 2.2 etc) you will find that your error log file will fill up with deprecated messages from a number of files still using old calls like ‘ereg’ and ‘ereg_replace.’

You could switch these error messages off if you can control the error_reporting configuration on the server you’re on, but there’s a chance that when php 5.4 is adopted by hosting companies (RC6 of this was released January 2012) many of these deprecated messages now will become broken scripts then.

Updating most of these old calls can be fairly easy – here is a reference table that will help:

ereg() = preg_match()
ereg_replace() = preg_replace()
eregi() = preg_match() with the ‘i’ modifier
eregi_replace() = preg_replace() with the ‘i’ modifier
split() = preg_split()
spliti() = preg_split() with the ‘i’ modifier

As an example – cre loaded 6.4.1a B2B file /includes/functions/general.php :

if (ereg('^[0-9]+$', $value)) {

would become

if (preg_match('/^[0-9]+$/', $value)) {

(note ereg becomes preg_match and the forward slashes (delimiters) are added in)

Other deprecated functions and directives are more involved and may in fact only be configurable by the hosting company if they don’t allow custom php.ini files. There are other examples in the code that can simply be removed to upgrade to php 5.3.x and will stop the deprecated message.

A popular old check in Cre Loaded is a 6.2 version check – this from /admin/includes/runtime/orders/RC_orders_boxesbottom.php:

if (defined('MODULE_ADDONS_RECOVERCARTS_STATUS') && MODULE_ADDONS_RECOVERCARTS_STATUS == 'True') {
  if (defined('PROJECT_VERSION') && ereg('6.2', PROJECT_VERSION)) {
    $rci = tep_admin_files_boxes(FILENAME_RECOVER_ABANDONED_CARTS, BOX_RECOVER_ABANDONED_CARTS, 'SSL','tdate=' . $tdate, '0');
  } else {
    $rci = tep_admin_files_boxes(FILENAME_RECOVER_ABANDONED_CARTS, BOX_RECOVER_ABANDONED_CARTS, 'SSL','tdate=' . $tdate, '2');
  }
}

In this case the ‘upgrade’ would be to remove the old version check (bypassing the need for the deprecated ereg check), so the file looks:

if (defined('MODULE_ADDONS_RECOVERCARTS_STATUS') && MODULE_ADDONS_RECOVERCARTS_STATUS == 'True') {
    $rci = tep_admin_files_boxes(FILENAME_RECOVER_ABANDONED_CARTS, BOX_RECOVER_ABANDONED_CARTS, 'SSL','tdate=' . $tdate, '2');
  }

Third-party modules may cause grief when your hosting company upgrades to php 5.3.
At the time of writing this, Magneticone’s modules that use Zend Optimizer for decoding will break as Zend hasn’t provided a backward compatible version of the ZO for scripts using php 5.2.x. Magneticone’s advice in this situation is to use the ioncube versions of the scripts only (as they haven’t upgraded their modules to use the standalone ZO php 5.3 version either.) Nuisance.

If you’re unsure about these changes, contact me for a quote to help you upgrade from php 5.2 to php 5.3

Jan 16

gift vouchers, how to setup, use and manage

Gift Vouchers

There are two types of gift vouchers (‘GVs’) in oscommerce-based carts:

  1. a printed voucher with a redemption code, value and message (physical)
  2. purchased online credit sent to someone’s email address (electronic)

You could have the first type printed up, sold through your online store as a regular product and mailed to the purchaser or recipient. This article is about the second type – the electronic gift voucher – which uses the store’s system to record credit.

Did you know ?

A little known FAQ script included with most installations can be found in the file gv_faq.php.

On www.yourwebsite.com the url address would be then: www.yourwebsite.com/gv_faq.php

Gift Vouchers Process (Buyer’s View)

  1. Purchase the GV product as you would any other product via checkout
  2. The value of the GV value is added to the Buyer’s Account as ‘credit’
  3. Buyer can send credit to a recipient’s email address, or use credit for themselves
  4. Recipient ticks checkbox in checkout to use GV balance – balances below the order value will require the Recipient to pay the balance using a different payment method
  5. Any unusued GV credit is recorded in the Recipient’s Account for later

Gift Vouchers Process (Admin’s View)

  1. GV is setup like any other product, except:
  • weight is usually zero
  • product_model must begin with the word GIFT
  1. Admin can collect purchases of GVs in a queue for checking before release to Buyer
  2. Admin needs to offer other payment methods for use with GVs below order total value
  3. The GV Order Total module should be enabled in Admin >> Modules >> Order Total

There are several considerations* for Admin in the GV system:

  • there is no way of telling Customer GV balances using the default reporting
  • if Release Queueing isn’t enabled in the Order Total module, the GV value will be credited immediately to the Buyer’s account
  • you’ll only be able to see purchased gvs through the order, as any non-queued gvs don’t go through the gv report.
  • there are issues using GVs and Paypal modules, in particular regarding $0.00 order balances and cancelling an order when on the Paypal site (GV value is still removed from Account)

*Not all of these considerations are found throughout all oscommerce-based carts. Zencart for example has a more reliable yet feature limited version of the system.

Aug 13

put lists in a dropdown in alphabetical order

Adding new infoboxes through the Admin of an oscommerce cart is laborious enough without having to hunt through an unsorted list of filenames in a dropdown. So this article’s short tip examples one of php’s really useful functions – sort().

This is an unsorted list of infobox files in a dropdown in a Cre Loaded Admin:
jumble1 put lists in a dropdown in alphabetical order

Same list now sorted alphabetically:
sorted1 put lists in a dropdown in alphabetical order

The basic code change required to an array:

 $dirs1[] = $file;
            $dirs_array1[] = array('id' => $file1,
                                   'text' => $file1);
          }
        }
        closedir($handle1);
      }

sort($dirs_array1);  // added to sort list alphabetically

Older posts «