Sunday, July 5, 2009

Convert a non-BTS contribution to BTS

Overview
Oscmax uses the BTS system, which is a real time-saver for those who understand it (the idea of BTS is to separate the PHP processing code from the front-end HTML, and allow the designer to quickly setup a uniform "frame" for the whole site with the main_page.tpl.php file). But since Oscommerce does not use this system, one major flaw is that many - perhaps most - developers are unfamiliar with it, and contributions are made with the usual format in mind. This tutorial will provide a general overview on how to get such contributions to work with Oscmax. I'll be using the Recently Viewed (Sales Optimized) contribution as my example.

How to implement
1) Create a new PHP file and name it the same as the original file, except with the extension tpl.php. For example, my original file was recently_viewed.php, so the new one is recently_viewed.tpl.php. If using Dreamweaver, enter the code view and delete everything you see.
NOTE: do not simply rename your old file - this new file does not replace it! In the end you will be using both on your site.

2) Open the original file and find in the code the beginning of the HTML page - "!doctype html public" etc.

3) Next, delete everything from the beginning of the HTML, the entire <'head'> tag, until and including the opening <'body'> tag. In BTS, this part is already provided for by the main_page.tpl.php file, so you don't need it here again.
NOTE: in the recently viewed contribution, there isn't anything new in this part of the code. However, in other contributions there may be references in the tag to script files or stylesheets. In that case you need to copy these references to the <'head'> section of the main_page.tpl.php file. Do not discard these references or your code will not work!

4) If there is a reference to "header.php" delete that too. This is also part of main_page.

5) Now go to the end of your new document. Starting from "require" reference to "footer.php", delete everything - through and including the closing < / body > and < / html > tags and the end of the document. If there is no reference to the footer just delete everything below and including the closing HTML tags.

6) Go to the beginning of the code - there should be a line that references "application_top.php" and immediately under it a "require" command for the corresponding language file. Select all the code that remains except these two lines - they should stay in the original file. Cut it, and paste into the new document you created in step #1.

7) In your new file, go to the beginning of the code file and add the opening php tag - " < ? php " (no quotes). In Dreamweaver the code should appear color-coded correctly (i.e. not black - if it is you didn't cut/paste correctly or add the tag in the right place!) Save this file with the tpl.php extension to the directory where all your other template content files reside (not necessarily the same folder as main_page.tpl.php...) 8) Open includes/filenames.php and add the following line:

define('CONTENT_PAGENAME', 'pagename');


Replace "pagename" with the name of your file. For example, for recently viewed:

define('CONTENT_RECENTLY_VIEWED', 'recently_viewed');


9) Go back to the original file you started out with. Under the language reference, add the following lines:


$content = CONTENT_PAGENAME;

include (bts_select('main', $content_template)); // BTSv1.5

require(DIR_WS_INCLUDES . 'application_bottom.php');


Replace "pagename" with the name of your file - should match what you just added to filenames.php. For example, for recently viewed:


$content = CONTENT_RECENTLY_VIEWED;


10) Add a closing php tag - " ? > " (no quotes). Now in Dreamweaver's code view, everything should show up color-coded, not black - if it's black you either didn't add everything or added it in the wrong places...

That's it! Save everything, upload to your server, and voila! You've converted a non-BTS file to BTS.

What's next?
This is just the beginning. Now that your file is in BTS mode, you can edit the HTML to match the look-and-feel of the rest of your site...

4 comments:

  1. I just tried to follow this, but didn't understand 'Starting from "require" reference' - what is require reference, the require statement turns up all over the code - left col, right col etc.

    Matt

    ReplyDelete
  2. Matt - You basically need to delete from the recently viewed file everything that BTS already covers: the opening HTML and BODY tags and left column includes, and towards the end, the right column code, footer, and closing BODY and HTML tags. You're only keeping the middle chunk of code that has the page content there.
    One of these days I'll post on the addons site the contribution is OscMax format... I've just made too many changes from the standard one to fit the designs of my websites.

    ReplyDelete
  3. Hi there,

    Just came across this site in my pursuit to try and see how best I can convert this oscommerce template so it works in the new oscmax 2.0.25.

    Maybe you can turn me around and point me in the right direction?

    The site layout I want to convert so it works in oscmax is..

    http://www.1300rentbuy.com

    Thanks


    oz :-)

    ReplyDelete
  4. I'm not too familiar with oscommerce, but from what I've seen it's very different from oscmax and there's no simple way to convert to BTS... Also, it's difficult to give feedback without seeing the template code.
    The general idea I describe - eliminating the headers and footers of each page - still holds, but unless you're very comfortable with php, I'd recommend to just do a fresh install of oscmax.

    ReplyDelete