2012-12-12 88 views
0

我有一个Magento货币的问题:我的代码工作正常,否则,现在我想在货币更改后重定向页面。Magento设置多种货币

假设我目前的网址为http://www.example.com/women/?color=black

现在,当我更改货币时,它将重定向到:http://www.example.com/women/;所以它删除了?color=black

代码:

if($this->getCurrencyCount()>1): ?> 
<div class="block block-currency"> 
    <div class="block-title"> 
     <strong><span><?php echo $this->__('Select Your Currency') ?></span></strong> 
    </div> 
    <div class="block-content"> 
     <select name="currency" title="<?php echo $this->__('Select Your Currency') ?>" onchange="setLocation(this.value)"> 
     <?php foreach ($this->getCurrencies() as $_code => $_name): ?> 
      <option value="<?php echo $this->getSwitchCurrencyUrl($_code) ?>"<?php if($_code==$this->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>> 
       <?php echo $_name ?> - <?php echo $_code ?> 
      </option> 
     <?php endforeach; ?> 
     </select> 
    </div> 
</div> 
<?php endif; 

更新的代码:

<?PHP $currentParams = $this->getRequest()->getParams(); ?> 
<div style="float:left; margin-top:10px; color:#727478;"> 
    <!--Change 1 to 0 if you wish to output selector always--> 
    <?php if($this->getCurrencyCount() > 1): ?> 
    <span>Select Currency:</span> 

    <select name="custom-currency-selector" id="custom-currency-selector"> 
    <?php foreach ($this->getCurrencies() as $_code => $_name): 
       $currencyUrl = $this->getSwitchCurrencyUrl($_code); 
       foreach ($currentParams as $_param) { 
        $currencyUrl = $this->helper('core/url')->addRequestParam($currencyUrl, $_param); 
       } 
       ?> 
     <option value="<?php echo $currencyUrl; ?>" 
      <?php if($_code == $this->getCurrentCurrencyCode()): ?> 
       selected="SELECTED" 
      <?php endif; ?>> 
      <?php echo $_code ?> 
     </option> 
    <?php endforeach; ?> 
    </select> 
    <?php endif;?> 

更新的代码:

<!--Change 1 to 0 if you wish to output selector always--> 
    <?php if($this->getCurrencyCount() > 1): 
    $currentParams = $this->getRequest()->getParams(); 
    ?> 
    <span>Select Currency:</span> 
    <select name="custom-currency-selector" id="custom-currency-selector"> 
    <?php foreach ($this->getCurrencies() as $_code => $_name): 
    $currencyUrl = $this->helper('core/url')->addRequestParam($this->getSwitchCurrencyUrl($_code),$currentParams) 
    ?> 
     <option value="<?php echo $currencyUrl ?>" 
      <?php if($_code == $this->getCurrentCurrencyCode()): ?> 
       selected="SELECTED" 
      <?php endif; ?>> 
      <?php echo $_code ?> 
     </option> 
    <?php endforeach; ?> 
    </select> 
    <?php endif; ?> 

回答

0

您应该将这些PARAMS添加到新网址:

$currentParams = $this->getRequest()->getParams(); 
$currencyUrl = $this->helper('core/url')->addRequestParam(
    $this->getSwitchCurrencyUrl($_code), 
    $currentParams 
) 

然后使用$ currencyUrl作为重定向的url。

+0

仍然是同样的问题.. –

+0

也许你在错误的地方使用它。在我提出的一段代码之后,什么网址包含$ currencyUrl? –

+0

让我用新代码更新我的问题。 –