2012-10-09 58 views
1

在我的項目中,我必須以兩種語言顯示網店。 默認情況下,您可以選擇下面的代碼語言:Magento更改語言選擇器

應用程序/設計/前端/基/默認/模板/頁/開關/ language.phtml

<?php if(count($this->getStores())>1): ?> 
<div class="form-language"> 
<label for="select-language"><?php echo $this->__('Your Language:') ?></label> 
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value"> 
<?php foreach ($this->getStores() as $_lang): ?> 
    <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?> 
    <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php  echo $this->htmlEscape($_lang->getName()) ?></option> 
<?php endforeach; ?> 
</select> 
</div> 
<?php endif; ?> 

這當然displaya選擇框選項是所有的語言。

但是我想改變它,使它成爲單獨的鏈接。 我只是不知道如何做到這一點。

這是我現在有。

<?php if(count($this->getStores())>1): ?> 
<div class="form-language"> 
<?php foreach ($this->getStores() as $_lang):?> 
    <a href="" title=""><?php echo $this->htmlEscape($_lang->getName()) ?></a> 
<?php endforeach;?> 
</div> 
<?php endif; ?> 

PS:我沒有默認的Magento代碼改變這一點。我在app/design/frontend/default/projectname/template/page/switch/language.phtml中工作。

所以我是自己用這個代碼得到這個工作:

<?php if(count($this->getStores())>1): ?> 
<div class="form-language"> 
<?php foreach ($this->getStores() as $_lang):?> 
    <a href="<?php echo Mage::getUrl() . '?___store=' . $_lang->getId()?>" title=""><?php echo $this->htmlEscape($_lang->getName()) ?></a> 
<?php endforeach;?> 
</div> 
<?php endif; ?> 

但現在當我切換語言。它重定向到主頁。 我發現我應該使用:

$_lang->getCurrentUrl() 

但我不知道在哪裏把這個在我的代碼。

+0

在我的magento版本(最新的企業版)中,它已經是一個包含單獨鏈接的列表。我不確定這個版本有哪些變化,也許你可以採用更新的magento版本? –

+0

嗯,我有最新的.. 奇怪:P – Weszzz7

回答

4

你非常接近,你只需要包含網址!

<?php if(count($this->getStores())>1): ?> 
<div class="form-language"> 
<?php foreach ($this->getStores() as $_lang):?> 
    <a href="<?php echo $_lang->getCurrentUrl() ?>" title="<?php echo $this->htmlEscape($_lang->getName()) ?>"><?php echo $this->htmlEscape($_lang->getName()) ?></a> 
<?php endforeach;?> 
</div> 
<?php endif; ?> 
+0

嗯,謝謝你:) 不知何故,我認爲我需要法師:: getUrl(),我什至沒有想到它做了什麼.. – Weszzz7

1

這與企業社區相比似乎有所不同。這就是Magento Enterprise v1.12中的代碼。也許它是有用的,或者它也可以。

<?php if(count($this->getStores())>1): ?> 
<div class="switch switcher-language"> 
    <label><?php echo $this->__('Language') ?>:</label> 
    <div class="switch-wrapper" id="languageSelect"> 
     <strong class="current language-<?php echo $this->htmlEscape(Mage::app()->getStore()->getCode()) ?>"> 
      <?php echo $this->htmlEscape(Mage::app()->getStore()->getName()) ?> 
     </strong> 
     <span class="switcher-holder">(<span onclick="popUpMenu(this);" class="switcher"><?php echo $this->__('Change')?></span>)</span> 
     <ul style="display:none" id="popId-languageSelect"> 
      <li class="current language-<?php echo $this->htmlEscape(Mage::app()->getStore()->getCode()) ?>"> 
       <span><?php echo $this->htmlEscape(Mage::app()->getStore()->getName()) ?></span> 
      </li> 
      <?php foreach ($this->getStores() as $_lang): ?> 
       <?php if($_lang->getId()!=$this->getCurrentStoreId()): ?> 
        <li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>"> 
         <a href="<?php echo $_lang->getCurrentUrl() ?>"><?php echo $this->htmlEscape($_lang->getName()) ?></a> 
        </li> 
       <?php endif; ?> 
      <?php endforeach; ?> 
     </ul> 
    </div> 
</div> 
<?php endif; ?> 
+0

啊這可能會幫助誰使用企業誰正在尋找相同的東西我:) – Weszzz7

0

試試看看這個代碼。我在EE 1.12中進行了測試。

<?php if(count($this->getStores())>1): ?> 
    <ul> 
    <?php foreach ($this->getStores() as $_lang): ?> 
     <?php if($_lang->getId()!=$this->getCurrentStoreId()): ?> 
     <li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>"> 
     <a href="<?php echo $_lang->getCurrentUrl() ?>"><?php echo $this->htmlEscape($_lang->getName()) ?></a> 
     </li> 
     <?php endif; ?> 
    <?php endforeach; ?> 
    </ul> 
    <?php endif; ?>