2012-10-09 153 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; ?>