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
)

次に、リダイレクトのURLとして$currencyUrlを使用します。

于 2012-12-12T10:06:00.897 に答える