<?php
$cur_term = get_term_by('slug', get_query_var('product_cat'), 'product_cat');
$base_args;
$minprice123 = isset($_GET['lpr']) ? floatval(filter_input(INPUT_GET, 'lpr')) : 1;
$maxprice123 = isset($_GET['rpr']) ? floatval(filter_input(INPUT_GET, 'rpr')) : 9999999;
if($maxprice123 == $minprice123) {
$maxprice123 = $maxprice123 + 1;
}
if($s != null)
{
$base_args = array(
'post_type' => 'product',
'post_status ' => 'publish',
'posts_per_page' => 16,
's' => $s,
'paged' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'availability_in_the_warehouse_1',
'value' => '0',
'compare' => '>'
),
array(
'key' => '_price',
'value' => $maxprice123,
'type' => 'numeric',
'compare' => '<='
),
array(
'key' => '_price',
'type' => 'numeric',
'value' => $minprice123,
'compare' => '>='
)
),
);
}
else {
$base_args = array(
'post_type' => 'product',
'post_status ' => 'publish',
'posts_per_page' => 16,
'paged' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'availability_in_the_warehouse_1',
'value' => '0',
'compare' => '>'
),
array(
'key' => '_price',
'type' => 'numeric',
'value' => $maxprice123,
'compare' => '<='
),
array(
'key' => '_price',
'type' => 'numeric',
'value' => $minprice123,
'compare' => '>='
)),
);
}
if($s != null)
{
$base_args1 = array(
'post_type' => 'product',
'post_status ' => 'publish',
'posts_per_page' => 16,
's' => $s,
'paged' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'availability_in_the_warehouse_1',
'value' => '0',
'compare' => '>'
)
),
);
}
else {
$base_args1 = array(
'post_type' => 'product',
'post_status ' => 'publish',
'posts_per_page' => 16,
'paged' => -1,
'meta_query' => array('relation' => 'OR',
array(
'key' => 'availability_in_the_warehouse_1',
'value' => '0',
'compare' => '>'
)),
);
}
if ($cur_term) {
$base_args['tax_query'][] = array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $cur_term->term_id
);
$base_args1['tax_query'][] = array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $cur_term->term_id
);
}
/// non filtered ///
$f_args = $base_args;
$f_args1 = $base_args1;
$f_args1['fields'] = 'ids';
$f_args1['posts_per_page'] = -1;
$f_args['fields'] = 'ids';
$f_args['posts_per_page'] = -1;
$all_ids = get_posts($f_args);
$all_ids1 = get_posts($f_args1);
/// filtered ///
$p_args = $base_args;
$atributes = get_field("filtering_by",'product_cat_'.$cur_term->term_id);
//echo "<pre>";
//var_dump($atributes);
//var_dump($atributes);
$taxes = array();
if($atributes != null)
{
foreach($atributes as $attr)
{
$taxes[] = 'pa_'.$attr['value'];
}
}
else {
# code...
}
//die();
foreach ($taxes as $tax) {
if (isset($_GET[$tax])) {
$p_args['tax_query'][] = array(
'taxonomy' => $tax,
'field' => 'term_id',
'terms' => $_GET[$tax]
);
}
}
//$p_args["tax_query"][1]["terms"] = explode (',' , $p_args["tax_query"][1]["terms"]);
//var_dump($p_args["tax_query"][1]["terms"]);
if (count($p_args['tax_query']) > 1)
$p_args['tax_query']['relation'] = 'AND';
// price args
$p_args = getPriceArg($p_args);
// order args
$orderby = filter_input(INPUT_GET, 'orderby');
switch ($orderby) {
case "price-desc":
$p_args['orderby'] = 'meta_value_num';
$p_args['meta_key'] = '_price';
$p_args['order'] = 'desc';
break;
case "price-asc":
$p_args['orderby'] = 'meta_value_num';
$p_args['meta_key'] = '_price';
$p_args['order'] = 'asc';
break;
default :
$p_args['orderby'] = 'post_title';
$p_args['order'] = 'asc';
break;
}
//$products = get_posts($p_args);
$p_args['paged'] = !isset($paged) ? 1 : $paged;
$products = new WP_Query($p_args);
if($cur_term != false)
{
?>
<form action="<?php echo get_term_link($cur_term, 'product_cat') ?>" method="GET" class="filterForm">
<?php
global $wpdb;
$taxes = array();
if($atributes != null)
{
foreach($atributes as $attr)
{
$taxes['pa_'.$attr['value']] = $attr['label'];
}
}
else {
# code...
}
?>
<aside class="filter"><span class="filter-open"><i class="filter-open-ico"></i></span>
<div class="filter__inner">
<?php
foreach ($taxes as $tax => $title) {
$terms = getFilterTerms($tax, 'product', $all_ids);
$get_tax = isset($_GET[$tax]) ? $_GET[$tax] : array();
if (count($terms)) {
?>
<div class="filter__block">
<p class="heading"><?php echo $title ?>:</p>
<div class="filter__block--inner">
<?php foreach ($terms as $t) { ?>
<div class="filter-count">
<?php $chkd = $t->term_id == $get_tax ? "checked='checked'" : ""; ?>
<input type="checkbox" name="<?php echo $tax ?>[]" value="<?php echo $t->term_id ?>" id="<?php echo $tax . "_" . $t->term_id ?>" <?php echo $chkd ?> />
<label for="<?php echo $tax . "_" . $t->term_id ?>"><?php echo $t->name ?></label>
</div>
<?php } ?>
</div>
</div>
<?php
}
}
?>
<?php
$min = (float) getMinMaxByIds('min', $all_ids1);
$max = (float) getMinMaxByIds('max', $all_ids1);
if($min == 0 || $max == 0 || $min == false || $max == false || $min == null || $max == null)
{
$min = 0;
$max = 0;
}
if($min == $max)
{
$max = $max + 1;
}
$fltr_min = isset($_GET['lpr']) ? floatval(filter_input(INPUT_GET, 'lpr')) : $min;
$fltr_max = isset($_GET['rpr']) ? floatval(filter_input(INPUT_GET, 'rpr')) : $max;
?>
<div class="widget range-block">
<div class="filter__block">
<p class="heading">Стоимость, руб.</p>
<div id="range-slider"></div>
<div class="price-txt cf">
<p>от <span id="range-slider-min"></span></p>
<p>до <span id="range-slider-max"></span></p>
</div>
<input id="range_min" type="hidden"/>
<input id="range_max" type="hidden"/>
<div class="pricerange">
<input type="hidden" id="prc-min" value="<?php echo $min ?>" disabled="disabled"/>
<input type="hidden" id="prc-max" value="<?php echo $max ?>" disabled="disabled"/>
<input type="hidden" id="fltr-min" value="<?php echo $fltr_min ?>" disabled="disabled"/>
<input type="hidden" id="fltr-max" value="<?php echo $fltr_max ?>" disabled="disabled"/>
<input type="hidden" id="lp" name="lpr" value="<?php echo $fltr_min ?>" />
<input type="hidden" id="rp" name="rpr" value="<?php echo $fltr_max ?>" />
<div id="prodcatprice-range" class="prodcatprice__sec"></div>
</div>
</div>
<div class="btn_fame">
<input type="submit" value="Подобрать" class="btn"/>
</div>
</div>
</div>
</aside>
</form>
<?php }?>
<div class="cat-content__inner">
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php
$chr=0;
while ( $products->have_posts() ) : $products->the_post(); ?>
<?php
$price = intval(get_post_meta( get_the_ID(), '_regular_price', true));
$sale = intval(get_post_meta( get_the_ID(), '_sale_price', true));
$difference = $price - $sale;
$discount = intval($difference/$price*100);
?>
<div class="swiper-slide">
<div class="img-wrap">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo the_post_thumbnail_url(); ?>" alt="">
</a>
</div>
<div class="title"> <a href="<?php the_permalink(); ?>"><?php echo the_title('','',false); ?> </a></div>
<?php global $product; ?>
<? if($product->product_type != "variable"){ ?>
<? if($sale) : ?>
<div class="price">
<span class="old-price"><?php echo $price; ?> ₽</span>
<?php echo $sale; ?> ₽
</div>
<?php else : ?>
<div class="price"><?php echo $price; ?> ₽</div>
<?php endif; ?>
<? } ?>
<? if($product->product_type == "variable"){
woocommerce_variable_add_to_cart(); ?>
<a href="" onclick="forms['add_to_cart_form'].submit()" class="buy">Купить<span class="basket"></span></a>
<? } else { ?>
<a href="<?php echo $product->add_to_cart_url(); ?>" class="buy">Купить<span class="basket"></span></a>
<? } ?>
<?php //woocommerce_template_loop_add_to_cart(); ?>
<?php if($sale) : ?>
<div class="discount-notify">Скидка<span class="discount-size"><?php echo ceil($discount); ?>%</span></div>
<?php endif; ?>
</div>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php
/**
* woocommerce_after_shop_loop hook.
*
* @hooked woocommerce_pagination - 10
*/
//do_action( 'woocommerce_after_shop_loop' );
wp_pagenavi(array( 'query' => $products ));
?>
</div>