Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Guide to Converting Addons from 2.2x to 2.3.x


kymation

Recommended Posts

Once you have the boxes converted (see Part 1), the next step is to convert any new pages in your 2.2x Addon to the new 2.3x style. You can skip this part if your new Addon doesn't add any new pages. For the rest of you, read on.

 

Before I start, there will be quite a bit of back-and-forth between old and new versions going on here. I suggest that you keep a clean copy of the Addon code that you downloaded to refer to as you work. If necessary, go download a new copy and extract the files.

 

It may also help to use your file comparison program in some of the steps. I use Meld. There are many equivalent programs available, and most of them are free. Learn to use one; it'll save you a lot of time and trouble in the future.

 

 

The major change in osCommerce pages from 2.2x to 2.3x is the replacement of the top and bottom parts of the page by catalog/includes/template_top.php and /template_bottom.php. That means that your 2.2x Addon has a lot of extra code that needs to be removed, and then a link to the new template files needs to be added.

 

Let's start with the top part. Here's the part of a typical file we need to find:

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONDITIONS));

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css">

</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->

 

<!-- body //-->

<table border="0" width="100%" cellspacing="3" cellpadding="3">

<tr>

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

</table></td>

<!-- body_text //-->

<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

Note the part in red that we are replacing. Yes, it ends in the middle of a line. Once you take that out, this is what we have left:

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONDITIONS));

?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

Now we need to add in the new template_top.php, so it looks like this:

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONDITIONS));

 

require(DIR_WS_INCLUDES . 'template_top.php');

 

?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

Note that the part that I've added here (shown in green) goes above the ?>. That's enough to convert most pages, but there could be one other thing that needs to be changed in a few cases. We'll come back to this later.

 

 

Now to replace the bottom part of the file with template_bottom.php:

 

</tr>

</table></td>

<!-- body_text_eof //-->

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- right_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>

<!-- right_navigation_eof //-->

</table></td>

</tr>

</table>

<!-- body_eof //-->

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<!-- footer_eof //-->

<br>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Again, the part you need to remove is the part in red. And again, the split is in the middle of a line. Replace that deleted code with the link to the template code like this:

 

</tr>

</table>

<?php

require(DIR_WS_INCLUDES . 'template_bottom.php');

require(DIR_WS_INCLUDES . 'application_bottom.php');

?>

You may notice that the original had this all on one line:

 

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

I've moved the PHP tags <?php and ?> onto their own lines for convenience. I could have left all of the code on one line, but this is easier to read.

 

Now you may have noticed that the remaining center part of your page starts with <table ... > and ends with </table>. This is normal for a classic osCommerce page. In a very few cases this may be <div> and </div>. If yours doesn't look like one or the other, you have probably made a mistake somewhere. Go back and look at the original file again and fix your new version if needed.

 

 

There is one more thing that might happen to complicate your conversion: Your original Addon code may have added something to the top of the page that's not in the 2.3.x code. This will usually be a bit of JavaScript, but it could also be a stylesheet or similar code. This is a bit unusual, but some pages do have this. The way to find out is to compare the code in the original Addon page to the example I posted above. The part that you want to look at is between the <head> and </head> tags. There are only 4 lines to look at. Do this line by line, while ignoring minor changes in individual lines. What you are looking for is a line that occurs in your Addon that does not match anything in the above code. This line (or several lines in some cases) will usually be just above the </head> tag.

 

Let's say you found this added line in your page:

 

<script type="text/javascript" src="foo/bar.js"></script>

You could just paste that line in your template_top.php in a similar location. That will work, but it adds the line to every page on your site when you only need it on one. This can slow down your pages, and may in some cases interfere with code on other pages. It's better to avoid this if possible.

 

Fortunately there's a better way to do this. Find this line in your newly converted page:

 

require(DIR_WS_INCLUDES . 'template_top.php');

and add the following just before that line:

 

$head_tag .= '<script type="text/javascript" src="foo/bar.js"></script>' . "\n";

$oscTemplate->addBlock( $head_tag, 'header_tags' );

Note that I pasted the code from the old page in between the single quotes in the new code above. That's very important. Don't mess up the single quotes and you'll be fine.

 

But wait, what happens if there are single quotes in the old code? That's rare, but if there are single quotes you have to escape them, like this: \' Just add that backslash in front of every single quote in the old code before you paste it into the new page. It's easier to see them that way.

 

Another possibility is that there may be multiple lines that you need to add. That's fine, just paste all of the lines between the single quotes like you did above. A multi-line addition might look like this:

 

$head_tag .= ' <script type="text/javascript">

$(function() {

$( "#accordion" ).accordion();

});' . "\n";

$oscTemplate->addBlock( $head_tag, 'header_tags' );

That's it for the head and foot. I'll cover Buttons in a future Tip.

 

Please keep any discussion here related to this Tip. I'm perfectly willing to answer questions if you're unclear about something I've said above, but I won't go off-topic.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

what i do when adding code in between the <head> </head> tags is to add it to template top.

but like this

 

<?php
if (basename($_SERVER['SCRIPT_FILENAME']) == FILENAME_PRODUCT_INFO) {
  ?> 
<script type="text/javascript" src="foo/bar.js"></script>
<?php
}
?>

 

and if multiple scripts are require, you just add it below or above the first

 

<?php
if (basename($_SERVER['SCRIPT_FILENAME']) == FILENAME_PRODUCT_INFO) {
  ?> 
<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
<?php
}
?>

for each different page you would need to change FILENAME_PRODUCT_INFO

which has the same effect as the way you said.

Phoenix support now at https://phoenixcart.org/forum/
App created for phoenix
TinyMCE editor for admin

 

Link to comment
Share on other sites

That method will also work, but it's a bit more complicated than the way I showed. I'm trying to keep this as simple as possible. Also, Harald said to do it this way. :-"

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

  • 2 months later...

Jim,

 

I get this: Fatal error: Call to a member function addBlock() on a non-object in /home/path/public_html/to/admin/affiliate_news.php on line 138 when I use this method:

$head_tag .= '<script language="javascript" src="includes/general.js"></script>' . "\n";
$oscTemplate->addBlock( $head_tag, 'header_tags' );
require(DIR_WS_INCLUDES . 'template_top.php');

 

Any idea what's wrong?

 

Mark.

All the Web's a stage.

Link to comment
Share on other sites

You should have this in includes/application_top.php (Lines 428-429 in a stock osC):

 

 require(DIR_WS_CLASSES . 'osc_template.php');
 $oscTemplate = new oscTemplate();

That is where the $oscTemplate class comes from. This is part of stock osCommerce 2.3.1, so you normally only get that error when trying to install a 2.3 module in a 2.2 store.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...