2025-11-04

This commit is contained in:
gcch 2025-11-04 13:21:41 +01:00
commit 71c35a497f
1626 changed files with 5901 additions and 2182 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* Le modèle du reçu envoyé au client (« Order Details »).
*/
@ -9,76 +12,76 @@ use Illuminate\Support\Number;
use Illuminate\Support\Str;
use Timber\Timber;
if (!defined("ABSPATH")) {
exit();
if (!defined('ABSPATH')) {
exit();
}
// Initialise Timber
Timber::init();
// Sélectionne le répertoire contenant les modèles Twig
Timber::$dirname = ["views"];
Timber::$dirname = ['views'];
// Contexte et modèles
$contexte = Timber::context();
$modeles = ["email-base.twig"];
$modeles = ['email-base.twig'];
/** @var Order $commande La Commande issue du contexte contenu dans la variable $order. */
$commande = $order;
/** @var Carbon $date */
$date = new Carbon($commande->get_date_created());
$email = [
"adresses" => [
"facturation" => $commande->get_address("billing"),
"livraison" => $commande->get_address("shipping"),
],
"commande" => [
"date" => $date->toDateString(),
"id" => $commande->get_id(),
],
"livraison" => [
"methode" => $commande->get_shipping_method(),
"numero_suivi" => $commande->get_meta("tracking_number"),
],
"paiement" => [
"methode" => "",
],
"produits" => collect($commande->get_items())->map(function (WC_Order_Item_Product $article) {
/** @var WC_Product_Simple|WC_Product_Variable $produit */
$produit = wc_get_product($article["product_id"]);
/** @var WC_Product_Simple|WC_Product_Variation $produit_article */
$produit_article = $article->get_product();
'adresses' => [
'facturation' => $commande->get_address('billing'),
'livraison' => $commande->get_address('shipping'),
],
'commande' => ['date' => $date->toDateString(), 'id' => $commande->get_id()],
'livraison' => [
'methode' => $commande->get_shipping_method(),
'numero_suivi' => $commande->get_meta('tracking_number'),
],
'paiement' => ['methode' => ''],
'produits' => collect($commande->get_items())->map(function (WC_Order_Item_Product $article) {
/** @var WC_Product_Simple|WC_Product_Variable $produit */
$produit = wc_get_product($article['product_id']);
return [
// Récupère l'Attribut d'un Produit variable ou renvoie un tableau vide
"attribut" => $produit->is_type("variable")
? collect($produit->get_attributes())
->mapWithKeys(function ($atr, $cle) use ($produit_article) {
return [
"nom" => Str::lower(wc_attribute_label($cle, $produit_article)),
"valeur" => $produit_article->get_attribute($cle),
];
})
->toArray()
: [],
"lien" => $produit->get_permalink(),
"nom" => $produit->get_title(),
"prix_total" => $article->get_total(),
"quantite" => $article->get_quantity(),
];
}),
"totaux" => [
"sous_total_livraison" => $commande->get_shipping_total() == "0" ? "Free" : $commande->get_shipping_total() . "",
"sous_total_produits" => $commande->get_subtotal() . "",
"sous_total_reduction" =>
$commande->get_discount_total == "0.00"
? "0"
: Number::format($commande->get_discount_total(), maxPrecision: 2) . "",
"total" => Number::format($commande->get_total(), maxPrecision: 2) . "",
],
/** @var WC_Product_Simple|WC_Product_Variation $produit_article */
$produit_article = $article->get_product();
return [
// Récupère l'Attribut d'un Produit variable ou renvoie un tableau vide
'attribut' => $produit->is_type('variable')
? collect($produit->get_attributes())
->mapWithKeys(fn($atr, $cle) => [
'nom' => Str::lower(wc_attribute_label($cle, $produit_article)),
'valeur' => $produit_article->get_attribute($cle),
])
->toArray()
: [],
'lien' => $produit->get_permalink(),
'nom' => $produit->get_title(),
'prix_total' => $article->get_total(),
'quantite' => $article->get_quantity(),
];
}),
'totaux' => [
'sous_total_livraison' => '0' === $commande->get_shipping_total()
? 'Free'
: $commande->get_shipping_total() . '€',
'sous_total_produits' => $commande->get_subtotal() . '€',
'sous_total_reduction' => '0.00' === $commande->get_discount_total
? '0'
: Number::format($commande->get_discount_total(), maxPrecision: 2) . '€',
'total' => Number::format($commande->get_total(), maxPrecision: 2) . '€',
],
];
// Transforme les codes de pays en noms de pays
$email["adresses"]["livraison"]["country"] = WC()->countries->countries[$commande->get_shipping_country()];
$email["adresses"]["facturation"]["country"] = WC()->countries->countries[$commande->get_billing_country()];
$email['adresses']['livraison']['country'] = WC()->countries->countries[$commande->get_shipping_country()];
$email['adresses']['facturation']['country'] = WC()->countries->countries[$commande->get_billing_country()];
$contexte["commande"] = $email;
$contexte['commande'] = $email;
// Rendu
Timber::render(filenames: $modeles, data: $contexte);
Timber::render(
filenames: $modeles,
data: $contexte,
);