I would like to ask for help with the following topic!
We use SJ Filter for VirtueMart on our website! However the price filter uses price without tax. It's not good this way.I think the system uses the "base price" (without tax).I would like the filter use "end user price" with tax.(27.tax).I didn't find anything in the setting. I attached files from filter.I checked the code but I couldn't find anything that I could change.
Please someone help !
enter image description here
enter image description here
<?php
/**
* #package SJ Filter for VirtueMart
* #version 2.0.0
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* #copyright (c) 2014 YouTech Company. All Rights Reserved.
* #author YouTech Company http://www.smartaddons.com
*/
defined ('_JEXEC') or die;
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function ($) {
;
(function (element) {
var $element = $(element),
$_ft_form = $('.ft-form', $element),
$_group_ft = $('.ft-group', $element),
$_filtering = $('.ft-filtering', $element)
$_ajax_url = '<?php echo (string)JURI::getInstance(); ?>';
var $_gr_prices = $('.ft-group-prices', $element),
$_slide_prices = $(".ft-slider-price", $_gr_prices),
_min_price = <?php echo (int)$params->get('price_min',0); ?>,
_max_price = <?php echo (int)$params->get('price_max',1300000); ?>;
var $timer = 0;
$_slide_prices.each(function (index, element) {
$(this)[index].slide = null;
});
$_slide_prices.slider({
range: true,
min: _min_price,
max: _max_price,
values: [_min_price, _max_price],
slide: function (event, ui) {
$(".ft-price-min", $_gr_prices).val(ui.values[0]);
$(".ft-price-max", $_gr_prices).val(ui.values[1]);
if ($timer) {
clearTimeout($timer);
}
$timer = setTimeout(
function () {
processAjax()
}, 1000);
}
});
$('.ft-price-input', $_gr_prices).on('keyup', function () {
var $that = $(this);
if ($timer) {
clearTimeout($timer);
}
var _price_tmp = parseInt($that.val());
$timer = setTimeout(function () {
if (!isNaN(_price_tmp) && _price_tmp >= 1) {
_price_tmp = _price_tmp >= _max_price ? _max_price : _price_tmp;
if ($that.hasClass('ft-price-min')) {
var _maxp = $(".ft-price-max", $_gr_prices).val();
_maxp = (_maxp != '' ) ? _maxp : _max_price;
_price_tmp = _price_tmp >= _maxp ? _maxp : _price_tmp;
$that.val(_price_tmp);
$_slide_prices.slider("values", 0, _price_tmp);
} else {
var _minp = $(".ft-price-min", $_gr_prices).val();
_minp = (_minp != '' ) ? _minp : _min_price;
_price_tmp = (_price_tmp >= _minp && _price_tmp <= _max_price ) ? _price_tmp : _minp;
$that.val(_price_tmp);
$_slide_prices.slider("values", 1, _price_tmp);
}
} else {
if ($that.hasClass('ft-price-min')) {
$that.val('');
$_slide_prices.slider("values", 0, _min_price);
} else {
$that.val('');
$_slide_prices.slider("values", 1, _max_price);
}
}
processAjax();
}, 1000);
});
// var $_open_close = $('.ft-open-close ', $_group_ft);
// $_open_close.on('click ', function () {
// var $_parent = $(this).parents('.ft-heading');
// $_parent.siblings('.ft-content').stop(true, false).slideToggle(400, function () {
// if ($_parent.parent().hasClass('ft-open')) {
// $_parent.parent().removeClass('ft-open').addClass('ft-close');
// }
// else {
// $_parent.parent().removeClass('ft-close').addClass('ft-open');
// }
// });
//
// });
var $_ft_heading = $('.ft-heading', $_group_ft);
$_ft_heading.on('click', function () {
$(this).siblings('.ft-content').stop(true, false).slideToggle(400, function () {
if ($(this).parent().hasClass('ft-open')) {
$(this).parent().removeClass('ft-open').addClass('ft-close');
} else {
$(this).parent().removeClass('ft-close').addClass('ft-open');
}
});
});
if ($('.ft-group', $element).width() <= 200) {
$('.sj-vm-filter .ft-content-prices .ft-price-value input[type="text"]').css('width', '38px');
}
//.ft-opt-count
var $_label_opt = $('.ft-opt-name, .ft-color-value', $_group_ft);
$_label_opt.on('click ', function () {
var _input_check = $(this).siblings('input[type="checkbox"]'),
_checked = _input_check.prop('checked'),
_color_value = $(this).is('.ft-color-value');
if (_checked) {
if (_color_value) {
$(this).removeClass('ft-checked');
}
_input_check.removeAttr('checked');
} else {
if (_color_value) {
$(this).addClass('ft-checked');
}
_input_check.attr('checked', 'checked');
}
processAjax();
});
function showClearAll() {
var $ft_content = $('.ft-content', $_group_ft);
$ft_content.each(function () {
var $that = $(this);
var $i = 0;
$(':input', $that).each(function () {
if ($(this).prop('checked')) {
$i++;
}
});
if ($i > 0) {
$('.ft-opt-clearall', $that).fadeIn(500);
} else {
$('.ft-opt-clearall', $that).fadeOut(500);
}
});
}
$('input[type="hidden"]', $element).val('');
$('input[type="hidden"]', $_group_ft).val('');
$(':checkbox ', $_group_ft).removeAttr('checked');
$(':checkbox ', $_group_ft).on('click', function () {
processAjax();
});
$('.ft-opt-clearall', $_group_ft).unbind('click.clearall').on('click.clearall', function () {
var _ft_select = $(this).siblings('.ft-select');
$('input[type="checkbox"]', _ft_select).removeAttr('checked');
$('.ft-color-value', _ft_select).removeClass('ft-checked');
processAjax();
});
var _config_global = '';
function processAjax() {
var fields = $(":input", $element).serialize();
_config_global = fields;
showClearAll();
var _loading = $('<div class="sj-loading" ><div class="ft-image-loading"></div></div>');
$("body").append(_loading);
$.ajax({
type: 'POST',
url: $_ajax_url,
data: {
is_ajax_ft: 1,
ft_module_id: <?php echo $module->id ?>,
_config_data: _config_global
},
success: function (data) {
_loading.remove();
if (data.items_markup != '') {
$('.ft-filtering', $_ft_form).replaceWith(data.items_markup);
updateAfterLoadAjax();
}
if (data.filter_product != '') {
if ($('<?php echo $params->get('area_results'); ?>').length) {
$('<?php echo $params->get('area_results'); ?>').html(data.filter_product);
updateAfterLoadAjax();
}
}
if (data == 'noresults') {
window.location.href = $_ajax_url;
}
},
error: function () {
_loading.remove();
},
dataType: 'json'
});
}
var parseQueryString = function (queryString) {
var params = {}, queries, temp, i, l;
queries = queryString.split("&");
for (i = 0, l = queries.length; i < l; i++) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
return params;
};
function updateAfterLoadAjax() {
if(typeof Virtuemart !== 'undefined'){
var $_form = $("form.product");
Virtuemart.product($_form);
}
var $_ft_result = $('#ft_results_<?php echo $module->id; ?>');
$('.orderlistcontainer', $_ft_result).hover(
function () {
$(this).find('.orderlist').stop().show()
},
function () {
$(this).find('.orderlist').stop().hide()
}
)
var $_orderList = $('.orderlist', $_ft_result);
if ($_orderList.length > 0) {
$_orderList.children().on('click', function () {
var _href = $('a ', $(this)).attr('href');
_href = _href.replace(/\?/g, '&').replace('by,', 'orderby=');
_href = _href.replace(/\//g, '&');
var _orderby = parseQueryString(_href);
$('.config-orderby', $element).attr('value', _orderby.orderby);
processAjax();
return false;
});
}
var $_selectbox = $('select.inputbox', $_ft_result);
var _limit = $('option:selected', $_selectbox).text();
$('option:selected', $_selectbox).each(function(){
var _limit = $(this).text();
$('.config-limit', $element).attr('value', _limit);
$_selectbox.removeAttr('onchange');
$_selectbox.on('change', function () {
var _value = $('option:selected', $(this)).text();
$('.config-limit', $element).attr('value', _value);
processAjax();
return false;
});
});
//add product_load_limit last run processAjax() in select box
var pro_load = "<?php echo $params->get('limit_results',5)?>";
var url_option = "<?php echo JURI::base(true).'/?limit=';?>";
var _option = '<option value="' + url_option + pro_load + '">' + pro_load + '</option>';
var $_selectbox_2 = $('select.inputbox option:first', $_ft_result);
if ($_selectbox_2.text() != pro_load) {
$_selectbox_2.before(_option);
}
var $vm_pagination = $('.vm-pagination ul', $_ft_result);
if ($vm_pagination.length > 0) {
$vm_pagination.children().on('click', function () {
var $this = $(this);
if ($this.is('.disabled') || $this.is('.active')) {
return false;
} else {
var _href = $('a ', $(this)).attr('href');
_href = _href.replace(/\?/g, '&').replace('results,', 'limit_start=');
_href = _href.replace(/\//g, '&');
var _lmstart = parseQueryString(_href);
var _start = 0;
if (typeof _lmstart.limit_start != 'undefined') {
_start = _lmstart.limit_start
_start = _start.split("-");
_start = _start[1];
} else if (typeof _lmstart.start != 'undefined') {
_start = _lmstart.start;
}
$('.config-limitstart', $element).attr('value', _start);
processAjax();
}
return false;
});
}
// Click Button
function display(view) {
jQuery('.browse-view .row').removeClass('vm-list vm-grid').addClass(view);
jQuery('.icon-list-grid .vm-view').removeClass('active');
if(view == 'vm-list') {
jQuery('.browse-view .product').addClass('col-lg-12 product-full');
jQuery('.browse-view .product .product-left').addClass('col-md-4');
jQuery('.browse-view .product .product-right').addClass('col-md-8');
jQuery('.icon-list-grid .' + view).addClass('active');
}else{
jQuery('.browse-view .product').removeClass('col-lg-12 product-full');
jQuery('.browse-view .product .product-left').removeClass('col-md-4');
jQuery('.browse-view .product .product-right').removeClass('col-md-8');
jQuery('.icon-list-grid .' + view).addClass('active');
}
}
jQuery('.vm-view-list .vm-view').each(function() {
var ua = navigator.userAgent,
event = (ua.match(/iPad/i)) ? 'touchstart' : 'click';
jQuery('.vm-view-list .vm-view').bind(event, function() {
jQuery(this).addClass(function() {
if(jQuery(this).hasClass('active')) return '';
return 'active';
});
jQuery(this).siblings('.vm-view').removeClass('active');
catalog_mode = jQuery(this).data('view');
display(catalog_mode);
});
});
var $_filtering = $('.ft-filtering', $element), _ft_opt_close = $('.ft-opt-close', $_filtering),
_filtering_clearall = $('.ft-filtering-clearall', $_filtering);
_ft_opt_close.on('click', function () {
var _data_value = $(this).parent().attr('data-filter'),
_cls_ft = $('.' + _data_value);
if (_cls_ft.length > 0) {
$(':checkbox', _cls_ft).removeAttr('checked');
$(_cls_ft).attr('value', '');
$('.ft-color-value', _cls_ft).removeClass('ft-checked');
processAjax();
}
});
_filtering_clearall.on('click', function () {
var _opt_inner = $('.ft-opt-inner', $_filtering);
if (_opt_inner.length > 0) {
_opt_inner.each(function () {
var _data_value = $(this).attr('data-filter'),
_cls_ft = $('.' + _data_value);
$(':checkbox', _cls_ft).removeAttr('checked');
$(_cls_ft).attr('value', '');
$('.ft-color-value', _cls_ft).removeClass('ft-checked');
});
processAjax();
}
});
}
})('#<?php echo $tag_id; ?>');
});
//]]>
</script>
I am trying to fill a dropdown using Ajax and PHP with JQuery. For some reason, I always get a Parse JSON Error.
JS file
function loadRolesToDropDown() {
var url = 'controller/get_all_roles.php';
$.ajax({
url: url,
type: 'GET',
dataType: 'JSON',
success: function (data) {
var len = data.length;
$("#roledropdown").empty();
for (var i = 0; i < len; i++) {
var roleId = data[i]['roleId'];
var roleName = data[i]['roleName'];
$("#roledropdown").append("<option value='" + roleId + "'>" + roleName + "</option>");
}
},
error: function (x, e) {
if (x.status == 0) {
alert('You are offline!!\n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internal Server Error.');
} else if (e == 'parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknown Error.\n' + x.responseText);
}
}
});
}
get_all_roles.php
$roleDaoImpl = new RoleDaoImpl($pdo);
$roleDaoImpl->getAllRoles();
Implementation of getAllRoles()
function getAllRoles()
{
$roleList[] = "";
try {
$SQL = "CALL getAllRoles()";
$sp_getAllRoles = $this->connection->prepare($SQL);
$sp_getAllRoles->execute();
$resultSet = $sp_getAllRoles->fetchAll(PDO::FETCH_ASSOC);
foreach ($resultSet as $row) {
$roleId = $row['role_id'];
$roleName = $row['role_name'];
$roleList[] = array("roleId" => $roleId, "roleName" => $roleName);
}
echo json_encode($roleList);
} catch (PDOException $e) {
die($e->getMessage());
}
}
And when I tried to echo what's return by json_encode($roleList); I get the ff:
["",{"roleId":1,"roleName":"Administrator"},{"roleId":2,"roleName":"Teacher"},{"roleId":3,"roleName":"Student"}]
What is the correct way to parse the php object array return by php?
Thank you.
In your php function getAllRoles
function getAllRoles()
{
$roleList[] = ""; // -> should be $roleList = [];
In your get_all_roles.php if you are getting such type of result from query then this code will work
$resultSet = array(0=>array('role_id'=>1,'role_name'=>'Administrator'),1=>array('role_id'=>2,'role_name'=>'Teacher'),2=>array('role_id'=>3,'role_name'=>'Student'));
foreach ($resultSet as $row) {
$roleId = $row['role_id'];
$roleName = $row['role_name'];
$roleList[] = array("roleId" => $roleId, "roleName" => $roleName);
}
echo json_encode($roleList);
i have a live searcher thats when its data its shows
i need to alert if the data is empty
this is the jquery:
$(document).ready(function() {
$('#q').on('input', function() {
var searchKeyword = $(this).val();
if (searchKeyword.length >= 3) {
$.post('/files/assets/php/ajax/search.php', { q: searchKeyword }, function(data) {
$('ul#content').show();
$('ul#content').empty()
$.each(data, function() {
if ( data.length == 0 ) {
$('ul#content').append('<li style="text-align: center;font-weight:bold;"><font color="white">empty</font></a></li>');
}else{
$('ul#content').append('<li style="text-align: center;font-weight:bold;"><font color="white">' + this.title + '</font></li>');
}
});
}, "json");
}
});
});
and the php:
$conexion = mysqli_connect($serv,$user,$pass,$base);
$arr = array();
if (!empty($_POST['q'])) {
$keywords = $Main->limpiar($_POST['q']);
$mysqli = $conexion;
$result = $mysqli->query("SELECT cat, titulo FROM pinturas WHERE titulo LIKE '%".$keywords."%' OR cat LIKE '%".$keywords."%'");
if ($result->num_rows > 0) {
while ($obj = $result->fetch_array()) {
$seo = str_replace(" ","_",$obj['titulo']);
$arr[] = array('id' => $obj['cat'], 'title' => $obj['titulo'], 'seo' => $seo);
}
}else{
$arr[] = array('id' => '', 'title' => '', 'seo' => '');
}
}
echo json_encode($arr);
i want to if the data is empty shows the append empty
but it dont work
Assuming the data is a JSON parsed object you can:
Object.keys(data).length === 0
Or
JSON.stingify(data) === '{}'
Check length of the records before iteration (using $.each in jquery API)
<script>
$(document).ready(function () {
$('#q').on('input', function () {
var searchKeyword = $(this).val();
if (searchKeyword.length >= 3) {
$.post('/files/assets/php/ajax/search.php', { q: searchKeyword }, function (data) {
console.log(data);
$('ul#content').show();
$('ul#content').empty()
if (data.length == 0) {
$('ul#content').empty().append('<li style="text-align: center;font-weight:bold;"><font color="white">empty</font></a></li>');
}
else {
$.each(data, function () {
$('ul#content').append('<li style="text-align: center;font-weight:bold;"><font color="white">' + this.title + '</font></li>');
});
}
});
}
});
});
</script>
Worked for me.
Hope this helps.
Im using Zend Framework ..in one of my phtml file's i have this code
<script>
function foobar(id,type){
var idarray = <?php AppNamespace_General::getparentids( ?>id, type<?php ) ?>; // here the id and type are from js
//the php function returns a json array to the js variable
......
location.href = baseurl +'/somepage/id/'+id;
}
How can i correctly pass the js elements to the php function
The php function(Already thought of doing it via ajax..its quite complex)
public static function getparentids($id, $type, $elmarray = '') {
if (empty($elmarray)) { //avoiding redeclaration of array
$elmarray = array();
}
switch (strtolower($type)) {
case 'group':
case 'product':
case 'specification':
$gp_handler = new PackAssist_Model_DbTable_Groups();
$q = "SELECT * FROM t_groups WHERE group_id = $id";
$sql = $gp_handler->getAdapter()->query($q);
break;
case 'part':
$pt_handler = new PackAssist_Model_DbTable_Parts();
$q = "SELECT * FROM t_parts WHERE part_id = $id";
$sql = $pt_handler->getAdapter()->query($q);
break;
}
$result = $sql->fetchAll();
$i = 0;
if (count($result) > 0) {
foreach ($result as $row) {
if (isset($row['group_parent_id']) && $row['group_parent_id'] != 0) {
if (in_array($row['group_id'], $elmarray)) {
$e = $row['group_parent_id'];
} else if ($row['group_parent_id'] != 0) {
$e = $row['group_id'];
}
} else if (isset($row['part_group_id'])) {
$e = $row['part_group_id'];
} else if ($row['group_parent_id'] == 0) {
break;
}
if (isset($e) && !empty($e)) {
array_push($elmarray, $e);
}
self::getparentids($e, 'group', $elmarray);
$i++;
}
} else {
array_push($elmarray, $id);
}
array_pop($elmarray); //removing the group of super parent group which we dont need
if ($i == 0) { // just encode the array only once
echo json_encode(array_reverse($elmarray));
}
}
If you use jQuery, you can do the following to execute the JSON request:
$.ajax({
type: 'GET',
url: '/path/to/script.php',
data: '{ id: '+id+', type: '+type+' }',
contentType: 'application/json',
dataType: 'json',
success: function(data) {
dataObject = JSON.parse(data);
// process data
},
error: function(e) {
console.log(e.message);
}
});
You can use your existing PHP code with this solution. The url you point to would just have to print the JSON result, as you are currently doing in getparentids().
I m using codeigniter and would like to grab some user info with ajax. This is what I have but it s not working
In the view I have a defined variable:
<script type="text/javascript">
var end_user = "<? echo $user_id; ?>";
</script>
<div id="tabs6"></div>
js file:
function get_experience()
{
$.post(base_url + "index.php/home/get_experience", { user : end_user }, function(data) {
if (data.status == 'ok')
{
$("div#tabs6").html(data);
}
else
{ //nothing }
}, "json");
}
get_experience();
controller:
public function get_experience()
{
$this->load->model('experience_model');
$end_user = $this->input->post('user');
$one_exp = $this->experience_model->one_exp($end_user);
if ($one_exp->num_rows() > 0)
{
$one_exp_html = '<ul>';
foreach($one_exp->result() as $exp)
{
$one_exp_html .= '<li>';
$one_exp_html .= $exp->experience;
$one_exp_html .= '</li>';
}
$one_exp_html .= '</ul>';
$result = array('status' => 'ok', 'content' => $one_exp_html);
return json_encode($result);
exit();
}
else
{
$result = array('status' => 'ok', 'content' => 'nothing here');
return json_encode($result);
exit();
}
}
model:
function one_exp($end_user)
{
$query_str = "SELECT experience FROM exp WHERE user_id = ?";
$query = $this->db->query($query_str, $end_user);
}
You need to add return $query to your one_exp method.
EDIT
You're setting user_id in your view, but then using end_user in your javascript function get_experience().
Also, since it's json you'll need to change the html fill to
$("div#tabs6").html(data.content);
For more debugging add an alert to your callback (right before if (data.status == 'ok') add alert(data);)
You've got to echo the result out I think, not return it.
I am not sure but problem occurs in end_user value in js.Try this oneView File:
<script type="text/javascript">
var end_user = "<? echo $user_id; ?>";
get_experience(end_user);
</script>
<div id="tabs6"></div>
The js file:
function get_experience(foo)
{
$.post(base_url + "index.php/home/get_experience", { user : foo }, function(data) {
if (data.status == 'ok')
{
$("div#tabs6").html(data);
}
else
{ //nothing }
}, "json");
}