Display currency selected by user on top
-
29-09-2020 - |
Question
please visit link , on top left you can see "currency" , once we mouse-over we can see list of store view names and currency assigned to each store.
what i want is if user select "Euro" ,
it should display the currency : [€] on top,
for US Dollar, it should display currency : [$]
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<ul id="select-language" title="<?php echo $this->__('Currency') ?>" class="dropDownMenu">
<li><a href=""><?php echo $this->__('Currency') ?></a>
<ul>
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' class="selected"' : '' ?>
<li <?php echo $_selected ?>>
<a href="<?php echo $_lang->getCurrentUrl() ?>"><?php echo $this->escapeHtml($_lang->getName()) ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
</ul>
</div>
<?php endif; ?>
Solution
Replace this :
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<ul id="select-language" title="<?php echo $this->__('Currency') ?>" class="dropDownMenu">
<li><a href=""><?php echo $this->__('Currency') ?></a>
<ul>
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' class="selected"' : '' ?>
<li <?php echo $_selected ?>>
<a href="<?php echo $_lang->getCurrentUrl() ?>"><?php echo $this->escapeHtml($_lang->getName()) ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
</ul>
</div>
<?php endif; ?>
WITH :
<?php if(count($this->getStores())>1): ?>
<?php
$lis = "";
$selCurrency = $this->__('Currency');
foreach ($this->getStores() as $_lang):
if($_lang->getId() == $this->getCurrentStoreId()){
//This line will show SYMBOL only
//$selCurrency = "[".Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()."]";
//This line will show FULLNAME
$selCurrency = $this->escapeHtml($_lang->getName());
}
$lis .= '<li><a href="'.$_lang->getCurrentUrl().'">'.$this->escapeHtml($_lang->getName()).'</a></li>';
endforeach;
?>
<div class="form-language">
<ul id="select-language" title="<?php echo $this->__('Currency') ?>" class="dropDownMenu">
<li><a href=""><?php echo $selCurrency ?></a>
<ul>
<?php echo $lis ?>
</ul>
</li>
</ul>
</div>
<?php endif; ?>
OTHER TIPS
Try is code. It may help you
<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-language">
<label for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
<select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
<?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 $_code ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
try this
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<ul id="select-language" title="<?php echo $this->__('Currency') ?>" class="dropDownMenu">
<li><a href=""><?php echo $this->__('Currency') ?></a>
<ul>
<?php
$select="";
$other="";
foreach ($this->getStores() as $_lang): ?>
<?php if($_lang->getId() == $this->getCurrentStoreId()) { $select='<li class="selected">
<a href="'.$_lang->getCurrentUrl().'">'.$this->escapeHtml($_lang->getName()).'</a>
</li>'; } else {
$other .='<li >
<a href="'.$_lang->getCurrentUrl().'">'.$this->escapeHtml($_lang->getName()).'</a>
</li>';
}
endforeach; echo $select; echo $other; ?>
</ul>
</li>
</ul>
</div>
<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange