archive-product.php 11.9 KB
Newer Older
imac's avatar
imac committed
1
<?php
Nahla Shiri's avatar
Nahla Shiri committed
2
//print_r($_GET);
imac's avatar
imac committed
3 4 5 6 7 8 9 10 11 12 13
/**
 * The Template for displaying product archives, including the main shop page which is a post type archive
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
imac's avatar
imac committed
14 15 16
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
imac's avatar
imac committed
17 18 19 20 21 22 23
 * @version     2.0.0
 */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
$current_page = 'catalogue';
get_header();
24
$product;
imac's avatar
imac committed
25
$cate = get_queried_object();
Nahla Shiri's avatar
Nahla Shiri committed
26
$cateID = $cate->term_id;
imac's avatar
imac committed
27 28

//SubCats
imac's avatar
imac committed
29
$child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' => the_category_ID(), 'exclude' => $cateID, 'orderby' => 'title', 'order' => 'ASC'));
imac's avatar
imac committed
30 31 32 33 34
?>

<div class="container clearfix" id="catalogue" data-page = "<?php echo $cateID; ?>">
    <div class="container-bg abs-full"></div>
    <?php get_sidebar() ?>
imac's avatar
imac committed
35 36 37 38 39
    <div class="header mobile-nav display--only-mobile blue-bg fixed">
        <div class="nav-wrapper blue-bg">
            <ul></ul>
        </div>
    </div>
imac's avatar
imac committed
40 41
    <div class="right-container">
        <div class="left-panel fixed-full position--after-menu ">
Nahla Shiri's avatar
Nahla Shiri committed
42 43 44 45 46 47 48 49 50 51 52
            <?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>
                    </div>
                    <div class="filter-content">
                        <div class="filter-list fixed position--after-menu">
                            <div class="top-header">
                                <span>Filtres</span>
                                <span class="close-btn"></span>
                            </div>
imac's avatar
imac committed
53

Nahla Shiri's avatar
Nahla Shiri committed
54 55 56 57 58 59 60 61
                            <?php
                            $attributes = array('Univers' => 'pa_univers', 'Matiére' => 'pa_matiere', 'Format' => 'pa_format', 'Couleurs' => 'pa_couleur');
                            foreach ($attributes as $key => $value) :
                                ?>
                                <div class="filter-bloc <?php if ($_GET[$value] != '') echo 'active selected-filter'; ?>">
                                    <div class="header">
                                        <p><span><?php echo $key ?></span></p>
                                    </div>
imac's avatar
imac committed
62

Nahla Shiri's avatar
Nahla Shiri committed
63 64 65 66 67 68 69 70 71 72
                                    <?php
                                    if ($value == 'pa_couleur') {
                                        $terms = get_terms($value);
                                    } else
                                        $terms = nap_attribute_by_category($cateID, $value);

                                    if (!empty($terms) && !is_wp_error($terms)):
                                        ?>
                                        <div class="bloc-content">
                                            <ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>">
Nahla Shiri's avatar
Nahla Shiri committed
73 74
                                                <?php
                                                $colors = array();
Nahla Shiri's avatar
Nahla Shiri committed
75 76 77
                                               
                                                foreach ( $terms as $term) :
                                                    
Nahla Shiri's avatar
Nahla Shiri committed
78 79 80 81 82 83 84
                                                    if ($value == 'pa_couleur'):
                                                        $colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id);

                                                    else :
                                                        $filter_format = nap_selected_filter($_GET['pa_format'], $term);
                                                        $filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term);
                                                        $filter_univers = nap_selected_filter($_GET['pa_univers'], $term);
Nahla Shiri's avatar
Nahla Shiri committed
85 86 87 88 89 90 91
                                                        
                                                        if($value == 'pa_univers')
                                                        {   $unv = get_term_by('name', $term, 'pa_univers');
    $termID = $term->term_id;
                                                           $date_deb = get_field('uv_date_debut', 'pa_univers_' . $unv->term_id);
                                                           $date_fin = get_field('uv_date_fin', 'pa_univers_' . $unv->term_id);
                                                        }
Nahla Shiri's avatar
Nahla Shiri committed
92
                                                        ?>
Nahla Shiri's avatar
Nahla Shiri committed
93
                                                
Nahla Shiri's avatar
Nahla Shiri committed
94 95 96 97 98 99 100 101
                                                        <li class="<?php echo $filter_format . ' ' . $filter_matiere .' '.$filter_univers ; ?>"><?php echo $term; ?></li>
                                                    <?php
                                                    endif;
                                                endforeach;
                                                foreach (array_unique($colors) as $name => $code) {
                                                    if (isset($code) && strlen($code) > 0):
                                                        $filter_class = nap_selected_filter($_GET['pa_couleur'], $code);
                                                        ?>
Nahla Shiri's avatar
Nahla Shiri committed
102
                                                        <li data-color = "<?php echo $code; ?>" class="<?php echo $name . ' ' . $filter_class; ?>"></li>
103 104
                                                        <?php
                                                    endif;
Nahla Shiri's avatar
Nahla Shiri committed
105 106
                                                }
                                                if ($value == 'pa_couleur'):
107 108
                                                    ?>

Nahla Shiri's avatar
Nahla Shiri committed
109
                                                    <li class="reinit">Tout déselectionner</li>
Nahla Shiri's avatar
Nahla Shiri committed
110
                                                <?php endif; ?>
Nahla Shiri's avatar
Nahla Shiri committed
111 112 113
                                            </ul>

                                        </div>
Nahla Shiri's avatar
Nahla Shiri committed
114
                                    <?php endif; ?>
Nahla Shiri's avatar
Nahla Shiri committed
115
                                </div>
Nahla Shiri's avatar
Nahla Shiri committed
116
                            <?php endforeach; ?>
117 118 119



Nahla Shiri's avatar
Nahla Shiri committed
120 121 122 123
                            <div class="center filter-btn-list">
                                <div class="btn pink-btn rounded" id="search-btn">Rechercher</div>
                                <span class = "reinit-all">Effacer les filtres</span>
                            </div>
imac's avatar
imac committed
124 125 126
                        </div>
                    </div>
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
127
            <?php endif; ?>
imac's avatar
imac committed
128 129 130 131
            <?php
            foreach ($child_category as $key => $value) :
                ?>
                <div class="cover-wrapper abs-full transition" data-cat = "#cat<?php echo $value->term_id ?>" style = "background-image: url('<?php echo nap_category_image($value->term_id) ?>')">
132 133 134
                    <div class="cover-desc-wrapper">
                        <p><?php echo $value->description; ?></p>
                    </div>
imac's avatar
imac committed
135
                </div>   
Nahla Shiri's avatar
Nahla Shiri committed
136 137 138
                <?php
            endforeach;
            ?>
imac's avatar
imac committed
139 140 141
        </div>
        <div class="right-panel right">
            <div class="panel panel-content list-animation">
Nahla Shiri's avatar
Nahla Shiri committed
142
                <?php if ($_GET['pa_couleur'] != '' || $_GET['pa_format'] != '' || $_GET['pa_matiere'] != ''): ?>
Nahla Shiri's avatar
Nahla Shiri committed
143 144 145
                    <span  class="search_result">Résultat de votre recherche :</span>
                <?php endif; ?>

imac's avatar
imac committed
146
                <?php foreach ($child_category as $key => $value) : ?>
Nahla Shiri's avatar
Nahla Shiri committed
147

imac's avatar
imac committed
148 149
                    <section id = "cat<?php echo $value->term_id ?>">
                        <h2 class="crete small-title"><?php echo $value->name ?></h2>
imac's avatar
imac committed
150 151 152 153 154
                        <div class="cover-mobile display--only-mobile animated fadeInUp" style = "background-image: url('<?php echo nap_category_image($value->term_id) ?>')">
                            <div class="cover-desc-wrapper">
                                <p><?php echo $value->description; ?></p>
                            </div>
                        </div>
imac's avatar
imac committed
155
                        <div class="product-list">
Nahla Shiri's avatar
Nahla Shiri committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                            <?php
                            $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);
                            $options = array();

                            while ($naps_posts->have_posts()) : $naps_posts->the_post();
                                $id = get_the_ID();
                                $list_att = array();

                                $options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small';
                                $args = array(
                                    'post_type' => array('product', 'product_variation'),
                                    'post_status' => array('private', 'publish'),
                                    'numberposts' => -1,
                                    'orderby' => 'menu_order',
                                    'order' => 'asc',
                                    'post_parent' => $id
                                );
Nahla Shiri's avatar
Nahla Shiri committed
174 175 176 177
                                $attribute_value['pa_couleur'] = get_the_terms($id, 'pa_couleur');
                                $attribute_value['pa_format'] = get_the_terms($id, 'pa_format');
                                $attribute_value['pa_matiere'] = get_the_terms($id, 'pa_matiere');
                                $attribute_value['pa_univers'] = get_the_terms($id, 'pa_univers');
Nahla Shiri's avatar
Nahla Shiri committed
178

Nahla Shiri's avatar
Nahla Shiri committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                                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;
                                        }
                                    }
Nahla Shiri's avatar
Nahla Shiri committed
200
                                    
Nahla Shiri's avatar
Nahla Shiri committed
201
                                    nap_filter_attribute($id, $args, $options, $list_att, $_GET);
Nahla Shiri's avatar
Nahla Shiri committed
202 203 204
                                } else {
                                    echo nap_get_item($id, $args, $current_page, $options);
                                }
imac's avatar
imac committed
205 206 207 208 209
                            endwhile;
                            wp_reset_query();
                            ?>
                        </div> 
                    </section>
Nahla Shiri's avatar
Nahla Shiri committed
210
                <?php endforeach; ?>
imac's avatar
imac committed
211 212 213 214
            </div>
        </div>
    </div>
</div>
Nahla Shiri's avatar
Nahla Shiri committed
215
<?php get_footer(); ?>