
如果你为一个站的所有商店各自设置了唯一的base URL,所有你需要用来多店切换的就是下面这段代码。
只要把它粘贴的模板的某处。
当然,记住我只在自己的配置上测试过,基本上这段代码就是跳转到商店的base url。
<!-- BEGIN website switcher -->
<select id="website-changer" onChange="document.location=this.options[selectedIndex].value">
< ?php
$websites = Mage::getModel('core/website')->getCollection();
foreach($websites as $website)
{
$default_store = $website->getDefaultStore();
$url_obj = new Mage_Core_Model_Url();
$default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
?>
<option <?php if(strstr($this->helper('core/url')->getCurrentUrl(), $default_store_path)):?>selected="selected"< ?php endif; ?> value="< ?php echo $default_store_path ?>">< ?php echo $website->getName()?></option>
< ?php
}
?>
</select>
<!-- END website switcher -->
尽管不能完全保证这段代码的正确性,我还是希望有些人会觉得可以用。
如果您有任何问题,可以在这里提问。
原文地址:http://inchoo.net/ecommerce/magento-snippet-for-switching-between-websites/