Commit 30e4f7b6 authored by imac's avatar imac

Merge branch 'develop' of https://gitlab.netisse.fr/msfari/NAP-wordpress into develop

parents b1fdff00 bfb65b0d
jQuery(document).ready(function() { jQuery(document).ready(function() {
jQuery(document).on('click', ".format-list", function() {
var format = jQuery(this).find('.format-desc').text();
jQuery('.info-format').text(format);
jQuery('.info-format-txt').text(format);
});
jQuery(document).on('click', ".download_file", function() { jQuery(document).on('click', ".download_file", function() {
var id; var id;
var download_link = jQuery('.download_file_link').attr('href'); var download_link = jQuery('.download_file_link').attr('href');
...@@ -49,7 +57,6 @@ jQuery(document).ready(function() { ...@@ -49,7 +57,6 @@ jQuery(document).ready(function() {
jQuery('article').removeClass('hidden'); jQuery('article').removeClass('hidden');
//filtre couleur
var tabcolor = []; var tabcolor = [];
i = 0; i = 0;
jQuery("#pa_couleur .selected").each(function() { jQuery("#pa_couleur .selected").each(function() {
...@@ -67,11 +74,19 @@ jQuery(document).ready(function() { ...@@ -67,11 +74,19 @@ jQuery(document).ready(function() {
jQuery("#pa_matiere .selected").each(function() { jQuery("#pa_matiere .selected").each(function() {
tabmatiere[i++] = jQuery(this).text(); tabmatiere[i++] = jQuery(this).text();
}); });
var tabunivers = [];
i = 0;
jQuery("#pa_univers .selected").each(function() {
tabunivers[i++] = jQuery(this).text();
});
var selected_colors = tabcolor.join(','); var selected_colors = tabcolor.join(',');
var selected_formats = tabformat.join(','); var selected_formats = tabformat.join(',');
var selected_matiere = tabmatiere.join(','); var selected_matiere = tabmatiere.join(',');
var params = { pa_couleur:selected_colors, pa_format:selected_formats, pa_matiere: selected_matiere}; var selected_univers = tabunivers.join(',');
window.location.href = "?" +jQuery.param(params); var params = {pa_couleur: selected_colors, pa_format: selected_formats, pa_matiere: selected_matiere, pa_univers:selected_univers};
window.location.href = "?" + jQuery.param(params);
/*history.pushState({}, null, "?" + jQuery.param(params)); /*history.pushState({}, null, "?" + jQuery.param(params));
jQuery.ajax({ jQuery.ajax({
...@@ -97,30 +112,37 @@ jQuery(document).ready(function() { ...@@ -97,30 +112,37 @@ jQuery(document).ready(function() {
}); });
*/ */
}); });
if(jQuery.urlParam('pa_format')!='' || jQuery.urlParam('pa_couleur')!='' || jQuery.urlParam('pa_matiere')!=''){
jQuery('.list-animation section').each(function() {
if (jQuery(this).find('article.selected').length == 0) {
jQuery('.filter-bloc ').each(function() {
if (jQuery(this).find('.bloc-content').length == 0) {
jQuery(this).hide(); jQuery(this).hide();
} }
}); });
}
jQuery('.filter-bloc ').each(function() { jQuery('.list-animation section').each(function() {
if (jQuery(this).find('.bloc-content').length == 0) { if (jQuery(this).find("article").length) {
console.log('article found');
}
else {
jQuery(this).hide(); jQuery(this).hide();
} }
}); })
}); });
jQuery.urlParam = function(name){ jQuery.urlParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0; return results[1] || 0;
} }
\ No newline at end of file
...@@ -35,6 +35,7 @@ $post_ID = 260; ...@@ -35,6 +35,7 @@ $post_ID = 260;
while (has_sub_field('tl_images', $post_ID)) : while (has_sub_field('tl_images', $post_ID)) :
$options = array(); $options = array();
$options['image'] = get_sub_field('tl_image'); $options['image'] = get_sub_field('tl_image');
$options['title'] = get_sub_field('tl_titre_image');
$options['dwnldLink'] = get_sub_field('tl_link'); $options['dwnldLink'] = get_sub_field('tl_link');
echo nap_get_item($post_ID, null, '', $options); echo nap_get_item($post_ID, null, '', $options);
?> ?>
......
...@@ -415,31 +415,32 @@ function nap_distinct_format_variations($variations) { ...@@ -415,31 +415,32 @@ function nap_distinct_format_variations($variations) {
return $var_format; return $var_format;
} }
function nap_filter_attribute($postID, $search, $attribute, $color = false) { function nap_filter_attribute($id, $args, $options, $list_attr, $search) {
if (isset($search) && $search != '') { if(isset($search['pa_format']) && $search['pa_format']!=''){
$tab_attr = get_the_terms($postID, $attribute); $list_format=explode(",", $search['pa_format']);
$filter = "hidden";
if (is_array($tab_attr)) {
foreach ($tab_attr as $key => $value) {
if ($color) {
$code = nap_color_attribute($value->slug);
if ($code != '' && stristr($search, $code)) {
$filter = "selected";
}
} else {
if (stristr($search, $value->name)) {
$filter = "selected";
} }
if(isset($search['pa_couleur']) && $search['pa_couleur']!=''){
$list_couleur=explode(",", $search['pa_couleur']);
} }
if(isset($search['pa_matiere']) && $search['pa_matiere']!=''){
$list_matiere=explode(",", $search['pa_matiere']);
} }
if(isset($search['pa_univers']) && $search['pa_univers']!=''){
$list_univers=explode(",", $search['pa_univers']);
} }
if(
( ($list_couleur && in_array($list_attr['pa_couleur'],$list_couleur)) || empty($list_couleur) ) &&
( ($list_format && in_array($list_attr['pa_format'],$list_format)) || empty($list_format) ) &&
( ($list_univers && in_array($list_attr['pa_univers'],$list_univers)) || empty($list_univers) ) &&
( ($list_matiere && in_array($list_attr['pa_matiere'],$list_matiere)) || empty($list_matiere) )
)
{
echo nap_get_item($id, $args, 'catalogue', $options);
} }
return $filter;
} }
function nap_get_item($post_ID, $args = null, $current_page = '', $options = null, $search = null) { function nap_get_item($post_ID, $args = null, $current_page = '', $options = null, $search = null) {
$link = $image = $size = ''; $link = $image = $size = '';
if (isset($options)) { if (isset($options)) {
if ($options['dwnldLink']) { if ($options['dwnldLink']) {
...@@ -453,9 +454,15 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul ...@@ -453,9 +454,15 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
if ($options['size']) { if ($options['size']) {
$size = $options['size']; $size = $options['size'];
} }
if ($options['title']) {
$title_item = $options['title'];
} else {
$title_item = get_the_title($post_ID);
}
} }
if (isset($search['pa_couleur']) && $search['pa_couleur'] != '') { /* if (isset($search['pa_couleur']) && $search['pa_couleur'] != '') {
$colors_value = get_the_terms($post_ID, 'pa_couleur'); $colors_value = get_the_terms($post_ID, 'pa_couleur');
$filter = "hidden"; $filter = "hidden";
if (is_array($colors_value)) { if (is_array($colors_value)) {
...@@ -474,8 +481,8 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul ...@@ -474,8 +481,8 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
$filter= nap_filter_attribute($post_ID,$search[$value],$value,true); $filter= nap_filter_attribute($post_ID,$search[$value],$value,true);
else else
$filter= nap_filter_attribute($post_ID,$search[$value],$value); $filter= nap_filter_attribute($post_ID,$search[$value],$value);
endforeach;*/ endforeach; */
if (isset($search['pa_format']) && $search['pa_format'] != '') { /* if (isset($search['pa_format']) && $search['pa_format'] != '') {
$format_value = get_the_terms($post_ID, 'pa_format'); $format_value = get_the_terms($post_ID, 'pa_format');
$filter = "hidden"; $filter = "hidden";
...@@ -501,7 +508,7 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul ...@@ -501,7 +508,7 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
} }
} }
} }
} } */
if (isset($filter)) if (isset($filter))
$class = $filter; $class = $filter;
...@@ -531,7 +538,8 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul ...@@ -531,7 +538,8 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
$nap_article.='</ul>'; $nap_article.='</ul>';
endif; endif;
$nap_article.='</figure> $nap_article.='</figure>
<h3 class = "font-small" >' . get_the_title($post_ID) . '</h3>
<h3 class = "font-small" >' . $title_item . '</h3>
</article>'; </article>';
return $nap_article; return $nap_article;
...@@ -718,3 +726,20 @@ function nap_trash_fiche_technique($post_id) { ...@@ -718,3 +726,20 @@ function nap_trash_fiche_technique($post_id) {
$wpdb->delete($table, array('meta_key' => 'fiche_simple_auto', 'meta_value' => $post->post_title)); $wpdb->delete($table, array('meta_key' => 'fiche_simple_auto', 'meta_value' => $post->post_title));
$wpdb->delete($table, array('meta_key' => 'fiche_var_auto', 'meta_value' => $post->post_title)); $wpdb->delete($table, array('meta_key' => 'fiche_var_auto', 'meta_value' => $post->post_title));
} }
add_action( 'pre_get_posts', 'nap_change_filter_post' );
function nap_change_filter_post() {
global $wp_query;
if(is_admin()) {
if(!empty($wp_query->query_vars['product_cat'])) {
setcookie("product_cat", $wp_query->query_vars['product_cat']);
}
if(!isset($_GET['product_cat']) && ($_GET['post_type'] == 'product')) {
$wp_query->query_vars['product_cat'] = $_COOKIE['product_cat'];
}
elseif(isset($_GET['product_cat']) && empty($_GET['product_cat'])) {
setcookie("product_cat", $wp_query->query_vars['product_cat']);
}
}
}
...@@ -39,7 +39,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -39,7 +39,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div> </div>
<div class="right-container"> <div class="right-container">
<div class="left-panel fixed-full position--after-menu "> <div class="left-panel fixed-full position--after-menu ">
<?php if($cateID != 20):?> <?php if ($cateID != 20): ?>
<div class="filter-wrapper"> <div class="filter-wrapper">
<div class="filter-btn fixed position--after-menu"> <div class="filter-btn fixed position--after-menu">
<div class="btn-container"><span class="abs-center font-small">Filtres</span></div> <div class="btn-container"><span class="abs-center font-small">Filtres</span></div>
...@@ -55,40 +55,45 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -55,40 +55,45 @@ $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'); $attributes = array('Univers' => 'pa_univers', 'Matiére' => 'pa_matiere', 'Format' => 'pa_format', 'Couleurs' => 'pa_couleur');
foreach ($attributes as $key => $value) : foreach ($attributes as $key => $value) :
?> ?>
<div class="filter-bloc <?php if($_GET[$value]!='') echo 'active selected-filter'; ?>"> <div class="filter-bloc <?php if ($_GET[$value] != '') echo 'active selected-filter'; ?>">
<div class="header"> <div class="header">
<p><span><?php echo $key ?></span></p> <p><span><?php echo $key ?></span></p>
</div> </div>
<?php <?php
if ($value == 'pa_couleur') if ($value == 'pa_couleur') {
$terms = get_terms($value); $terms = get_terms($value);
else } else
$terms = nap_attribute_by_category ($cateID, $value); $terms = nap_attribute_by_category($cateID, $value);
if (!empty($terms) && !is_wp_error($terms)): if (!empty($terms) && !is_wp_error($terms)):
?> ?>
<div class="bloc-content"> <div class="bloc-content">
<ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>"> <ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>">
<?php <?php
$colors = array();
foreach ($terms as $term) : foreach ($terms as $term) :
if ($value == 'pa_couleur'): if ($value == 'pa_couleur'):
$color = get_field('couleurs', 'pa_couleur_' . $term->term_id); $colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id);
if (isset($color) && strlen($color) > 0):
$filter_class = nap_selected_filter($_GET['pa_couleur'],$color);
?>
<li data-color = "<?php echo $color; ?>" class="<?php echo $term->name.' '.$filter_class; ?>"></li>
<?php
endif;
else : else :
$filter_format = nap_selected_filter($_GET['pa_format'],$term); $filter_format = nap_selected_filter($_GET['pa_format'], $term);
$filter_matiere = nap_selected_filter($_GET['pa_matiere'],$term); $filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term);
$filter_univers = nap_selected_filter($_GET['pa_univers'], $term);
?> ?>
<li class="<?php echo $filter_format.' '.$filter_matiere; ?>"><?php echo $term; ?></li> <li class="<?php echo $filter_format . ' ' . $filter_matiere .' '.$filter_univers ; ?>"><?php echo $term; ?></li>
<?php <?php
endif; endif;
endforeach; endforeach;
foreach (array_unique($colors) as $name => $code) {
if (isset($code) && strlen($code) > 0):
$filter_class = nap_selected_filter($_GET['pa_couleur'], $code);
?>
<li data-color = "<?php echo $code; ?>" class="<?php echo $name . ' ' . $filter_class; ?>"></li>
<?php
endif;
}
if ($value == 'pa_couleur'): if ($value == 'pa_couleur'):
?> ?>
...@@ -110,7 +115,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -110,7 +115,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div> </div>
</div> </div>
</div> </div>
<?php endif;?> <?php endif; ?>
<?php <?php
foreach ($child_category as $key => $value) : foreach ($child_category as $key => $value) :
?> ?>
...@@ -125,9 +130,9 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -125,9 +130,9 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div> </div>
<div class="right-panel right"> <div class="right-panel right">
<div class="panel panel-content list-animation"> <div class="panel panel-content list-animation">
<?php if($_GET['pa_couleur']!='' || $_GET['pa_format']!='' || $_GET['pa_matiere']!=''):?> <?php if ($_GET['pa_couleur'] != '' || $_GET['pa_format'] != '' || $_GET['pa_matiere'] != ''): ?>
<span style =" position: relative; display: block;top: 80px;font-size: 11px;" class="search_result">Résultat de votre recherche :</span> <span class="search_result">Résultat de votre recherche :</span>
<?php endif;?> <?php endif; ?>
<?php foreach ($child_category as $key => $value) : ?> <?php foreach ($child_category as $key => $value) : ?>
...@@ -140,12 +145,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -140,12 +145,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div> </div>
<div class="product-list"> <div class="product-list">
<?php <?php
$args = array('post_type' => 'product', 'stock' => 1, 'posts_per_page' => -1, 'product_cat' => $value->name, 'orderby' => 'title' , 'order' => 'ASC'); $args = array('post_type' => 'product', 'stock' => 1, 'posts_per_page' => -1, 'product_cat' => $value->name, 'orderby' => 'title', 'order' => 'ASC');
$naps_posts = new WP_Query($args); $naps_posts = new WP_Query($args);
$options = array(); $options = array();
while ($naps_posts->have_posts()) : $naps_posts->the_post(); while ($naps_posts->have_posts()) : $naps_posts->the_post();
$id = get_the_ID(); $id = get_the_ID();
$list_att = array();
$options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small'; $options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small';
$args = array( $args = array(
...@@ -156,12 +162,36 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -156,12 +162,36 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
'order' => 'asc', 'order' => 'asc',
'post_parent' => $id 'post_parent' => $id
); );
?> $attribute_value['pa_couleur'] = get_the_terms($id, 'pa_couleur');
$attribute_value['pa_format'] = get_the_terms($id, 'pa_format');
<?php echo nap_get_item($id, $args, $current_page, $options,$_GET); ?> $attribute_value['pa_matiere'] = get_the_terms($id, 'pa_matiere');
$attribute_value['pa_univers'] = get_the_terms($id, 'pa_univers');
<?php if ($_GET) {
if (is_array($attribute_value['pa_couleur'])) {
foreach ($attribute_value['pa_couleur'] as $key => $value) {
$list_att['pa_couleur'] = nap_color_attribute($value->slug);
}
}
if (is_array($attribute_value['pa_format'])) {
foreach ($attribute_value['pa_format'] as $key => $value) {
$list_att['pa_format'] = $value->name;
}
}
if (is_array($attribute_value['pa_matiere'])) {
foreach ($attribute_value['pa_matiere'] as $key => $value) {
$list_att['pa_matiere'] = $value->name;
}
}
if (is_array($attribute_value['pa_univers'])) {
foreach ($attribute_value['pa_univers'] as $key => $value) {
$list_att['pa_univers'] = $value->name;
}
}
nap_filter_attribute($id, $args, $options, $list_att, $_GET);
} else {
echo nap_get_item($id, $args, $current_page, $options);
}
endwhile; endwhile;
wp_reset_query(); wp_reset_query();
?> ?>
......
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