magento -- 前台在一站多店之間切換的代碼片段
如果你為一個站的所有商店各自設置了唯一的base URL,所有你需要用來多店切換的就是下麵這段代碼。
隻要把它粘貼的模板的某處。
當然,記住我隻在自己的配置上測試過,基本上這段代碼就是跳轉到商店的base url。
<!-- BEGIN website switcher --> <select 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 -->
盡管不能完全保證這段代碼的正確性,我還是希望有些人會覺得可以用。
如果您有任何問題,可以在這裏提問。
原文地址:https://inchoo.net/ecommerce/magento-snippet-for-switching-between-websites/
最後更新:2017-04-02 04:26:00