0

我对 Magento 货币有疑问:否则我的代码工作正常,现在我想在更改货币后重定向页面。

假设我当前的 URL 是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; ?>
4

1 回答 1

0

您应该将这些参数添加到新的 url:

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

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

于 2012-12-12T10:06:00.897 回答