X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   MultiSkin (https://forum.x-cart.com/showthread.php?t=4708)

buster 10-10-2003 12:44 PM

MultiSkin
 
When you go to http://www.x-cart.com/shopping_cart_demo.html you have a choice to demo different schemes. It adds ?multiskin=skin# to the end of the url and you get the corresponding skin.

Are they using the Skin Swap mod? Or something else?

Thanks

funkydunk 10-13-2003 08:44 AM

been looking at that - they have a slightly modified version of the xcart there for the demo - this includes a session/cookie that sets the skin to use.

nice mod - shame they haven't released it :(

jpsowin 10-13-2003 09:19 AM

Isn't that false advertising? :lol:

funkydunk 10-13-2003 09:22 AM

be nice if this was the exact code that was released :)

buster 10-13-2003 12:04 PM

Would be nice... Even if it was an add-on (that way I know updates would work).

It would really solve the problem that I have with personalized pages.


Mabey it is unstable and that is why they haven't released it?

jpsowin 10-13-2003 12:09 PM

Mabey it is unstable and that is why they haven't released it?

I doubt that's the reason. No further comment on why I think that... ;)

funkydunk 10-13-2003 12:10 PM

it wouldn't be unstable - just want to keep it to themselves maybe :)

come on rrf - how about releasing it??? :wink:

funkydunk 10-13-2003 12:11 PM

promise we wouldn't tell anyone :lol:

buster 10-13-2003 12:37 PM

Ok.. so first off i'm not the php wiz (or smarty wiz at that) but I was/am screwing around with this.

What about going into smarty.php and putting in an if statement:
Code:

if( $HTTP_GET_VARS['skin'] == 2){
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates2_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache2";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->debug_tpl="file:debug_templates.tpl";
} else {
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->debug_tpl="file:debug_templates.tpl";
}

And
Code:

if( $HTTP_GET_VARS['skin'] == 2){
        $smarty->assign("ImagesDir","../skin2/images");
        $smarty->assign("SkinDir","../skin2");
} else {
        $smarty->assign("ImagesDir","../skin1/images");
        $smarty->assign("SkinDir","../skin1");
}



It seems to work, but I know 0 (<-- thats a zero) about cookies.

Will this break anything???


[Edit] I guess it would help if i finish a thought.

I know 0 about putting this in a cookie, so the url doesn't always have ?skin=# in it
[/Edit]

buster 10-13-2003 12:57 PM

Ok.. I'm about to go home from work and wont be able to play with this for awhile but:
Code:

if( $HTTP_GET_VARS['skin']){
        setcookie('skin', $HTTP_GET_VARS['skin']);
        }

if(( $HTTP_COOKIE_VARS['skin'] == 2) || ( $HTTP_GET_VARS['skin'] == 2)){
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates2_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache2";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->debug_tpl="file:debug_templates.tpl";
        $smarty->assign("ImagesDir","../skin2/images");
        $smarty->assign("SkinDir","../skin2");
} else {
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->debug_tpl="file:debug_templates.tpl";
        $smarty->assign("ImagesDir","../skin1/images");
        $smarty->assign("SkinDir","../skin1");
}       


Not being a php guru is there a way to use a switch statement to make this cleaner/add more skins easier?

Also, there is the problem of switching back to the 1st skin, when the cookie is set to skin2 and you put a ?skin=1, the cookie is updated but skin2 shoews till you hit refresh because of :
Code:

if(( $HTTP_COOKIE_VARS['skin'] == 2) || ( $HTTP_GET_VARS['skin'] == 2)){
I assume it reads the cookie (2) before it sets the cookie (1)? Or it reads the cookie (2) caches the value then the page runs?
Again, this just shows how little I know of php. :(


Going to do some looking, but any help is apprecieated.

buster 10-15-2003 07:18 AM

Ok, (not that anyone is following this thread :) )
Here is the latest that I have, (the whole smarty.php):
Code:

<?
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2003 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2003          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: smarty.php, Modified $
#

umask(0);

#
# If we are in subdir of X-Cart dir, then include with '../'
# else include with './'
#
if (!@include("../Smarty-2.5.0/Smarty.class.php"))
        @include("./Smarty-2.5.0/Smarty.class.php");

#
# Get absolute path
#
define('BASEDIR', realpath(dirname(__FILE__)));

#
# Smarty object for processing html templates
#
$smarty = new Smarty;
       
if( $HTTP_GET_VARS['skin']){
        // Setting the fake cookie so we can do some if's later
        $_COOKIE['skin'] = $HTTP_GET_VARS['skin'];
        //Setting the real cookie, expires 1 year from now
        setcookie('skin', $HTTP_GET_VARS['skin'], time() + 31536000);
} else {
        // Setting the fake cookie so we can do some if's later
        $_COOKIE['skin'] = $HTTP_COOKIE_VARS['skin'];
        //Updating the real cookie to expire 1 year form now
        setcookie('skin', $HTTP_COOKIE_VARS['skin'], time() + 31536000);
}

// Set some directories based on cookie, or lack of cookie
if( $_COOKIE['skin'] == 2){
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates2_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache2";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin2";
        $smarty->debug_tpl="file:debug_templates.tpl";
        $smarty->assign("ImagesDir","../skin2/images");
        $smarty->assign("SkinDir","../skin2");
} else {
        //Default Template in case cookie is not set
        $smarty->template_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->compile_dir = BASEDIR.DIRECTORY_SEPARATOR."templates_c";
        $smarty->config_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->cache_dir = BASEDIR.DIRECTORY_SEPARATOR."cache";
        $smarty->secure_dir = BASEDIR.DIRECTORY_SEPARATOR."skin1";
        $smarty->debug_tpl="file:debug_templates.tpl";
        $smarty->assign("ImagesDir","../skin1/images");
        $smarty->assign("SkinDir","../skin1");
}       

if( !is_dir($smarty->compile_dir) && !file_exists($smarty->compile_dir) )
        @mkdir($smarty->compile_dir);

if( !is_writable($smarty->compile_dir) || !is_dir($smarty->compile_dir) ){
        echo "Can't write template cache in the directory: ".$smarty->compile_dir.".
Please check if it exists, and have writable permissions.";
        exit;
}

$file_temp_dir=$smarty->compile_dir;

#
# Smarty object for processing mail templates
#
$mail_smarty = $smarty;

#
# WARNING :
# Please ensure that you have no whitespaces / empty lines below this message.
# Adding a whitespace or an empty line below this line will cause a PHP error.
#
?>


I copied the default skin1 directory to a new skin2 directory.
If you add ?skin=# to the end of the URL the change is immediate, unlike my last post. You don't need ?skin=# except to change skins. The cookie stays between sessions. Still reading up on cookies, security wise.

The admin section is a little funny.
When you are in the admin section you can change skins after you login. After changing skins you can edit the skin, yadda, yadda. When you log out it goes back to skin1, I assume the cookie gets deleted when you logout, that way you are forced to re-enter your username and password.
So still looking at that as well.

Any help? Comment? Foreseeable problems?

buster 10-16-2003 08:38 AM

Ok, figured out the admin section. When you set the cookie you have to set the path that can read the cookie. So if you do this:
Code:

setcookie('skin', $HTTP_GET_VARS['skin'], time() + 31536000, "/");
Then the skin works for the admin section as well.

B00MER 10-19-2003 11:28 AM

Your close but not quite there yet ;)

I've already got such done, and is in working condition & tested on live sites, mod_skinswap:

http://www.cartlab.net/lab/customer/product.php?productid=27

New version is about to be released which includes some of the new features:

- Admin configurable
- Disable/Enabled Swapping
- What to swap with, Store Language, Affiliate ID, Skin variable or any other variable.
- Default skin (fallback) if none is specified
- Use a skin repository directory to store all skins, or use subdirs directly from the root of xcart/
- Set which debug template to use on "Enable debug console" in General Settings of admin. (debug.tpl, or debug_tempaltes.tpl)
- Cookie lifetime of 1 year of skin choice.
- Check if skin directory specified in swap variable exist if not fallback to default.

http://www.cartlab.net/images/skinswap_ss.gif

The new version will be either released today or tomorrow.

Kudos! ;)


All times are GMT -8. The time now is 03:52 PM.

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