Fake Real Static HTML Product Pages
Jon Peters
Written: Tuesday, March 23, 2004
----------------------------------------------------
This mod will allow you to access your current pages as read from your database with a url like:
http://www.yourstore.com/product/productid/
The productid will be the productid for the product you want to view.
It does not require any database changes, or any compiling or creation of actual html pages.
----------------------------------------------------
DO NOT START THIS PROCESS WITHOUT READING STEP 8 FIRST!!!!!!!!!!!!!!!!!!!!!!! -> It's not fun!
Be sure to know your full path to the files, and substitute it everywhere below where it says /full/path/to/files/
WARNING: This mod is a LOT of work, and takes knowledge of your store and it's inner workings to install. If you are expecting a complete list of steps here to fully integrate this, do not attempt this mod. Changes will need to be made specifically to your version of x-cart.
We have a very customized version of an earlier version of x-cart, so I've tried to make these instructions more applied to the generic x-cart, but changes will be needed for your particular installation.
I believe this will only work on apache servers.
Be sure to back up, and don't blame me if your installation messes up, cause it works for me.
LAST WARNING: This is meant as a guideline, not a step-by-step process!!! Got it? Ok, lets proceed...
----------------------------------------------------
##################################
# STEP 1 #
##################################
By default, x-cart and smarty are setup to use directory structures which use includes with ./ and ../
We need to change this. Lets start by editing our config.php
Backup config.php first!!!
---------------------------
Find all areas such as these:
Code:
if ($reg_globals) {
if (is_readable("../globals.php"))
require_once "../globals.php";
elseif (is_readable("./globals.php"))
require_once "./globals.php";
}
and change them to:
Code:
if ($reg_globals) {
require_once "/full/path/to/files/globals.php";
}
Find:
Code:
#
# Include functions
#
if (!@include_once("../include/func.php"))
@include_once("./include/func.php");
Change to:
Code:
#
# Include functions
#
@include_once("/full/path/to/files/include/func.php");
Find:
Code:
if ($store_sessions_in_mysql)
if (!@include_once("../include/mysql_sessions.php"))
@include_once("./include/mysql_sessions.php");
Change to:
Code:
if ($store_sessions_in_mysql)
@include_once("/full/path/to/files/include/mysql_sessions.php");
Find:
Code:
#
# Prepare session
#
if (!@include_once("../include/sessions.php"))
@include_once("./include/sessions.php");
Change to:
Code:
#
# Prepare session
#
@include_once("/full/path/to/files/include/sessions.php");
UPLOAD AND MAKE SURE YOUR SITE STILL WORKS. IF IT DOESN'T, REUPLOAD FROM BACKUP AND TRY AGAIN.
##################################
# STEP 2 #
##################################
Download smarty.php and rename to smarty_staticpages.php
Open smarty_staticpages.php
Find:
Code:
#
# If we are in subdir of X-Cart dir, then include with '../'
# else include with './'
#
if (!@include("../Smarty-2.1.1/Smarty.class.php"))
@include("./Smarty-2.1.1/Smarty.class.php");
Change to:
Code:
@include("/full/path/to/files/Smarty-2.1.1/Smarty.class.php");
Find:
Code:
$smarty->template_dir = "../skin1";
$smarty->compile_dir = "../templates_c";
$smarty->config_dir = "../skin1";
$smarty->cache_dir = "../cache";
$smarty->secure_dir = "../skin1";
$smarty->debug_tpl="file:debug_templates.tpl";
$file_temp_dir=$smarty->compile_dir;
$smarty->assign("ImagesDir",$smarty->template_dir."/images");
$smarty->assign("SkinDir",$smarty->template_dir);
Change to:
Code:
$smarty->template_dir = "/full/path/to/files/skin1";
$smarty->compile_dir = "/full/path/to/files/templates_c";
$smarty->config_dir = "/full/path/to/files/skin1";
$smarty->cache_dir = "/full/path/to/files/cache";
$smarty->secure_dir = "/full/path/to/files/skin1";
$smarty->debug_tpl="file:debug_templates.tpl";
$file_temp_dir=$smarty->compile_dir;
$smarty->assign("ImagesDir","../../skin1/images");
$smarty->assign("SkinDir",$smarty->template_dir);
Upload smarty_staticpages.php to the same folder as your smarty.php (which should be a directory level lower than your customer folder).
##################################
# STEP 3 #
##################################
Download your product.php and rename it to staticproduct.php
At the very top of it (after the <? of course) put:
NOTE: BE SURE TO EDIT THE $redirecturl VARIABLE.
Code:
if (!$productid) {
#
# BE SURE TO SET THIS VARIABLE TO YOUR STORE HOME
#
$redirecturl = "/customer";
// Seperate URL by slashes
$request = explode("/",$_SERVER["REQUEST_URI"]);
// Count the Slashes
$i = count($request);
// Make adjustment to grab the second last folder
$i--;
$i--;
// Grab the product ID
$productid = $request[$i];
$productid = stripslashes($productid);
// Ensure the productid is a number
if (!is_numeric($productid)) { header ("Location: $redirecturl"); }
}
Still in staticproduct.php, change all references of
to:
Code:
/full/path/to/files/
Change all references of
to:
Code:
/full/path/to/files/customer/
Change the include of smarty.php to instead include the file we upload earlier.
Change:
Code:
require "/full/path/to/files/smarty.php";
To:
Code:
require "/full/path/to/files/smarty_staticpages.php";
Change your smarty display to use a full path. I've changed smarty display paths so many times I don't remember what the original was, I think it was:
Code:
$smarty->display("customer/home.tpl");
Change it to:
Code:
$smarty->display("file:/full/path/to/files/skin1/customer/home.tpl");
Save, Close and Upload to the same folder as product.php
##################################
# STEP 4 #
##################################
If you have an .htaccess file in your root directory (the directory that the customer folder resides in, not inside the customer folder) then edit it. Otherwise create a new .htaccess
In it put:
Code:
<Files product>
ForceType application/x-httpd-php
</Files>
Upload it.
##################################
# STEP 5 #
##################################
Log in to telnet or ssh, whatever you use to connect via shell. This part is very important, it's creating a symlink between your pretend product folder and your staticproduct.php
Change to your root directory (again, the directory that the customer folder resides in, not inside the customer folder) and type:
Code:
ln customer/staticproduct.php product
(That's a lower case L)
##################################
# STEP 6 #
##################################
Open up your /customer/auth.php file
Change all references of
to:
Code:
/full/path/to/files/
Upload it.
##################################
# STEP 7 #
##################################
Open up a static url with a valid productid such as:
http://www.yourstore.com/product/productid/
NOTE: You must have a trailing slash after the productid.
The productid variable is the same as normally passed through product.php?productid=whatever
i.e.
http://www.yourstore.com/product/productid/
##################################
# STEP 8 #
##################################
You'll now be able to view your product, with 1 problem. All the links on this page are going to be referenced to the folder it's in, which is now wrong.
When we were calling it from /customer/product.php?productid= we could use a link such as home.php to return to the store. Now we can't. We need to change everything to call /customer/filename.php instead.
This includes all the links, the image.php's, form action's, etc.
This is very tricky, as many links are hidden in module template files, and so forth.
Only the links called from this current page will need to be changed, not your entire store, however some modules currently turned off, will also need to be changed when turned on, so you'll want to find them in advance.
Here's a few templates to change for sure.
Code:
Open /skin1/product_thumbnail.tpl and change ../image.php to /customer/image.php
(or /image.php I don't recall which is default, make it point to your image.php anyway)
Code:
Open /skin1/modules/Detailed_Product_Images/product_images.tpl and change ../product_image.php to your product_image.php
You should now be able to refresh your static page and have images.
Code:
/customer/categories.tpl needs the <a href tags changed to <a href="/customer/home.php...
Code:
/location.tpl needs the <a href tags changed to <a href="/customer/home.php...
If you have a search form or search links, those need changing.
Bestsellers module
/skin1/Modules/giftcertificates/gc_menu.tpl
/skin1/Modules/Recommended_Products/recommends.tpl
Reviews Module
Upselling Products Module
/skin1/Modules/Wishlist/wishlist.tpl
/skin1/customer/menu_cart.pl
/skin1/customer/main/product.tpl
--------------------------------
LOGIN ISSUES
--------------------------------
Check your auth.tpl and your authbox.tpl and log in and out on your static pages to make sure it works.
I created seperate auth_store.tpl and authbox_store.tpl and changed the ../include/login.php reference and the <a href links.
You'll probably have to edit your /include/login.php file as well as there are a lot of ../ references. If you have issues, rename your default login.php to login_staticpages.php call that from your auth_store.pl and authbox_store.tpl and hardcode all the header locations.
I edited my staticpages.php to smarty assign redirect as product/$productid/ and then edited my login_staticpages.php to send error pages, etc. to /customer/... and direct logins and logouts to remain on this same static page.
--------------------------------
CONCLUSION
--------------------------------
Not a fun mod to implement, but it's very effective and saves lots of updates and compiling.