<?php
global $paged;
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$catObj = $wp_query->get_queried_object();
$catId = $catObj->term_id;
$filterData = $_GET;
$params = [
'post_status' => 'publish',
'posts_per_page' => 12,
'paged' => $paged,
'post_type' => 'product'
];
if (isset($filterData['orderby'])) {
switch ( $filterData['orderby'] ) {
case 'date':
$params['orderby'] = 'date';
$params['order'] = 'DESC';
break;
case 'price':
$params['orderby'] = 'meta_value_num';
$params['order'] = 'ASC';
$params['orderby_meta_key'] = '_price';
break;
case 'price-desc':
$params['orderby'] = 'meta_value_num';
$params['order'] = 'DESC';
$params['orderby_meta_key'] = '_price';
break;
case 'popularity':
$params['orderby'] = 'meta_value_num';
$params['order'] = 'DESC';
$params['orderby_meta_key'] = 'total_sales';
break;
case 'rating':
$params['orderby'] = 'meta_value_num';
$params['order'] = 'DESC';
$params['orderby_meta_key'] = '_wc_average_rating';
break;
}
unset($filterData['orderby']);
}
$meta_query = [
'relation' => 'AND'
];
$tax_query = [
'relation' => 'AND'
];
if ($catId != '') {
$tax_query[] =
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $catId,
'operator' => 'IN'
);
}
foreach ($filterData as $key => $metaItem) {
if ($metaItem != '') {
$values = explode(',', $metaItem);
$compare = '=';
switch ($key) {
case ('min_tempo') :
$key = 'tempo';
$compare = '>=';
break;
case ('max_tempo') :
$key = 'tempo';
$compare = '<=';
break;
}
foreach ($values as $value) {
if ($key == 'tempo') {
$meta_query[] = [
'key' => $key,
'value' => $value,
'compare' => $compare,
'type' => 'NUMERIC'
];
} else {
$tax_query[] = [
'taxonomy' => 'pa_' . $key,
'field' => 'slug',
'terms' => $value
];
}
}
}
}
if (count($meta_query) > 1) {
$params['meta_query'] = $meta_query;
}
$params['tax_query'] = $tax_query;
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) {
woocommerce_product_loop_start();
woocommerce_product_subcategories();
while ($wc_query->have_posts()) {
$wc_query->the_post();
wc_get_template_part('content', 'product');
}
woocommerce_product_loop_end();
if ($wc_query->max_num_pages > 1) : ?>
<nav class="woocommerce-pagination">
<?php echo paginate_links(apply_filters('woocommerce_pagination_args', array(
'base' => esc_url_raw(str_replace(999999999, '%#%', remove_query_arg('add-to-cart', get_pagenum_link(999999999, false)))),
'format' => '',
'add_args' => false,
'current' => max(1, get_query_var('paged')),
'total' => $wc_query->max_num_pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
))); ?>
</nav>
<?php endif;
} elseif (!woocommerce_product_subcategories(array('before' => woocommerce_product_loop_start(false), 'after' => woocommerce_product_loop_end(false)))) {
wc_get_template('loop/no-products-found.php');
}
?>
$(document).ready(function() {
"use strict";
var recursionCount = 0,
elements = [],
dom = document.getElementById("dom");
function showDOM(node) {
for(var i=0; i < node.children.length; i++){
var n = node.children[i],
el = document.createElement("div"),
elClass = n.className,
parentNode = n.parentNode,
parent;
if(n.id != "dom" && n.tagName != "SCRIPT"){
n.setAttribute("id", recursionCount);
el.setAttribute("data-element-id", recursionCount);
recursionCount++;
if(n.parentNode.tagName == "BODY"){
parent = "dom";
} else {
parent = parentNode.getAttribute("id");
}
el.setAttribute("data-parent-id", (parent));
el.innerText = "<" + n.tagName + " class='" + elClass + "'> recursionCount = " + recursionCount;
console.log(el);
elements.push(el);
}
showDOM(node.children[i]);
}
return elements;
}
showDOM(document.body);
for(var a in elements){
var pasteIn = elements[a].getAttribute("data-parent-id"),
all = document.getElementsByTagName("*");
for(var b = 0; b < all.length; b++){
if(all[b].getAttribute("data-element-id") == pasteIn){
all[b].appendChild(elements[a]);
}
}
}
});
$current_cat_id = get_query_var('cat');
$child = get_category($current_cat_id);
$level2 = $child->parent;
$child2 = get_category($level2);
$level3 = $child2->parent;
if(is_category(6)){
include "catalog.php";
} else if ($level2 == 6){
include "catalog_level2.php";
} else if ($level3 == 6){
include "catalog_level3.php";
}
$(function(){
// Определяем карту (добавляем маркеры, балуны и список со ссылками)
mapInit();
// Cобытие клика по ссылке
$(document).on("click", "#markers a", function(){
var i = $(this).attr("rel"),
lat = $(this).data("lat"),
lng = $(this).data("lng");
// Эта строка кода, закрывает все открытые балуны, для открытия выбранного
for(close=0; close < arrInfoWindows.length; close++){ arrInfoWindows[close].close(); }
// Center the map on the clicked marker
map.setCenter(arrMarkers[i].getPosition());
arrInfoWindows[i].open(map, arrMarkers[i]);
return false;
});
});