X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Fake Real Static HTML Product Pages (https://forum.x-cart.com/showthread.php?t=6826)

Jon 03-23-2004 03:21 PM

Fake Real Static HTML Product Pages
 
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

Code:

../

to:

Code:

/full/path/to/files/

Change all references of

Code:

./

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

Code:

../

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.

Jon 03-23-2004 03:42 PM

Note also, that this only reads the last folder, so you can fake a .html file after it, filled with keywords.

i.e.
http://www.domain.com/product/1/fake_file_name_here.html
http://www.domain.com/product/1/other_fake_name.html

Will both load the same product.

You can then build a .html name from the product title.

I use:

{$products[product].product|escape}

groovico 03-23-2004 04:19 PM

Very nice mod, anyone undertaking it though remember it will affect your future upgrade patches and make them a nightmare to implement (prepare for lots of coffee and lots of patching by hand) so only do it if your very confident with the system and have a cart you don't intend on upgrading very often.

Remember to BACK UP your site properly before undertaking a mod like the one above.

We use a very similar method in a CMS we've been developing for another project. It's one area where apache servers come in very useful :D

B00MER 03-24-2004 08:32 PM

Whew, one helluva a mod you got there. Looks interesting enough, haven't gotten a chance to implement it but may sometime soon. Only thing I'd like to add is if your good enough with regular expressions you could use apache mod_rewrite and setup rules for easy urls, like:

www.example.com/xcart/customer/product/34

34 being the product ID. Which is good for search engines especially, that and it just looks nicer.

Anyhow, thanks for sharing the hard efforts! :wink:

Dmitri 03-24-2004 09:09 PM

very imressive mod!

but for search engines it alwasy better to have keywords in the URL.
in that matter HTML catalogue works better because it allow you to include keywords in the product title.

groovico 03-25-2004 06:35 AM

Quote:

Originally Posted by Dmitri
very imressive mod!

but for search engines it alwasy better to have keywords in the URL.
in that matter HTML catalogue works better because it allow you to include keywords in the product title.


The mod above has that, note the use of the productname.html portion which you can effectively configure for anything.

You can be very creative with stuff like this as it can be taken many many stages further.

Just because a site looks static these days, doesn't mean it is. You can make an html site look like it's php, php look like it's html, php look like it's asp.

You can be really funny and force apache to parse .asp files as php, do a global file rename on everything in the x-cart install, and change all .php extentions to .asp and confuse the world into thinking there's an asp version of x-cart! :twisted:

I've seen some systems where the extension is changed to .m so you have no idea what the system is running on.

Dmitri 03-25-2004 07:20 AM

yep! I know that.

I actualy running similar thing on asfdesign.com

in knowledge base url looks like there are directories, when the fact is, / being parsed and replaces with ? / and = when needed...

what people won't do just to get to top of search engines :)

Jon 03-25-2004 09:52 AM

Thanks for the feedback.


MOD REWRITE

Mod rewrite can be server intensive, so I wanted to stay away from it.


UPGRADES

For people who want to install this and keep their x-cart upgrades manageable, I would just backup all the files you change now. When you upgrade, revert to the backed up files, do the upgrade, and then reapply this mod. Probably faster to reapply this mod than to spend time with .diff's ;)


KEYWORDS

As mentioned, you can put keywords in the .html file name which can be anything.

If you wanted to increase key words, you can always modify this (as mentioned you can be as creative as you wish) to add a secondary folder, so that you have http://www.domain.com/product/FAKE_KEYWORD_FOLDER/PRODUCTID/key_words_here_too.html

xcell67 04-06-2004 08:37 PM

Hi Jon,
Great work on this mod. I think I got everything right up until step 7.

I used the program Putty to connect via SSH and went to my directory that holds my customer folder.

I then entered the command:

ln customer/staticproduct.php product

but then I get this message

ln: 'product': File exists

Does this mean the command worked and I just did not edit the pages correctly in the previous steps or do I need to enter a different command?

Thanks.

Jon 04-07-2004 09:44 AM

Can you type: pwd

And tell me what your current path is?

It either means your working from the wrong path, or that you have a product folder already.

The product folder can't exist, because it's going to become a faked folder.

If you have an empty product folder below your customer directory, delete it, if you need the folder, you'll have to use a different name, like item.

Then substitute "item" for "product" in your URLs.

i.e. http://www.yourstore.com/item/productid/


All times are GMT -8. The time now is 10:27 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.