我在路径中为显示价格滑块应用了一个代码 app / design / frontend / rwd / inspire / template / catalog / layer / view.phtml
<?php
$current_catId=Mage::registry('current_category');
if($current_catId>0){
$max=Mage::getSingleton('catalog/layer')
->setCurrentCategory(Mage::registry('current_category'))
->getProductCollection()->getMaxPrice();
$max_price = round($max);
$min=Mage::getSingleton('catalog/layer')
->setCurrentCategory(Mage::registry('current_category'))
->getProductCollection()->getMinPrice();
$min_price = round($min);
}else{
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT max(price) as max_price , min(price)as
min_price FROM mage_catalog_product_index_price ORDER BY
customer_group_id');
$rows = $result->fetch();
$max_price= $rows['max_price'];
$min_price= $rows['min_price'];
}
?>
<style>
.ui-slider-horizontal{height:2px!important;}
.abc{color:#fff;background-color:#2c5987;padding-top: 2px;padding-bottom:
2px;}
.abc:hover{color:#fff;}
.ui-widget-header{background:#2874f0 !important;}
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header
.ui-state-default{border: 1px solid #2874f0 !important;background: #fff
!important;border-radius: 50% !important;outline:0;}
.btn.abc{float:right!important;}
.dp-block{display:block !important;}
.ui-slider-horizontal .ui-slider-range{height:8px!important;top:
-4px!important;}
.ui-slider-horizontal .ui-slider-handle{top:-7px!important;}
</style>
<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
<div class="block-content">
<?php echo $this->getStateHtml() ?>
<?php if ($this->getLayer()->getState()->getFilters()): ?>
<div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
<?php endif; ?>
<?php if($this->canShowOptions()): ?>
<p class="block-subtitle"></p>
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters();
?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<?php if($_filter->getName() == 'Price'): ?>
<?php else: ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if(Mage::getSingleton( 'customer/session' )->isLoggedIn()): ?>
<dd id="slider" style="height:1px"></dd>
<dd><p>
<label class="dp-block" for="amount">Price range</label> <div style="margin-left: 25%;">Rs.
<input type="text" id="amount" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');" style="border: 1px solid #ccc; color: #2c5987;text-align:center; font-weight: bold; padding: 5px 0;width: 50%;" /></div>
</p>
<div id="slider-range"></div>
</dd>
<dd>
<label class="dp-block" onclick='callPriceSlider()' style="cursor:pointer;"><br>
<button class="btn abc">Search</button>
<label>
<div class="clearfix"></div>
</dd>
</dl>
<?php endif; ?>
<script type="text/javascript">decorateDataList('narrow-by-list')
</script>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#slider-range" ).slider({
range: true,
min: <?php if($min_price == 0){echo $min_price+1;}
else
{echo $min_price;}
?>,
max: <?php echo $max_price;?>,
values: [ <?php echo $min_price;?>, <?php echo $max_price;?> ],
slide: function( event, ui ) {
$( "#amount" ).val( + ui.values[ 0 ] + " - " + ui.values[ 1 ]);
}
});
$( "#amount" ).val( $( "#slider-range" ).slider( "values", 0 ) +
" - " + $( "#slider-range" ).slider( "values", 1 ) );
});
function callPriceSlider()
{
var priceRang=$("#amount").val();
//alert(priceRang);
var urlSpl=document.URL.split('?');
//alert(urlSpl[0]+"-----"+urlSpl[1]);
var redirectUrl=urlSpl[0]+'?price='+priceRang.split(' ').join('');
//alert(redirectUrl);
document.location.href=redirectUrl;
}
</script>
但是这在我的实时站点上不起作用,但是当我在登台服务器上应用相同的代码时,它可以正常工作。我还检查了它获得的min_price和max_price值,但在浏览器错误中它显示了
之类的错误Uncaught TypeError: Cannot read property 'val' of null
at callPriceSlider (medical-devices:13385)
at HTMLLabelElement.onclick (medical-devices:13354)