Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Created June 7, 2012 21:23
Show Gist options
  • Save georgestephanis/2891616 to your computer and use it in GitHub Desktop.
Save georgestephanis/2891616 to your computer and use it in GitHub Desktop.
Magento Website Switcher
/* Determine the store we're after. */
if( isset( $_REQUEST['___website'] ) ) {
$___website = preg_replace( '/[^a-zA-Z0-9\s]/', '', $_REQUEST['___website'] );
$_SERVER['MAGE_RUN_CODE'] = $___website;
$_SERVER['MAGE_RUN_TYPE'] = 'website';
/* If the cookie isn't yet set, or the request variable is changing it ... */
if( ! isset( $_COOKIE['___website'] ) || ( $_COOKIE['___website'] !== $___website ) ){
setcookie( '___website', $___website, ( time() + ( 60*60*24*365 ) ) ); # One Year
}
unset( $___website );
} elseif( isset( $_COOKIE['___website'] ) ) {
$___website = preg_replace( '/[^a-zA-Z0-9\s]/', '', $_COOKIE['___website'] );
$_SERVER['MAGE_RUN_CODE'] = $___website;
$_SERVER['MAGE_RUN_TYPE'] = 'website';
unset( $___website );
}
@lukebranch
Copy link

Hi George,

I've been searching to find a website selector/switcher and store selector switcher to implement in addition to the default store view selector available with Magento. I've thought of doing it manually with a simple HTML dropdown, however this is obviously not the ideal solution.

Any idea or suggestions on how this could be implemented in CE 1.8? I have not managed to find anything except outdated posts back in 2010 on inchoo that tackle the subject and the code is outdated and not workable for 1.7-1.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment