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/

xcell67 04-07-2004 06:23 PM

Hi Jon,
after typing PWD, this is the path that I am in:

/var/www/html/store/

store is my main folder that holds all the xcart files including the customer folder

when I FTP into my customer folder, there is no "product" folder that exists but there is product.php but I doubt that the SSH session is picking up on that file.

I also tried to go into the directory

/var/www/html/store/customer/

and typing ln staticproduct.php product

this creates a file, not a folder called product in my customer folder but typing http://www.mysite.com/product/290/ still gets me a 404 not found message.

By the way, I also used

/var/www/html/store/ as the /full/path/to/files to edit the pages.

Jon 04-07-2004 06:57 PM

Sounds like the product file (it should look like a file) is located in:
/var/www/html/store/

If that's the case, you'll need to use:

http://www.mysite.com/store/product/290/

xcell67 04-08-2004 01:57 AM

Yup, It WORKS!

not putting the "store" in the address was the evil little problem.

Now that I got this to work, I have one last question to ask, with this, would there still be a need to create the html catalog?

Jon 04-08-2004 09:50 AM

I don't see the need to use the HTML catalog, however I'm using an x-cart version pre-html catalog, so I don't know a lot about how it works.

What I've done instead, is edit my template files to use these static links anywhere a product is linked - The product templates, the best sellers list, upselling templates, etc., etc.

Then I created php files for my categories: http://forum.x-cart.com/viewtopic.php?t=9313&highlight=

And now the majority of the store appears static. A benefit about this also, is that you don't have duplication in your store, you don't have to do any re-compiling, etc.

xcell67 04-08-2004 02:53 PM

Correct me if I'm wrong, but I think it is redundant to use this mod along with the html catalog. The advantage of this mod is not having to recompile all the time, but the advantage of the html catalog is less pressure on your site because the customer browses the html catalog and doesn't enter php until they checkout. Or am I missing something, and they both can coexist?

Also, do you have to do this process for each category or put them all in one file?

1) Use an .htaccess file to parse .html as php.

2) Create a category1.html

3) In category1.html put:

Code:

<?
$cat = "1";
include "./home.php";
?>

Jon 04-08-2004 02:58 PM

I've never used the HTML catalog, so perhaps somebody who has could elaborate on the strengths and weaknesses of each approach and how they would or wouldn't co-exist.

You'd only have create the .htaccess file once, and repeat the other two steps for each category.

Or you could create a category_name.php and just put in:

<?
$cat = "1";
include "./home.php";
?>

And repeat that for each category.

cmtrade 06-17-2004 05:13 AM

Anyone did it for version 3.5.8 yet?

Thanks,
Dan.

Jon 06-17-2004 08:35 AM

I've installed 3.5.8 and am studying the code.

Unless you DON'T plan on upgrading your cart, probably best only to use this mod on pre-catalog carts.

For carts with the catalog, I would suggest just building your catalog to your root httpdocs directory (below the customer directory) and setting up a cron job to build the catalog a couple times daily.

Alan 07-06-2004 01:24 AM

Greetings,

Thank you so much for contributing to us x-carters with this masterpiece.

I do have 1 question, and that is how you allow spiders to index your search frienly pages? Do you write out a whole lists of URLs in your robots.txt for them to crawl? As your "Product" folder is only a symbolic file, I wouldn't be able to put any files in there such as search_friendly_words.html

As some of us have stores that enables/disables products daily, keeping an uptodate list is tedious as well. I guess I want to say that, how do you let the Search Engines knows that you have these pages? Or is this only useful in your store itself that you can add a couple of html pages in your subcategories.tpl, instead of being product.php?

Jon 07-06-2004 08:42 AM

What I did, was edit my category links, so that they were php files by using code like this:

Code:

<?
$cat = "15";
include "./home.php";
?>


I then edited the categories.tpl to include these.

I then edited all of my product links, including my products.tpl, best sellers list, etc., etc., to change product links to something like this:

Code:

<a href="/product/{$products[list].productid}/{$products[list].product|replace:" ":"_"}.html">

This creates a link to the product using the product title as the file name.

I also created a full page product listing, that grabs all of the enabled products, and lists them on 1 page, with links to their static pages, and put a link to that page on the index page. Most important thing to remember, is not to have your index page as a redirect.

Doing this we've had success with search engine spiders.

macker123 10-17-2004 12:14 PM

I am wanting to do this on a 4.0.5 installation. It looks like the paths are already fully encoded into the new version and some steps seem to be missing. Has anyone done this on a 4 installation?

This is EXACTLY what I need for a client. Any help is appreciated.

Jon 10-17-2004 06:21 PM

I haven't yet tried it with 4.0 but I do believe the paths are fully encoded, so it should work. Just be sure to backup before trying :) Please let us know if you attempt this.

jdiehl 03-12-2005 06:32 PM

4.0.12 got it!
 
I'm new to X-Cart and just installed 4.0.12

I wanted this feature on my store especially for product pages and for category pages, possibly more in the future i.e. articles

I spent the last couple of days working out this mod for 4.0.12 and I have it working successfully except that I am using "MultiViews" in the httpd.conf file under directory>options. But using a symbolic link like Jon suggested works fine also.

The good news is that the mod isn't as extensive for 4.0.12 because the Paths are encoded, but just not for the links to the products which you have to change anyway.

With MultiViews turned on if I goto www.mystore.com/product/37/43/keywords.html then because the directory "product" doesn't exist it will automatically load product.php instead. Then I just explode the "PATH_INFO" in the product.php (or in the home.php for categories, we don't want the spiders to think the categories are dynamic and stop crawling) which results in the /37/43/keywords.html and I can use code to tell assign varibles for productid 37 in category 43.

I had to adjust the code though and I can paste it if you guys want, but here's what I found:

1. by default when exploding it assigns the "37" as a string not as an integer so I forced it into an integer (I don't know if this really matters)

2. In X-Cart 4.0.12 it checks to see if the variables have been assigned from the URL in the conventional GET Method, so if you assign these variables to $productid and $cat the X-Cart will forward you to an error message. So you have to adjust for this also

This might be as clear as mud due to my bad communication skills, but I understand it and got it to work so if anyone needs more help with this let me know and I'll post code and more. I am not quite finished with editing all the links but it is working for me.


All times are GMT -8. The time now is 08:28 PM.

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