haiku-atelier-2024/web/app/themes/haiku-atelier-2024/page-shop.php
2024-08-09 18:47:38 +02:00

48 lines
1.2 KiB
PHP

<?php
/**
* Le modèle de la Page Boutique (« E-Shop »).
*/
declare(strict_types=1);
use Timber\Timber;
// Contexte et modèles
$contexte = Timber::context();
$modeles = ["boutique.twig"];
// Récupère les Produits
$recupere_informations_produit = fn($produit) => [
"id" => $produit->get_id(),
"nom" => $produit->get_name(),
"prix" => $produit->get_price(),
"slug" => $produit->get_slug(),
"premiere_photo_gauche" => wp_get_attachment_image(
get_post_meta($post_id = $produit->get_id(), $key = "_photos_colonne_gauche|||0|value")[0],
"full",
false,
["loading" => false],
),
"premiere_photo_droite" => wp_get_attachment_image(
get_post_meta($post_id = $produit->get_id(), $key = "_photos_colonne_droite|||0|value")[0],
"full",
false,
["loading" => false],
),
"url" => $produit->get_permalink(),
];
$informations_produits = wc_get_products([
"orderby" => "date",
"order" => "DESC",
]);
$produits = array_map($callback = $recupere_informations_produit, $array = $informations_produits);
$contexte["produits"] = $produits;
// echo "<pre>";
// print_r($informations_produits);
// print_r($produits);
// echo "</pre>";
// Rendu
Timber::render($filenames = $modeles, $data = $contexte);