php 货币切换器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 货币切换器相关的知识,希望对你有一定的参考价值。

Here, I will show you how you can change the location of currency selector to header in Magento.

By default, the currency selector is displayed in the left sidebar. Here, I will show you how you can show it in header just below the language selector.

Create a new phtml file (template/directory/currency-top.phtml) and write the following code in it :-

<?php if($this->getCurrencyCount()>1): ?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Change Country'); ?></label>

        <ul class="flag">
            <?php if(strtolower($this->getCurrentCurrencyCode()) == 'aud'): ?>
                <li class="active"><img src="<?php echo $this->getSkinUrl('images/flag-aud.png'); ?>" alt="Australia" width="17" height="11" /></li>
            <?php else: ?>
                <li><img src="<?php $imagef = 'images/flag-'.strtolower($this->getCurrentCurrencyCode()).'.jpg'; echo $this->getSkinUrl($imagef); ?>" alt="Australia" width="17" height="11" /></li>
            <?php endif; ?>
        </ul>

        <select id="select-language" name="currency" title="Your Language" onchange="changeCurrency(this)">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
            <option value="<?php echo $_code ?>"<?php if($_code==$this->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>>
                <?php echo $_name ?> - <?php echo $_code ?>
            </option>
        <?php endforeach; ?>
        </select>
</div>
<script type="text/javascript">
//<![CDATA[
function changeCurrency(sObject){
    if(sObject.value){
        setLocation('<?php echo $this->helper('directory/url')->getSwitchCurrencyUrl() ?>currency/'+sObject.value);
    }
}
//]]>
</script>
<?php endif; ?>

Add currency_top block after store_language block inside header block of page.xml present around line #66 :-

<block type="directory/currency" name="currency_top" template="directory/currency-top.phtml"/>

Add getChildHtml(‘currency_top’) below getChildHtml(‘store_language’) in template/page/html/header.phtml like below :-

<?php echo $this->getChildHtml('currency_top') ?>

А так же добавить доп Currency в настройках и Manage Currency Rates

以上是关于php 货币切换器的主要内容,如果未能解决你的问题,请参考以下文章

php WOO货币切换器的压轴折扣兼容性

php 重力Wiz //重力形式//货币转换器

php [WooCommerce货币转换器小部件]使用国家标志而不是国家代码。

woocommerce上的多种货币,可根据位置自动切换[关闭]

Java中的货币转换器具有精度和浓缩问题

Pyspark 货币转换器