Commit 540de525 authored by Nahla Shiri's avatar Nahla Shiri

679 filtres contextuel et non global

parent f0bd5a5b
......@@ -431,7 +431,7 @@ function nap_image_resize($image,$size){
function nap_get_item($post_ID, $args = null, $current_page = '', $options = null) {
function nap_get_item($post_ID, $args = null, $current_page = '', $options = null,$search = null) {
$link = $image = $size = '';
if (isset($options)) {
if ($options['dwnldLink']) {
......@@ -447,8 +447,38 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
}
}
if(isset($search['pa_couleur']) && $search['pa_couleur']!='' ){
$colors_value = get_the_terms( $post_ID, 'pa_couleur');
$filter = "hidden";
if(is_array($colors_value)){
foreach($colors_value as $key => $value) {
$code = nap_color_attribute($value->slug);
$nap_article = '<article class = " visible row">
if($code!='' && stristr($search['pa_couleur'],$code )) {
$filter = "selected";
}
}
}
}
if(isset($search['pa_format']) && $search['pa_format']!='' ){
$format_value = get_the_terms( $post_ID, 'pa_format');
$filter = "hidden";
if(is_array($format_value)){
foreach($format_value as $key => $value) {
if(stristr($search['pa_format'],$value->name )) {
$filter = "selected";
}
}
}
}
if(isset($filter)) $class = $filter;
$nap_article = '<article class = " visible row '.$class.'">
<a href="#"></a>
<figure data-bg = "" class = "' . $size . ' transition">
<div class="abs-full article-bg transition"></div>';
......@@ -611,3 +641,27 @@ function externe_referrer(){
return $ref ;
}
function nap_attribute_by_category($categorie, $attr){
$args = array(
'post_type' => array('product', 'product_variation'),
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $categorie,
'operator' => 'IN',
)
)
);
$products = get_posts($args);
$attribute=array();
foreach ($products as $key => $value) {
$attribute[] = array_shift(woocommerce_get_product_terms($value->ID, $attr, 'names'));
}
return array_unique($attribute);
}
<?php
print_r($_GET);
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
......@@ -22,10 +23,32 @@ $current_page = 'catalogue';
get_header();
$product;
$cate = get_queried_object();
$cateID = $cate->term_id;
print '******CATID Nahla'.$cateID = $cate->term_id;
//SubCats
$child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' => the_category_ID(), 'exclude' => $cateID, 'orderby' => 'title', 'order' => 'ASC'));
$products =nap_attribute_by_category($cateID, 'pa_format');
print_r($products);
if(is_product_category()){
global $product;
// the array of attributes names
$attribute_names = array('pa_format','pa_matiere');
foreach( $attribute_names as $key => $attribute_name ) {
// Getting the value of an attribute
$attribute_value = array_shift(wc_get_product_terms( $product->id, $attribute_name));
// Displays only if attribute exist for the product
if(!empty($attribute_value) || $attribute_value == '0' ){
echo print"*********".$attribute_value;
// Separating each number by a " / "
if($key < 3) echo ' / ';
}
}
}
?>
<div class="container clearfix" id="catalogue" data-page = "<?php echo $cateID; ?>">
......@@ -38,6 +61,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div>
<div class="right-container">
<div class="left-panel fixed-full position--after-menu ">
<?php if($cateID != 20):?>
<div class="filter-wrapper">
<div class="filter-btn fixed position--after-menu">
<div class="btn-container"><span class="abs-center font-small">Filtres</span></div>
......@@ -53,31 +77,46 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
$attributes = array('Univers' => 'pa_univers', 'Matiére' => 'pa_matiere', 'Format' => 'pa_format', 'Couleurs' => 'pa_couleur');
foreach ($attributes as $key => $value) :
?>
<div class="filter-bloc">
<div class="filter-bloc <?php if($_GET[$value]!='') echo 'active selected-filter'; ?>">
<div class="header">
<p><span><?php echo $key ?></span></p>
</div>
<?php
if ($value == 'pa_couleur')
$terms = get_terms($value);
else
$terms = nap_attribute_by_category ($cateID, $value);
//print_r($terms);
if (!empty($terms) && !is_wp_error($terms)):
?>
<div class="bloc-content">
<ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?>>
<ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>">
<?php
foreach ($terms as $term) :
if ($value == 'pa_couleur'):
$color = get_field('couleurs', 'pa_couleur_' . $term->term_id);
if (isset($color) && strlen($color) > 0):
if(isset($_GET['pa_couleur']) && stristr($_GET['pa_couleur'],$color )) :
$filter_class = 'selected';
else:
$filter_class = '';
endif;
?>
<li data-color = "<?php echo $color; ?>" class="<?php echo $term->name; ?>"></li>
<li data-color = "<?php echo $color; ?>" class="<?php echo $term->name.' '.$filter_class; ?>"></li>
<?php
endif;
else :
?>
<li><?php echo $term->name; ?></li>
<?php
if(isset($_GET['pa_format']) && stristr($_GET['pa_format'],$term )) :
$filter_class = 'selected';
else:
$filter_class = '';
endif;
?>
<li class="<?php echo $filter_class ?>"><?php echo $term; ?></li>
<?php
endif;
endforeach;
......@@ -102,6 +141,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div>
</div>
</div>
<?php endif;?>
<?php
foreach ($child_category as $key => $value) :
?>
......@@ -144,7 +184,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
);
?>
<?php echo nap_get_item($id, $args, $current_page, $options); ?>
<?php echo nap_get_item($id, $args, $current_page, $options,$_GET); ?>
<?php
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment