All popular questions related to OS Property will be posted here

How to change money format on slider

  • Mr. Dam
  • Topic Author
  • Online
  • Administrator
  • Administrator
More
10 years 3 months ago #48767 by Mr. Dam
How to change money format on slider was created by Mr. Dam
Hi,
Some customers ask us that they want to change the money format on the "Price" slider in the search form. The current money format is: 12,456,789
They want to change to: 12.456.789 And here is the solution.
1. Open file:
components > com_osproperty > helpers > helper.php
2 Find
public static function showPriceFilter($option_id,$min_price,$max_price,$property_type,$style,$prefix){
global $configClass;

$document = JFactory::getDocument();
$db = JFactory::getDbo();
$db->setQuery("Select price from #__osrs_properties order by price desc limit 1");
$max_price_value = $db->loadResult();
$db->setQuery("Select price from #__osrs_properties order by price limit 1");
$min_price_value = $db->loadResult();

if(intval($max_price) == 0){
$max_price = $max_price_value;
}
if($min_price_value == $max_price_value){
$min_price_value = 0;
}
if($configClass == 1){
?>

<?php

$document->addStyleSheet("//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css");
//$document->addScript(" code.jquery.com/ui/1.10.4/jquery-ui.js ");
?>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js" type="text/javascript"></script>
<?php
$document->addScript(JURI::root()."components/com_osproperty/js/autoNumeric.js");
?>
<script>
jQuery.ui.slider.prototype.widgetEventPrefix = 'slider';
jQuery(function() {
jQuery( "#<?php echo $prefix;?>sliderange" ).slider({
range: true,
min: <?php echo intval($min_price_value);?>,
max: <?php echo intval($max_price_value);?>,
values: [ <?php echo intval($min_price);?>, <?php echo intval($max_price);?> ],
slide: function( event, ui ) {
var price_from = ui.values[ 0 ];
var price_to = ui.values[ 1 ];
jQuery( "#<?php echo $prefix;?>price_from_input1" ).val( price_from );
jQuery( "#<?php echo $prefix;?>price_to_input1" ).val( price_to );

price_from = price_from.formatMoney(0,',','.');
price_to = price_to.formatMoney(0,',','.');

jQuery( "#<?php echo $prefix;?>price_from_input" ).text( price_from );
jQuery( "#<?php echo $prefix;?>price_to_input" ).text( price_to );
}
});
});
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) {
var n = this,
decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
decSeparator = decSeparator == undefined ? "." : decSeparator,
thouSeparator = thouSeparator == undefined ? "," : thouSeparator,
sign = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};
</script>
<div id="<?php echo $prefix;?>sliderange"></div>
<div class="clearfix"></div>
<?php
if(strpos($prefix,"adv") === FALSE)
{
$span = "span5";
$style = "margin-top:10px;margin-left:0px;";
$style1 = "text-align:right;";
$style2 = "text-align:left;";
$input_class_name = "input-mini";
}else
{
$span = "span6";
$style = "";
$style1 = "margin-top:10px;margin-left:0px;text-align:left;";
$style2 = "margin-top:10px;margin-left:0px;text-align:right;";
$input_class_name = "input-small";
}
?>
<div class="row-fluid">
<div class="<?php echo $span?>" style="<?php echo $style;?><?php echo $style1?>">
<?php if(strpos($prefix,"adv") !== FALSE){?>
<?php echo JText::_('OS_MIN')?>(<?php echo HelperOspropertyCommon::loadCurrency();?>).
<?php } ?>
<!-- <input type="text" name="min_price_show" id="<?php echo $prefix;?>price_from_input" value="<?php echo number_format($min_price,0,'',',');?>" class="<?php echo $input_class_name;?>" disabled/> -->
<span id="<?php echo $prefix;?>price_from_input"><?php echo number_format($min_price,0,'',',');?></span>
<input type="hidden" name="min_prmin_price_showice" id="<?php echo $prefix;?>price_from_input1" value="<?php echo $min_price;?>"/>
</div>
<?php
if(strpos($prefix,"adv") === FALSE)
{
?>
<div class="span2" style="margin-left:0px;margin-top:10px;text-align:center;">
-
</div>
<?php }?>
<div class="<?php echo $span?>" style="<?php echo $style;?><?php echo $style2?>">
<?php if(strpos($prefix,"adv") !== FALSE){?>
<?php echo JText::_('OS_MAX')?>(<?php echo HelperOspropertyCommon::loadCurrency();?>).
<?php } ?>
<!-- <input type="text" name="max_price_show" id="<?php echo $prefix;?>price_to_input" value="<?php echo number_format($max_price,0,'',',');?>" class="<?php echo $input_class_name;?>" disabled/>-->
<span id="<?php echo $prefix;?>price_to_input"><?php echo number_format($max_price,0,'',',');?></span>
<input type="hidden" name="max_price" id="<?php echo $prefix;?>price_to_input1" value="<?php echo $max_price;?>"/>
</div>
</div>
<?php
}else{
echo HelperOspropertyCommon::generatePriceList($property_type,$price,$style);
}


and replace by
public static function showPriceFilter($option_id,$min_price,$max_price,$property_type,$style,$prefix){
global $configClass;

$document = JFactory::getDocument();
$db = JFactory::getDbo();
$db->setQuery("Select price from #__osrs_properties order by price desc limit 1");
$max_price_value = $db->loadResult();
$db->setQuery("Select price from #__osrs_properties order by price limit 1");
$min_price_value = $db->loadResult();

if(intval($max_price) == 0){
$max_price = $max_price_value;
}
if($min_price_value == $max_price_value){
$min_price_value = 0;
}
if($configClass == 1){
?>

<?php

$document->addStyleSheet(" code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css ");
//$document->addScript(" code.jquery.com/ui/1.10.4/jquery-ui.js ");
?>
<script src=" code.jquery.com/ui/1.10.4/jquery-ui.js " type="text/javascript">
<?php
$document->addScript(JURI::root()."components/com_osproperty/js/autoNumeric.js");
?>
<script>
jQuery.ui.slider.prototype.widgetEventPrefix = 'slider';
jQuery(function() {
jQuery( "#<?php echo $prefix;?>sliderange" ).slider({
range: true,
min: <?php echo intval($min_price_value);?>,
max: <?php echo intval($max_price_value);?>,
values: [ <?php echo intval($min_price);?>, <?php echo intval($max_price);?> ],
slide: function( event, ui ) {
var price_from = ui.values[ 0 ];
var price_to = ui.values[ 1 ];
jQuery( "#<?php echo $prefix;?>price_from_input1" ).val( price_from );
jQuery( "#<?php echo $prefix;?>price_to_input1" ).val( price_to );

price_from = price_from.formatMoney(0,'.',',');
price_to = price_to.formatMoney(0,'.',',');

jQuery( "#<?php echo $prefix;?>price_from_input" ).text( price_from );
jQuery( "#<?php echo $prefix;?>price_to_input" ).text( price_to );
}
});
});
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) {
var n = this,
decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
decSeparator = decSeparator == undefined ? "," : decSeparator,
thouSeparator = thouSeparator == undefined ? "." : thouSeparator,
sign = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};
</script>
<div id="<?php echo $prefix;?>sliderange"></div>
<div class="clearfix"></div>
<?php
if(strpos($prefix,"adv") === FALSE)
{
$span = "span5";
$style = "margin-top:10px;margin-left:0px;";
$style1 = "text-align:right;";
$style2 = "text-align:left;";
$input_class_name = "input-mini";
}else
{
$span = "span6";
$style = "";
$style1 = "margin-top:10px;margin-left:0px;text-align:left;";
$style2 = "margin-top:10px;margin-left:0px;text-align:right;";
$input_class_name = "input-small";
}
?>
<div class="row-fluid">
<div class="<?php echo $span?>" style="<?php echo $style;?><?php echo $style1?>">
<?php if(strpos($prefix,"adv") !== FALSE){?>
<?php echo JText::_('OS_MIN')?>.
<?php } ?>
<!-- <input type="text" name="min_price_show" id="<?php echo $prefix;?>price_from_input" value="<?php echo number_format($min_price,0,'',',');?>" class="<?php echo $input_class_name;?>" disabled/> -->
<span id="<?php echo $prefix;?>price_from_input"><?php echo number_format($min_price,0,'','.');?></span>
<input type="hidden" name="min_prmin_price_showice" id="<?php echo $prefix;?>price_from_input1" value="<?php echo $min_price;?>"/>
</div>
<?php
if(strpos($prefix,"adv") === FALSE)
{
?>
<div class="span2" style="margin-left:0px;margin-top:10px;text-align:center;">
-
</div>
<?php }?>
<div class="<?php echo $span?>" style="<?php echo $style;?><?php echo $style2?>">
<?php if(strpos($prefix,"adv") !== FALSE){?>
<?php echo JText::_('OS_MAX')?>.
<?php } ?>
<!-- <input type="text" name="max_price_show" id="<?php echo $prefix;?>price_to_input" value="<?php echo number_format($max_price,0,'',',');?>" class="<?php echo $input_class_name;?>" disabled/>-->
<span id="<?php echo $prefix;?>price_to_input"><?php echo number_format($max_price,0,'','.');?></span>
<input type="hidden" name="max_price" id="<?php echo $prefix;?>price_to_input1" value="<?php echo $max_price;?>"/>
</div>
</div>
<?php
}else{
echo HelperOspropertyCommon::generatePriceList($property_type,$price,$style);
}


Good luck
Dam
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: Mr. DamNguyen Phu Quan