fonc(contexte) récupère plusieurs ensembles de données
- les informations de pages ; - les catégories de Produits ; - le panier.
This commit is contained in:
parent
7592508874
commit
eba795db4e
4 changed files with 73 additions and 29 deletions
|
|
@ -7,26 +7,8 @@ declare(strict_types=1);
|
|||
|
||||
use Timber\Timber;
|
||||
|
||||
/* Récupère les Catégories de Produits */
|
||||
$categories_produits = get_categories([
|
||||
"hide_empty" => false,
|
||||
"orderby" => "menu_order",
|
||||
"taxonomy" => "product_cat",
|
||||
]);
|
||||
$cree_entree_menu = fn ($categorie) => [
|
||||
"nom" => $categorie->name,
|
||||
"slug" => $categorie->slug,
|
||||
];
|
||||
$entrees_menu_categories = array_map($callback = $cree_entree_menu, $array = $categories_produits);
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($zzz);
|
||||
// echo "</pre>";
|
||||
|
||||
/* Contexte et modèles */
|
||||
$contexte = Timber::context();
|
||||
$contexte["categories_produits"] = $entrees_menu_categories;
|
||||
|
||||
$modeles = ["accueil.twig"];
|
||||
|
||||
/* Rendu */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace HaikuAtelier;
|
||||
|
||||
use stdClass;
|
||||
use Timber\Site;
|
||||
|
||||
require_once __DIR__ . "/inc/Fonctionnalites.php";
|
||||
|
|
@ -44,10 +45,56 @@ class StarterSite extends Site {
|
|||
$logo_personnalisee = wp_get_attachment_image_src($logo_personnalisee_id, "full");
|
||||
$context["logo"] = $logo_personnalisee;
|
||||
|
||||
// Informations des Pages
|
||||
$recupere_informations_page = function ($slug) {
|
||||
$page = get_page_by_path($slug);
|
||||
|
||||
return (object) [
|
||||
"nom" => $page->post_title ?? "",
|
||||
"lien" => get_page_link($page->ID),
|
||||
];
|
||||
};
|
||||
|
||||
// Pages spécifiques
|
||||
$pages = (object) [
|
||||
"about" => $recupere_informations_page("about"),
|
||||
"account" => $recupere_informations_page("account"),
|
||||
"cart" => $recupere_informations_page("cart"),
|
||||
"contact" => $recupere_informations_page("contact"),
|
||||
"checkout" => $recupere_informations_page("checkout"),
|
||||
"home" => $recupere_informations_page("home"),
|
||||
"shop" => $recupere_informations_page("shop"),
|
||||
];
|
||||
|
||||
$context["pages"] = $pages;
|
||||
|
||||
// Politique de confidentialité
|
||||
$politique_confidentialite_lien = esc_url(get_privacy_policy_url());
|
||||
$context["lien_politique_confidentialite"] = $politique_confidentialite_lien;
|
||||
|
||||
/* Récupère les Catégories de Produits */
|
||||
$categories_produits = get_categories([
|
||||
"hide_empty" => false,
|
||||
"orderby" => "menu_order",
|
||||
"taxonomy" => "product_cat",
|
||||
]);
|
||||
$cree_entree_menu = fn($categorie) => [
|
||||
"nom" => $categorie->name,
|
||||
"slug" => $categorie->slug,
|
||||
];
|
||||
$entrees_menu_categories = array_map($callback = $cree_entree_menu, $array = $categories_produits);
|
||||
|
||||
$context["categories_produits"] = $entrees_menu_categories;
|
||||
|
||||
// Récupère le Panier de l'Utilisateur
|
||||
$panier = WC()->cart->get_cart();
|
||||
$quantite_articles = sizeof($panier);
|
||||
$articles_presents = $quantite_articles > 0 ? "oui" : "non";
|
||||
|
||||
$context["panier"] = $panier;
|
||||
$context["quantite_articles"] = $quantite_articles;
|
||||
$context["articles_presents"] = $articles_presents;
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,48 @@
|
|||
<header id="en-tete">
|
||||
<div class="logo">
|
||||
<section class="logo">
|
||||
<figure>
|
||||
<picture>
|
||||
<img
|
||||
alt="Le logo Haiku Atelier"
|
||||
alt="Haiku Atelier's Logo"
|
||||
src="{{ site.theme.link }}/assets/img/logos/logo-lines.svg"
|
||||
>
|
||||
</picture>
|
||||
</figure>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<nav class="menu-navigation" id="menu-navigation-en-tete">
|
||||
<ul class="avec-puce-cercle">
|
||||
<span class="menu-navigation__entree">
|
||||
<li><a href="#">Home</a></li>
|
||||
<li>
|
||||
<a href="{{ pages.home.lien }}">
|
||||
{{ pages.home.nom }}</a>
|
||||
</li>
|
||||
</span>
|
||||
<span class="menu-navigation__entree">
|
||||
<li><a href="#">About</a></li>
|
||||
<li>
|
||||
<a href="{{ pages.about.lien }}">
|
||||
{{ pages.about.nom }}</a>
|
||||
</li>
|
||||
</span>
|
||||
<span class="menu-navigation__entree">
|
||||
<li><a href="#">E-Shop</a></li>
|
||||
<li>
|
||||
<a href="{{ pages.shop.lien }}">
|
||||
{{ pages.shop.nom }}</a>
|
||||
</li>
|
||||
</span>
|
||||
<span class="menu-navigation__entree">
|
||||
<li><a href="#">Contact</a></li>
|
||||
<li>
|
||||
<a href="{{ pages.contact.lien }}">
|
||||
{{ pages.contact.nom }}</a>
|
||||
</li>
|
||||
</span>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="panier">
|
||||
<a class="panier__lien lien-bouton" href="#" rel="cart">cart (0)</a>
|
||||
</div>
|
||||
<section class="compte-panier">
|
||||
<a class="lien-bouton lien-compte" href="#">Account</a>
|
||||
<a class="lien-bouton" data-contient-articles="{{ articles_presents }}" href="#" rel="cart">
|
||||
cart ({{ quantite_articles }})
|
||||
</a>
|
||||
</section>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<nav id="menu-categories-produits" class="menu-categories-produits">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/boutique">Tout</a>
|
||||
<a href="{{ pages.shop.lien }}">All</a>
|
||||
</li>
|
||||
{% for categorie in categories_produits %}
|
||||
<li id="categorie-{{ categorie.slug|e }}">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue