2011/03/21

[Magento] 更改language drop down menu

magento 最煩既一樣野就係你搵唔到個file出黎改....

當然你可以去admin config 個 show path hints, 但有時template 入面再有template, 就不免要人手入去搵

今日想改langauge 個drop down menu, 變左<a href=""....>既link

路徑幾經辛苦找到是base\default\template\page\switch\

language.phtml, 把select tag comment掉, 

我希望做到, 當store view是中文的時候, 顯示"eng" link ; 當英文的是時候, 顯示"中文"link

這時要了解一下magento 部份api function...

$this->getCurrentStoreId();    // (int) 取得store view的id (e.g. 中文→ 1 , 英文 →2)

$this->getStores() ;      //  (array) 取得所有store view的data  (包含id, name)

$_lang = $this->getStores() ;   //   先用variable裝住佢

$_lang->getId()              // 取得array中的store id

$_lang->getName()    // 取得array 中的store name

$_lang->getCurrentUrl()  //取得array中的url

基本上有齊以上function就能做大部份....

e.g.



<?php $curr_lang = $this->getCurrentStoreId();?>
<?php foreach ($this->getStores() as $_lang): ?>
<?php if ( $this->htmlEscape($_lang->getId())!= $curr_lang ) { ?>
        <a href="<?php echo $_lang->getCurrentUrl() ?>"><img
src="<?php echo $this->getSkinUrl('images/flag_' . $this->htmlEscape($_lang->getName()) . '.gif') ?>"
alt="<?php echo $this->htmlEscape($_lang->getName()) ?>"/></a>
<?php }?>
    <?php endforeach; ?>

沒有留言:

發佈留言