-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
352 lines (276 loc) · 11 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
get_header();
$show = 'used';
if(isset($_GET['show'])){
$show = esc_attr( $_GET['show'] );
}
$term = get_queried_object();
if ( $term ) {
$currentlink = get_category_link($term->term_id);
}
$navid = ( $term ) ? $term->term_id : 0;
$apply = false;
?>
<div class="category-head">
<h4><?php echo single_cat_title();?></h4>
<div class="bars-animation">
<img src="<?php echo THEME_URL; ?>/dist/assets/img/elements/hicon.png" alt="PM">
</div>
</div><!-- Category Head -->
<main class="cd-main-content">
<div class="cd-tab-filter-wrapper">
<div class="cd-tab-filter">
<ul class="cd-filters">
<li class="filtertype"><a <?php if($show=='used'):?>class="selected"<?php endif;?> href="<?php echo $currentlink;?>?show=used">Used</a></li>
<li class="filtertype"><a <?php if($show=='new'):?>class="selected"<?php endif;?>href="<?php echo $currentlink;?>?show=new">New</a></li>
<li class="filtertype"><a <?php if($show=='all'):?>class="selected"<?php endif;?>href="<?php echo $currentlink;?>?show=all">All</a></li>
</ul> <!-- cd-filters -->
</div> <!-- cd-tab-filter -->
</div> <!-- cd-tab-filter-wrapper -->
<section class="cd-gallery filter-is-visible">
<ul class="productsfilter">
<?php
$productsbrands = array();
$productslevels = array();
$productcategories = array();
$the_query = new WP_Query( array(
'post_type' => 'product',
'numberposts' => '-1',
'posts_per_page' => '-1',
's' => esc_attr( $_GET['s'] ),
) );
$brands = array();
$levels = array();
$products = array();
$unsortedcats = array();
$productcats = array();
$productpbrands = array();
$globalfilters = array();
$globalbrands = array();
$globallevels = array();
$cats = array();
while ( $the_query->have_posts() ) :
$the_query->the_post();
$sorttypes = pmwoodwind_list_hierarchical_terms(get_the_id(), 'product_cat');
$sorttypesb = pmwoodwind_list_hierarchical_terms(get_the_id(), 'pwb-brand');
$isnew = pmwoodwind_is_new_product(get_the_id());
if($isnew && ($isnew == 'yes')){
$products['new'][$sorttypes.$sorttypesb.get_the_id()] = get_the_id();
} else {
$products['used'][$sorttypes.$sorttypesb.get_the_id()] = get_the_id();
}
$products['all'][$sorttypes.$sorttypesb.get_the_id()] = get_the_id();
endwhile;
wp_reset_postdata();
ksort($products[$show]);
$sortedp = $products[$show];
$sortedproductsbyside = array();
foreach($sortedp as $p=>$product_id):
$types = wp_get_post_terms($product_id, 'product_cat',array( 'orderby' => 'term_order' ));
$pbrands = wp_get_post_terms($product_id, 'pwb-brand',array( 'orderby' => 'term_order' ));
$plevels = wp_get_post_terms($product_id, 'level',array( 'orderby' => 'term_order' ));
$filters = '';
$filtersbrands = '';
$filterslevels = '';
$productcats[$product_id] = $types;
$productpbrands[$product_id] = $pbrands[0];
foreach($types as $type){
$filters .= ' filter'.$type->term_id;
$unsortedcats[$type->term_id] = $type;
$productcategories[$type->term_id][] = $product_id;
}
if($plevels):
foreach($plevels as $plevel){
$filterslevels .= ' filter'.$plevel->term_id;
$levels[$plevel->term_id] = $plevel;
$productslevels[$plevel->term_id][] = $product_id;
}
endif;
foreach($pbrands as $brand){
$filtersbrands .= ' filter'.$brand->term_id;
$brands[$brand->term_id] = $brand;
$brandname = $brand->name;
$productsbrands[$brand->term_id][] = $product_id;
}
$globalfilters[$product_id] = $filters;
$globalbrands[$product_id] = $filtersbrands;
$globallevels[$product_id] = $filterslevels;
$sortedbrands = array();
$sortedlevels = array();
foreach($brands as $brand){
$sortedbrands[$brand->term_order] = $brand;
}
foreach($levels as $level){
$sortedlevels[$level->term_order] = $level;
}
foreach($unsortedcats as $unsortedcat){
if($unsortedcat->parent == $navid){
$cats[$unsortedcat->term_order.'_'.$unsortedcat->term_id] = $unsortedcat;
}
if($unsortedcat->term_id == $navid){
$cats[$unsortedcat->term_order.'_'.$unsortedcat->term_id] = $unsortedcat;
}
}
ksort($sortedbrands);
ksort($cats);
ksort($sortedlevels);
endforeach;
foreach($cats as $cat){
$xx = $cat->term_order;
if($cat->parent == $navid):
$childs = get_terms( array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hide_empty' => 0,
'parent' => $cat->term_id,
) );
endif;
if($childs):
foreach($childs as $child):
$xx .= '_'.$child->term_order;
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'product',
's' => esc_attr( $_GET['s'] ),
)
);
foreach($posts_array as $post_array){
$sortedproductsbyside[$xx.'-'.basename(get_permalink($post_array->ID))] = $post_array->ID;
}
endforeach;
else:
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'product',
's' => esc_attr( $_GET['s'] ),
)
);
foreach($posts_array as $post_array){
$sortedproductsbyside[$xx.'-'.basename(get_permalink($post_array->ID))] = $post_array->ID;
}
endif;
}
ksort($sortedproductsbyside, SORT_NATURAL | SORT_FLAG_CASE);
foreach($sortedproductsbyside as $p=>$product_id):
$isnew = pmwoodwind_is_new_product($product_id);
$price = pmwoodwind_product_main_price($product_id);
$status = $price;
if(is_numeric($price)){
$status = 'sale';
}
?>
<li id="<?php echo $product_id;?>" class="mix <?php echo $isnew;?> <?php echo $status;?> <?php echo ( isset( $globalfilters[$product_id] ) ? esc_attr( $globalfilters[$product_id] ) : '');?> <?php echo ( isset( $globalbrands[$product_id] ) ? esc_attr( $globalbrands[$product_id] ) : '' );?> <?php echo ( isset( $globallevels[$product_id] ) ? esc_attr( $globallevels[$product_id] ) : '' );?> <?php echo pmwoodwind_product_get_serial($product_id);?> <?php echo get_the_title($product_id);?>">
<a href="<?php echo get_permalink($product_id);?>" title="<?php echo get_the_title($product_id);?>">
<?php
global $product;
$product = new WC_Product( $product_id );
echo woocommerce_get_product_thumbnail( 'main_image' );
?>
</a>
<h5>
<a href="<?php echo get_permalink($product_id);?>"><?php echo get_the_title($product_id);?></a>
<br/>
<?php if($price):?><span class="price <?php echo $price;?>"><?php
if(is_numeric($price)){
echo money_format("$ %i",$price);
} else {
echo $price;
}
?></span><?php endif;?>
</h5>
</li>
<?php
endforeach;
?>
<li class="gap"></li>
<li class="gap"></li>
<li class="gap"></li>
</ul>
<?php if ( $term ) : ?>
<div class="cd-fail-message" <?php if($sortedproductsbyside < 1):?> style="display:block;" <?php endif;?>>No <?php echo $term->name;?> found</div>
<?php endif; ?>
</section> <!-- cd-gallery -->
<div class="cd-filter filter-is-visible">
<form>
<div class="cd-filter-block">
<h4>Search</h4>
<div class="cd-filter-content">
<input type="search" id="searchs" value="<?php echo esc_attr( $_GET['s'] );?>" name="s" placeholder="Serial or Name...">
</div> <!-- cd-filter-content -->
</div> <!-- cd-filter-block -->
<?php if($levels):?>
<div class="cd-filter-block levels">
<h4>Levels</h4>
<ul class="cd-filter-content cd-filters list levels">
<?php foreach($sortedlevels as $level):?>
<li class="<?php echo implode(' ', $productslevels[$level->term_id]);?>">
<input class="filter" type="checkbox" name="radioButton" id="filter<?php echo $level->term_id;?>">
<label class="checkbox-label" for="filter<?php echo $level->term_id;?>"><?php echo $level->name;?></label>
</li>
<?php endforeach;?>
</ul> <!-- cd-filter-content -->
</div> <!-- cd-filter-block -->
<?php endif;?>
<?php if($cats && $term):?>
<div class="cd-filter-block categories">
<h4><?php echo $term->name;?></h4>
<ul class="cd-filter-content cd-filters list categories">
<?php foreach($cats as $term):
if($term->parent == $navid):
$childs = get_terms( array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hide_empty' => 0,
'parent' => $term->term_id,
) );
?>
<li class="<?php echo implode(' ', $productcategories[$term->term_id]);?>">
<input class="filter" <?php if($apply == $term->term_id):?>checked="checked"<?php endif;?> data-filter=".filter<?php echo $term->term_id;?>" type="checkbox" id="filter<?php echo $term->term_id;?>">
<label class="checkbox-label" for="filter<?php echo $term->term_id;?>"><?php echo $term->name;?></label>
<?php if($childs): ?>
<ul class="cd-filter-content cd-filters list child">
<?php foreach($childs as $child):?>
<?php if(isset($productcategories[$child->term_id])):?>
<li class="<?php echo implode(' ', $productcategories[$child->term_id]);?>">
<input class="filter" type="checkbox" id="filter<?php echo $child->term_id;?>">
<label class="checkbox-label" for="filter<?php echo $child->term_id;?>"><?php echo $child->name;?></label>
</li>
<?php endif;?>
<?php endforeach;?>
</ul>
<?php endif;?>
</li>
<?php endif; endforeach;?>
</ul> <!-- cd-filter-content -->
</div> <!-- cd-filter-block -->
<?php endif;?>
<?php if($sortedbrands):?>
<div class="cd-filter-block brands">
<h4>Brands</h4>
<ul class="cd-filter-content cd-filters list brands">
<?php foreach($sortedbrands as $brand):?>
<li class="<?php echo implode(' ', $productsbrands[$brand->term_id]);?>">
<input class="filter" type="checkbox" name="radioButton" id="filter<?php echo $brand->term_id;?>">
<label class="checkbox-label" for="filter<?php echo $brand->term_id;?>"><?php echo $brand->name;?></label>
</li>
<?php endforeach;?>
</ul> <!-- cd-filter-content -->
</div> <!-- cd-filter-block -->
<?php endif;?>
</form>
<a href="#0" class="cd-close">Close</a>
</div> <!-- cd-filter -->
<a href="#0" class="cd-filter-trigger">Filters</a>
</main> <!-- cd-main-content -->
<?php if($apply):
$apply = '.filter'.$apply;
?>
<?php endif;?>
<script>
jQuery(function(){
jQuery('.productsfilter').mixItUp();
});
</script>
<?php get_footer();