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)
-   -   Making the Skin Swap mod more temporary... (https://forum.x-cart.com/showthread.php?t=9833)

minorgod 10-13-2004 01:56 PM

Making the Skin Swap mod more temporary...
 
The CartLab skinswap mod is very useful for changing the look of your site by triggering the skin swap with a variable in your URL. However, since it uses a cookie, you have trouble with the swapped skin showing up the next time your users visit your web site, regardless of whether the skinswap variable is in your URL. Instead, it would be nice if the SkinSwap did not use cookies with specific expiration dates, but instead had cookies that expired whenever the user closes his browser window, so that the next time he visits the site he will see the default skin unless it's specifically swapped again via another variable in the URL. I tried several methods of messing with the cookie expiration times and then realized how much easier it would be to do this using sessions instead of cookies. All you have to do is take the Skin Swap version of your smarty.php file and make the following changes.
Replace this:
Code:

if($allow_skin_swap_mod=="Y") {
                if($HTTP_GET_VARS[$value_to_swap_with]) {
                        if(!is_dir(BASEDIR.DIRECTORY_SEPARATOR.$skin_swap_repository.$HTTP_GET_VARS[$value_to_swap_with])) {
                                $skinswap_found_dir = false;
                                $skinswap = $default_skin;
                        }
                        if($skinswap_found_dir) {
                                $skinswap = $HTTP_GET_VARS[$value_to_swap_with];
                                setcookie ("skinswap", "", time()-31536000);
                                setcookie ("skinswap", $HTTP_GET_VARS[$value_to_swap_with], time()+60);
                        }
                } elseif($HTTP_COOKIE_VARS["skinswap"] && !$HTTP_GET_VARS[$value_to_swap_with]) {
                        $skinswap = $HTTP_COOKIE_VARS["skinswap"];
                } elseif(!$HTTP_COOKIE_VARS["skinswap"] or !$HTTP_GET_VARS[$value_to_swap_with]) {
                        $skinswap = $default_skin;
                }
} else {
        $skinswap = $default_skin;
}

with this:
Code:

if($allow_skin_swap_mod=="Y") {
                //here we start a session just to keep track of the skinswap info.
                //This uses standard PHP sessions in files and is later ignored by
                //x-cart's custom session handlers which will replace this session
                //with new data after this session is read.
                session_start();
                if($_GET[$value_to_swap_with]) {
                        if(!is_dir(BASEDIR.DIRECTORY_SEPARATOR.$skin_swap_repository.$_GET[$value_to_swap_with])) {
                                $skinswap_found_dir = false;
                                $skinswap = $default_skin;
                        }
                        if($skinswap_found_dir) {
                                $skinswap = $_GET[$value_to_swap_with];
                                $_SESSION['skinswap']=$_GET[$value_to_swap_with];
                        }
                } elseif($_SESSION["skinswap"] && !$_GET[$value_to_swap_with]) {
                        $skinswap = $_SESSION["skinswap"];
                } elseif(!$_SESSION["skinswap"] or !$_GET[$value_to_swap_with]) {
                        $skinswap = $default_skin;
                }
} else {
        $skinswap = $default_skin;
}


Since there's no expiration set for the session, it expires automagically when the browser window is closed or after the default PHP session expiration time, depending in which happens first. Notice that we're using basic PHP session handling here because we do not have access to the xcart sessions until later in the x-cart code since x-cart sessions are started way after the smarty.php file is included and we need access to sessions before that happens. That's why I've simply started a new session so we can use that skinswap data before the x-cart sessions overwrite the skinswap session data in memory. Oh, and I also replaced the crusty old $HTTP_GET_VARS syntax with shiny new $_GET superglobal syntax because I'm cool like that.
Enjoy.

minorgod 11-09-2004 12:29 PM

I've found a better way to do this...I think.
 
Disregard my previous method. It causes problems if you have hardcoded links that add products directly to your cart without going through the storefront. I have set up a different method that requires no modification to the skinswap mod itself. Instead modify your /customer/auth.php file by adding the following lines somewhere...it doesn't really matter where...
Code:

//skin swap mod modification by brett
//first we register an x-cart session variable to hold the skinswap status
//then we see if the customer has submitted a variable that triggers the skin swapping

x_session_register('do_skinswap');
if(!empty($_GET[$value_to_swap_with])){
        if(!empty($skinswap) && !empty($default_skin) && $skinswap != $default_skin){
                $do_skinswap="true";
        }
}
//now that we've set the variable that determines if we should swap skins or not
//we check to see if it is empty (meaning it contains no string at all) which would
//indicate that it has not yet been set. If it hasn't been set, we set the variable equal
//to the string "false", expire the existing skinswap cookie that causes the swapping,
//then redirect to wherever the user was. This should kill the skin swapping when the
//page reloads

if(empty($do_skinswap)){
        $do_skinswap="false";
        setcookie ("skinswap", $default_skin, time()-31536000);
        header("Location: $_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]");
}


The purpose of this mod is to keep the customer from being locked into the same skin each time they return to your store under a different session. With my modification, the skin swapping will stop if a user closes their browser window and revisits your site without going through your specific skinswap URLs. Enjoy.

gfiebich 03-14-2005 12:07 PM

Any chance you could update this code to work with 4.0.12?

minorgod 03-14-2005 12:18 PM

Nope, sorry, not in the near future. The code should only require minor tweaking to work with the 4.x branch if you'd like to take a stab at it yourself though.


All times are GMT -8. The time now is 03:22 AM.

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