Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Making the Skin Swap mod more temporary...

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-13-2004, 01:56 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default 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.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #2  
Old 11-09-2004, 12:29 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default 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.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #3  
Old 03-14-2005, 12:07 PM
 
gfiebich gfiebich is offline
 

Senior Member
  
Join Date: Feb 2003
Location: St. Paul, MN
Posts: 108
 

Default

Any chance you could update this code to work with 4.0.12?
__________________
NO LONGER USING X-CART - NOT ACTIVE IN THESE FORUMS
Reply With Quote
  #4  
Old 03-14-2005, 12:18 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

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.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2020