2012-12-12 199 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

讓我用新代碼更新我的問題。 –