corvée(fmt) formate
This commit is contained in:
parent
4720c46ff8
commit
fdb6aaa7e9
23 changed files with 139 additions and 156 deletions
|
|
@ -11,21 +11,21 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
use function Env\env;
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
// USE_ENV_ARRAY + CONVERT_* + STRIP_QUOTES
|
||||
Env\Env::$options = 31;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Directory containing all of the site's files.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
$root_dir = dirname(__DIR__);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Document Root.
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -59,7 +59,7 @@ if (file_exists($root_dir.'/.env')) {
|
|||
define('WP_ENV', env('WP_ENV') ?: 'production');
|
||||
|
||||
// Infer WP_ENVIRONMENT_TYPE based on WP_ENV
|
||||
if (!env('WP_ENVIRONMENT_TYPE') && in_array(WP_ENV, ['production', 'staging', 'development', 'local'])) {
|
||||
if (!env('WP_ENVIRONMENT_TYPE') && in_array(WP_ENV, ['production', 'staging', 'development', 'local'], true)) {
|
||||
Config::define('WP_ENVIRONMENT_TYPE', WP_ENV);
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ Config::define('WP_CONTENT_URL', Config::get('WP_HOME').Config::get('CONTENT_DIR
|
|||
|
||||
// DB settings
|
||||
if (env('DB_SSL')) {
|
||||
Config::define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
|
||||
Config::define('MYSQL_CLIENT_FLAGS', \MYSQLI_CLIENT_SSL);
|
||||
}
|
||||
|
||||
Config::define('DB_NAME', env('DB_NAME'));
|
||||
|
|
@ -88,9 +88,9 @@ $table_prefix = env('DB_PREFIX') ?: 'wp_';
|
|||
if (env('DATABASE_URL')) {
|
||||
$dsn = (object) parse_url(env('DATABASE_URL'));
|
||||
|
||||
Config::define('DB_NAME', substr($dsn->path, 1));
|
||||
Config::define('DB_NAME', mb_substr($dsn->path, 1));
|
||||
Config::define('DB_USER', $dsn->user);
|
||||
Config::define('DB_PASSWORD', isset($dsn->pass) ? $dsn->pass : null);
|
||||
Config::define('DB_PASSWORD', $dsn->pass ?? null);
|
||||
Config::define('DB_HOST', isset($dsn->port) ? "{$dsn->host}:{$dsn->port}" : $dsn->host);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
use function Env\env;
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
Config::define('SAVEQUERIES', true);
|
||||
Config::define('WP_DEBUG', true);
|
||||
Config::define('WP_DEBUG_DISPLAY', false);
|
||||
Config::define('WP_DEBUG_DISPLAY', true);
|
||||
Config::define('WP_DEBUG_LOG', env('WP_DEBUG_LOG') ?? true);
|
||||
Config::define('WP_DISABLE_FATAL_ERROR_HANDLER', true);
|
||||
Config::define('SCRIPT_DEBUG', true);
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
use function Env\env;
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
Config::define('WP_DEBUG', true);
|
||||
Config::define('WP_DEBUG_DISPLAY', false);
|
||||
Config::define('WP_DEBUG_LOG', env('WP_DEBUG_LOG') ?? true);
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
use function Env\env;
|
||||
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
Config::define('DISALLOW_INDEXING', true);
|
||||
Config::define('WOOCOMMERCE_API_CONSUMER_KEY', env('WOOCOMMERCE_API_CONSUMER_KEY'));
|
||||
Config::define('WOOCOMMERCE_API_CONSUMER_SECRET', env('WOOCOMMERCE_API_CONSUMER_SECRET'));
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require_once 'web/wp/wp-load.php';
|
||||
|
||||
ini_set('max_execution_time', 3600);
|
||||
set_time_limit(3600);
|
||||
ini_set('max_execution_time', 3_600);
|
||||
set_time_limit(3_600);
|
||||
|
||||
$pdo = new PDO('mysql:dbname=haiku_atelier;host=localhost', 'haiku_utilisateur', 'spNFx5EAYwvF7o7XFMjiHpNPYJimDtmKWv');
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ require_once __DIR__ . '/src/inc/TraitementInformations.php';
|
|||
$contexte = Timber::context();
|
||||
$modeles = ['boutique.twig'];
|
||||
|
||||
/** @var array<WC_Product> $informations_produits Les informations brutes des Produits. */
|
||||
/** @var list<WC_Product> $informations_produits Les informations brutes des Produits. */
|
||||
$informations_produits = wc_get_products([
|
||||
'limit' => 12,
|
||||
'order' => 'DESC',
|
||||
|
|
@ -22,9 +22,9 @@ $informations_produits = wc_get_products([
|
|||
'status' => 'publish',
|
||||
]);
|
||||
|
||||
/** @var InformationsProduitShop $produits Les informations strictement nécessaires pour la grille des Produits. */
|
||||
/** @var mixed $produits Les informations strictement nécessaires pour la grille des Produits. */
|
||||
$produits = array_map(
|
||||
callback: 'recupere_informations_produit_shop',
|
||||
callback: recupere_informations_produit_shop(...),
|
||||
array: $informations_produits,
|
||||
);
|
||||
$contexte['produits'] = $produits;
|
||||
|
|
|
|||
|
|
@ -71,10 +71,8 @@ new StarterSite();
|
|||
|
||||
/**
|
||||
* Personnalisation du thème.
|
||||
*
|
||||
* @param mixed $wp_customize
|
||||
*/
|
||||
function enregistre_personnalisations_theme($wp_customize) {
|
||||
function enregistre_personnalisations_theme(mixed $wp_customize): void {
|
||||
// Section « Réseaux sociaux »
|
||||
$wp_customize->add_section('liens_reseaux_sociaux', [
|
||||
'title' => __('Liens des réseaux sociaux'),
|
||||
|
|
@ -149,15 +147,15 @@ function enregistre_personnalisations_theme($wp_customize) {
|
|||
add_action('customize_register', 'enregistre_personnalisations_theme');
|
||||
|
||||
function retire_tailles_image_par_defaut(mixed $sizes): mixed {
|
||||
error_log(print_r($sizes, true));
|
||||
|
||||
/** @var array<string> */
|
||||
/** @var list<string> */
|
||||
$targets = ['full', 'thumbnail'];
|
||||
|
||||
foreach ($sizes as $size_index => $size) {
|
||||
if (!in_array($size, $targets, true)) {
|
||||
unset($sizes[$size_index]);
|
||||
if (in_array($size, $targets, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($sizes[$size_index]);
|
||||
}
|
||||
|
||||
return $sizes;
|
||||
|
|
@ -171,7 +169,7 @@ add_filter('async_update_translation', '__return_false');
|
|||
add_filter('auto_update_translation', '__return_false');
|
||||
|
||||
// Block Patterns
|
||||
add_action('after_setup_theme', function () {
|
||||
add_action('after_setup_theme', static function (): void {
|
||||
remove_theme_support('core-block-patterns');
|
||||
});
|
||||
add_filter('should_load_remote_block_patterns', '__return_false');
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Le modèle de la Page Panier (« Cart »).
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Number;
|
||||
use Timber\Timber;
|
||||
|
||||
use function Crell\fp\pipe;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
use Timber\Timber;
|
||||
|
||||
// Importe la fonction pour récupérer les informations affichées des Produits dans le Panier
|
||||
require_once __DIR__ . '/src/inc/TraitementInformations.php';
|
||||
|
|
@ -95,25 +93,25 @@ $panier = [];
|
|||
/** @var float $sous_total_panier Le sous-total de la Commande dans le Panier. */
|
||||
$sous_total_panier = WC()->cart->get_subtotal();
|
||||
|
||||
/** @var null|string $code_promo Le code promo appliqué au Panier s'il existe. */
|
||||
/** @var string|null $code_promo Le code promo appliqué au Panier s'il existe. */
|
||||
$code_promo = collect(WC()->cart->get_applied_coupons())->first();
|
||||
|
||||
/** @var int $sous_total_reduction Le total du montant de la Réduction appliquée au Panier */
|
||||
$sous_total_reduction = Number::format(WC()->cart->get_totals()['discount_total'], maxPrecision: 2);
|
||||
|
||||
/** @var float $total_panier Le total de la Commande dans le Panier. */
|
||||
$total_panier = Number::format(floatval(WC()->cart->get_totals()['total']), maxPrecision: 2);
|
||||
$total_panier = Number::format((float) WC()->cart->get_totals()['total'], maxPrecision: 2);
|
||||
|
||||
foreach (WC()->cart->get_cart() as $cle_panier => $article_panier) {
|
||||
$panier[$cle_panier] = [
|
||||
'attributs' => $article_panier['data']?->get_type() == 'variation'
|
||||
'attributs' => $article_panier['data']?->get_type() === 'variation'
|
||||
? recupere_et_formate_attributs_produit($article_panier['data']?->get_attributes())
|
||||
: [],
|
||||
'cle' => $cle_panier,
|
||||
'id_produit' => $article_panier['product_id'],
|
||||
'id_variation' => $article_panier['variation_id'],
|
||||
'image' => pipe($article_panier['data']?->get_image_id(), fn($id) => genere_balise_img_multiformats(
|
||||
id: $id,
|
||||
'image' => pipe($article_panier['data']?->get_image_id(), static fn($id): string => genere_balise_img_multiformats(
|
||||
id: (string) $id,
|
||||
lazy: true,
|
||||
)),
|
||||
'prix' => $article_panier['data']?->get_price(),
|
||||
|
|
@ -127,15 +125,15 @@ foreach (WC()->cart->get_cart() as $cle_panier => $article_panier) {
|
|||
$email = WC()->customer->get_billing_email();
|
||||
$adresse_livraison = WC()->customer->get_shipping();
|
||||
$adresse_facturation = WC()->customer->get_billing();
|
||||
$adresse_renseignee = $adresse_livraison['city'] != '';
|
||||
$adresse_renseignee = $adresse_livraison['city'] !== '';
|
||||
$pays_livraison = collect(WC()->countries->get_countries())->only($pays_acceptes)->toArray();
|
||||
$total_livraison = Number::format(floatval(WC()->cart->get_totals()['shipping_total']), precision: 0);
|
||||
$total_livraison = Number::format((float) WC()->cart->get_totals()['shipping_total'], precision: 0);
|
||||
$methodes_livraison = collect(WC()->session->get('shipping_for_package_0')['rates'])
|
||||
->values()
|
||||
->map(fn(WC_Shipping_Rate $methode) => [
|
||||
->map(static fn(WC_Shipping_Rate $methode): array => [
|
||||
'id' => $methode->get_method_id(),
|
||||
'prix' => Number::format(intval($methode->get_cost()), maxPrecision: 2),
|
||||
'selectionnee' => collect(WC()->session->get('chosen_shipping_methods'))->first() == $methode->get_id(),
|
||||
'prix' => Number::format((int) $methode->get_cost(), maxPrecision: 2),
|
||||
'selectionnee' => collect(WC()->session->get('chosen_shipping_methods'))->first() === $methode->get_id(),
|
||||
'titre' => $methode->get_label(),
|
||||
]);
|
||||
|
||||
|
|
@ -152,14 +150,6 @@ $contexte['pays_livraison'] = $pays_livraison;
|
|||
$contexte['sous_total_livraison'] = $total_livraison;
|
||||
$contexte['methodes_livraison'] = $methodes_livraison;
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($adresse_livraison);
|
||||
// print_r($adresse_facturation);
|
||||
// print_r($adresse_renseignee);
|
||||
// print_r($methodes_livraison);
|
||||
// print_r(WC()->session->get("chosen_shipping_methods"));
|
||||
// echo "</pre>";
|
||||
|
||||
// Charge les scripts et styles de la page
|
||||
function charge_scripts_styles_page_panier(): void {
|
||||
wp_enqueue_style(
|
||||
|
|
@ -179,6 +169,9 @@ function charge_scripts_styles_page_panier(): void {
|
|||
|
||||
add_action('wp_enqueue_scripts', 'charge_scripts_styles_page_panier');
|
||||
|
||||
$lal = wp_json_encode($contexte);
|
||||
echo "<script>console.debug({$lal});</script>";
|
||||
|
||||
// Rendu
|
||||
Timber::render(
|
||||
filenames: $modeles,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Roots\WPConfig\Config;
|
||||
use Stripe\BillingPortal\Session;
|
||||
use Stripe\Coupon;
|
||||
use Stripe\Product;
|
||||
use Stripe\Stripe;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
|
|
@ -61,13 +61,13 @@ $panier = WC()->cart;
|
|||
/** @var string $email_client */
|
||||
$email_client = WC()->session->get('customer')['email'];
|
||||
|
||||
/** @var array<Product> $articles */
|
||||
/** @var list<Product> $articles */
|
||||
$articles = collect($panier->get_cart())
|
||||
->map(function ($article_panier) {
|
||||
$titre_produit = match ('variable' == $article_panier['data']?->get_type()) {
|
||||
->map(static function ($article_panier) {
|
||||
$titre_produit = match ('variable' === $article_panier['data']?->get_type()) {
|
||||
true => $article_panier['data']?->get_title()
|
||||
. ' ('
|
||||
. explode(': ', $article_panier['data']?->get_attribute_summary())[1]
|
||||
. explode(': ', (string) $article_panier['data']?->get_attribute_summary())[1]
|
||||
. ')',
|
||||
false => $article_panier['data']?->get_title(),
|
||||
};
|
||||
|
|
@ -91,7 +91,6 @@ $articles = collect($panier->get_cart())
|
|||
/** @var WC_Order $commande */
|
||||
$commande = wc_get_order($order_id);
|
||||
|
||||
/** @var mixed $methode_livraison */
|
||||
$methode_livraison = ['nom' => $commande->get_shipping_method(), 'cout' => $commande->get_shipping_total() * 100];
|
||||
|
||||
// Le nom de la méthode de livraison ne peut être une chaîne vide.
|
||||
|
|
@ -105,19 +104,19 @@ Stripe::setApiKey(Config::get('STRIPE_API_SECRET'));
|
|||
// Met à jour les Codes promos
|
||||
$coupons_stripe = collect(Coupon::all()->data);
|
||||
$coupons_wc = collect(WC()->cart->get_coupons())
|
||||
->map(fn(WC_Coupon $coupon) => [
|
||||
->map(static fn(WC_Coupon $coupon): array => [
|
||||
'duration' => 'forever',
|
||||
'id' => $coupon->get_code(),
|
||||
'name' => $coupon->get_code(),
|
||||
'fixed_cart' === $coupon->get_discount_type() ? 'amount_off' : 'percent_off' => $coupon->get_amount(),
|
||||
])
|
||||
->each(function (array $item) use ($coupons_stripe) {
|
||||
->each(static function (array $item) use ($coupons_stripe): void {
|
||||
// Si le code promo n'existe, le créer
|
||||
if (!$coupons_stripe->contains('name', $item['name'])) {
|
||||
Coupon::create($item);
|
||||
}
|
||||
});
|
||||
$reductions_stripe = $coupons_wc->map(fn($coupon) => ['coupon' => $coupon['name']])->values()->toArray();
|
||||
$reductions_stripe = $coupons_wc->map(static fn($coupon): array => ['coupon' => $coupon['name']])->values()->toArray();
|
||||
|
||||
/** @var Session $session_checkout_stripe */
|
||||
$session_checkout_stripe = \Stripe\Checkout\Session::create([
|
||||
|
|
@ -134,9 +133,9 @@ $session_checkout_stripe = \Stripe\Checkout\Session::create([
|
|||
'tax_behavior' => 'inclusive',
|
||||
'type' => 'fixed_amount',
|
||||
]]],
|
||||
], ['idempotency_key' => Uuid::uuid4()]);
|
||||
], ['idempotency_key' => Uuid::v4()]);
|
||||
// echo json_encode($session_checkout_stripe);
|
||||
header('HTTP/1.1 303 See Other');
|
||||
header('Location: ' . $session_checkout_stripe->url);
|
||||
|
||||
exit();
|
||||
exit;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Modèle de la Page Contact.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Timber\Timber;
|
||||
|
||||
// Contexte et modèles
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use function Crell\fp\pipe;
|
||||
use Roots\WPConfig\Config;
|
||||
use Stripe\Checkout\Session;
|
||||
use Stripe\StripeClient;
|
||||
use Timber\Timber;
|
||||
|
||||
use function Crell\fp\pipe;
|
||||
use Timber\Timber;
|
||||
|
||||
require_once __DIR__ . '/src/inc/TraitementInformations.php';
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ try {
|
|||
|
||||
// Récupère les données des Produits
|
||||
/** @var mixed $produits Les Produits de la Commande sous forme de tableau contenant uniquement les données affichées nécessaires pour le Page. */
|
||||
$produits = collect($commande->get_items())->map(function (WC_Order_Item $produit_commande) {
|
||||
$produits = collect($commande->get_items())->map(static function (WC_Order_Item $produit_commande) {
|
||||
/** @var string $id_produit L'ID du Produit. */
|
||||
$id_produit = $produit_commande['product_id'];
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ try {
|
|||
|
||||
// Récupère le nom et la valeur de l'attribut du Produit
|
||||
$attribut = $produit->is_type('variable')
|
||||
? collect($produit->get_attributes())->mapWithKeys(function ($_atr, $cle) use ($produit_commande) {
|
||||
? collect($produit->get_attributes())->mapWithKeys(static function ($_atr, $cle) use ($produit_commande) {
|
||||
$nom_attribut = wc_attribute_label($cle, $produit_commande->get_product());
|
||||
$valeur_attribut = $produit_commande->get_product()->get_attribute($cle);
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ try {
|
|||
return [
|
||||
'attribut' => $attribut,
|
||||
'id_produit' => $id_produit,
|
||||
'image' => pipe($produit->get_image_id(), fn($id) => genere_balise_img_multiformats(
|
||||
'image' => pipe($produit->get_image_id(), static fn($id): string => genere_balise_img_multiformats(
|
||||
id: $id,
|
||||
lazy: true,
|
||||
)),
|
||||
|
|
@ -114,7 +114,7 @@ try {
|
|||
filenames: $modeles,
|
||||
data: $contexte,
|
||||
);
|
||||
} catch (Error $e) {
|
||||
} catch (Error $error) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => esc_html($e->getMessage())]);
|
||||
echo json_encode(['error' => esc_html($error->getMessage())]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Le modèle de la Page « Terms & Conditions ».
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Timber\Timber;
|
||||
|
||||
// Contexte et modèles
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace HaikuAtelier;
|
||||
|
||||
use function Crell\fp\pipe;
|
||||
use function Env\env;
|
||||
use Roots\WPConfig\Config;
|
||||
|
||||
use Timber\Site;
|
||||
use Timber\URLHelper;
|
||||
|
||||
use function WC;
|
||||
use function add_action;
|
||||
use function add_theme_support;
|
||||
use function array_map;
|
||||
use function base64_encode;
|
||||
use function Crell\fp\pipe;
|
||||
use function Env\env;
|
||||
use function esc_url;
|
||||
use function get_categories;
|
||||
use function get_option;
|
||||
|
|
@ -23,24 +24,24 @@ use function get_privacy_policy_url;
|
|||
use function get_theme_mod;
|
||||
use function get_theme_mods;
|
||||
use function preg_match;
|
||||
use function WC;
|
||||
use function wp_create_nonce;
|
||||
use function wp_get_attachment_image_src;
|
||||
use function wpautop;
|
||||
|
||||
class StarterSite extends Site {
|
||||
final class StarterSite extends Site {
|
||||
public function __construct() {
|
||||
add_action('after_setup_theme', [$this, 'defini_fonctionnalites_theme']);
|
||||
add_action('after_setup_theme', $this->defini_fonctionnalites_theme(...));
|
||||
add_action('after_setup_theme', [$this, 'charge_traductions_theme']);
|
||||
|
||||
add_action('timber/context', [$this, 'ajoute_au_contexte_twig']);
|
||||
add_action('timber/twig/environment/options', [$this, 'maj_environnement_twig']);
|
||||
add_action('timber/context', $this->ajoute_au_contexte_twig(...));
|
||||
add_action('timber/twig/environment/options', $this->maj_environnement_twig(...));
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,mixed> $context
|
||||
* @param array<int,mixed> $context
|
||||
*
|
||||
* @return array<int,mixed>
|
||||
*/
|
||||
public function ajoute_au_contexte_twig(array $context): array {
|
||||
|
|
@ -65,13 +66,13 @@ class StarterSite extends Site {
|
|||
$context['descriptions_produits'] = $descriptions_produits;
|
||||
|
||||
// Logo personnalisée
|
||||
$context['logo'] = pipe(get_theme_mod('custom_logo'), fn($id) => wp_get_attachment_image_src(
|
||||
$context['logo'] = pipe(get_theme_mod('custom_logo'), static fn($id) => wp_get_attachment_image_src(
|
||||
attachment_id: $id,
|
||||
size: 'full',
|
||||
));
|
||||
|
||||
// Informations des Pages
|
||||
$recupere_informations_page = function ($slug) {
|
||||
$recupere_informations_page = static function ($slug) {
|
||||
$page = get_page_by_path($slug);
|
||||
|
||||
return (object) ['nom' => $page->post_title ?? '', 'lien' => get_page_link($page?->ID)];
|
||||
|
|
@ -118,18 +119,18 @@ class StarterSite extends Site {
|
|||
$context['base_categorie_produit'] = get_option('woocommerce_permalinks')['category_base'] ?? '';
|
||||
|
||||
// Récupère les Catégories de Produits
|
||||
$cree_entree_menu = fn($categorie) => [
|
||||
$cree_entree_menu = static fn($categorie): array => [
|
||||
'nom' => $categorie->name,
|
||||
'slug' => $categorie->slug,
|
||||
// Détermine si l'URL courante est celle de la Page d'Archive d'une Catégorie de Produits
|
||||
'courante' => preg_match(
|
||||
pattern: "/(\\b{$categorie->slug}\\b)/",
|
||||
subject: pipe(URLHelper::get_current_url(), URLHelper::get_rel_url(...)),
|
||||
subject: (string) pipe(URLHelper::get_current_url(), URLHelper::get_rel_url(...)),
|
||||
),
|
||||
];
|
||||
$entrees_menu_categories = pipe(
|
||||
get_categories(['hide_empty' => false, 'orderby' => 'menu_order', 'taxonomy' => 'product_cat']),
|
||||
fn($categories) => array_map(
|
||||
static fn($categories): array => array_map(
|
||||
callback: $cree_entree_menu,
|
||||
array: $categories,
|
||||
),
|
||||
|
|
@ -178,7 +179,7 @@ class StarterSite extends Site {
|
|||
/**
|
||||
* Met à jour l'environnement de Twig.
|
||||
*
|
||||
* @param array $options un tableau avec les options d'environnement
|
||||
* @param array $options un tableau avec les options d'environnement
|
||||
*/
|
||||
public function maj_environnement_twig(array $options): array {
|
||||
return $options;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Enregistre et rend disponible des types de contrôles personnalisés.
|
||||
*
|
||||
|
|
@ -16,16 +17,14 @@ function enregistre_controle_personnalise_tinymce(): void {
|
|||
*
|
||||
* @see https://github.com/maddisondesigns
|
||||
*/
|
||||
class Controle_Personnalise_TinyMCE extends WP_Customize_Control {
|
||||
/**
|
||||
* The type of control being rendered.
|
||||
*/
|
||||
final class ControlesPersonnalises extends WP_Customize_Control {
|
||||
/** The type of control being rendered. */
|
||||
public $type = 'editeur_tinymce';
|
||||
|
||||
/**
|
||||
* Enqueue our scripts and styles.
|
||||
*/
|
||||
#[\Override()]
|
||||
#[Override()]
|
||||
public function enqueue(): void {
|
||||
wp_enqueue_script(
|
||||
handle: 'controle-personnalise-tinymce',
|
||||
|
|
@ -37,10 +36,26 @@ function enregistre_controle_personnalise_tinymce(): void {
|
|||
wp_enqueue_editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control in the customizer.
|
||||
*/
|
||||
#[Override()]
|
||||
public function render_content(): void { ?>
|
||||
<div class="tinymce-control">
|
||||
<span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
|
||||
<?php if (!empty($this->description)) { ?>
|
||||
<span class="customize-control-description"><?php echo esc_html($this->description); ?></span>
|
||||
<?php } ?>
|
||||
<textarea id="<?php echo esc_attr($this->id); ?>" class="customize-control-tinymce-editor" <?php $this->link(); ?>><?php echo
|
||||
esc_html($this->value())
|
||||
; ?></textarea>
|
||||
</div>
|
||||
<?php }
|
||||
|
||||
/**
|
||||
* Pass our TinyMCE toolbar string to JavaScript.
|
||||
*/
|
||||
#[\Override()]
|
||||
#[Override()]
|
||||
public function to_json(): void {
|
||||
parent::to_json();
|
||||
|
||||
|
|
@ -56,22 +71,6 @@ function enregistre_controle_personnalise_tinymce(): void {
|
|||
? true
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control in the customizer.
|
||||
*/
|
||||
#[\Override()]
|
||||
public function render_content() { ?>
|
||||
<div class="tinymce-control">
|
||||
<span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
|
||||
<?php if (!empty($this->description)) { ?>
|
||||
<span class="customize-control-description"><?php echo esc_html($this->description); ?></span>
|
||||
<?php } ?>
|
||||
<textarea id="<?php echo esc_attr($this->id); ?>" class="customize-control-tinymce-editor" <?php $this->link(); ?>><?php echo
|
||||
esc_html($this->value())
|
||||
; ?></textarea>
|
||||
</div>
|
||||
<?php }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ function desactive_wpautop(): void {
|
|||
/**
|
||||
* Désactive divers transformations du contenu par TinyMCE.
|
||||
*
|
||||
* @param array<string, bool> $configuration un tableau associatif de la configuration TinyMCE
|
||||
* @param array<string, bool> $configuration un tableau associatif de la configuration TinyMCE
|
||||
*
|
||||
* @return array<string, bool> le même tableau avec des configurations en plus
|
||||
*/
|
||||
function desactive_transformation_contenu_tinymce(array $configuration): array {
|
||||
|
|
@ -32,7 +33,8 @@ function desactive_transformation_contenu_tinymce(array $configuration): array {
|
|||
/**
|
||||
* Autorise les imports en SVG dans la médiathèque.
|
||||
*
|
||||
* @param array<string, string> $file_types un tableau des types de fichiers autorisés dans la médiathèque
|
||||
* @param array<string, string> $file_types un tableau des types de fichiers autorisés dans la médiathèque
|
||||
*
|
||||
* @return array<string, string> le même tableau avec SVG en plus
|
||||
*/
|
||||
function autorise_import_svg_mediatheque(array $file_types): array {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ function retire_script_galerie(): void {
|
|||
remove_action('wp_head', 'wc_gallery_noscript');
|
||||
}
|
||||
|
||||
function retire_merdes_wc() {
|
||||
function retire_merdes_wc(): void {
|
||||
// remove WC generator tag
|
||||
remove_filter('get_the_generator_html', 'wc_generator_tag', 10, 2);
|
||||
remove_filter('get_the_generator_xhtml', 'wc_generator_tag', 10, 2);
|
||||
|
|
@ -128,11 +128,11 @@ function retire_merdes_wc() {
|
|||
* Modifie la réponse REST pour un Produit en y ajoutant des balises <img> pour chaque image d'intérêt.
|
||||
*
|
||||
* @param WP_REST_Response $response the response object
|
||||
* @param WC_Data $product object data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function genere_balises_img_dans_produit_dans_reponse_rest($response, $_product) {
|
||||
function genere_balises_img_dans_produit_dans_reponse_rest(
|
||||
WP_REST_Response $response,
|
||||
mixed $_product,
|
||||
): WP_REST_Response {
|
||||
// Vérifie que la Réponse a des données
|
||||
if (empty($response->data)) {
|
||||
return $response;
|
||||
|
|
@ -141,35 +141,35 @@ function genere_balises_img_dans_produit_dans_reponse_rest($response, $_product)
|
|||
// Génère la balise <img> pour l'image au repos
|
||||
$response->data['image_repos'] = pipe(
|
||||
$response->data['meta_data'],
|
||||
fn($metadata) => array_filter(
|
||||
static fn($metadata): array => array_filter(
|
||||
array: $metadata,
|
||||
callback: fn($entree) => '_photos_colonne_gauche|||0|value' === $entree->key,
|
||||
callback: static fn($entree): bool => '_photos_colonne_gauche|||0|value' === $entree->key,
|
||||
),
|
||||
fn($metadata) => array_map(
|
||||
static fn($metadata): array => array_map(
|
||||
array: $metadata,
|
||||
callback: fn($entree) => genere_balise_img_multiformats(
|
||||
callback: static fn($entree): string => genere_balise_img_multiformats(
|
||||
id: $entree?->value,
|
||||
lazy: true,
|
||||
),
|
||||
),
|
||||
fn($image) => array_values(array: $image)[0],
|
||||
static fn($image) => array_values(array: $image)[0],
|
||||
);
|
||||
|
||||
// Génère la balise <img> pour l'image au survol
|
||||
$response->data['image_survol'] = pipe(
|
||||
$response->data['meta_data'],
|
||||
fn($metadata) => array_filter(
|
||||
static fn($metadata): array => array_filter(
|
||||
array: $metadata,
|
||||
callback: fn($entree) => '_photos_colonne_droite|||0|value' === $entree->key,
|
||||
callback: static fn($entree): bool => '_photos_colonne_droite|||0|value' === $entree->key,
|
||||
),
|
||||
fn($metadata) => array_map(
|
||||
static fn($metadata): array => array_map(
|
||||
array: $metadata,
|
||||
callback: fn($entree) => genere_balise_img_multiformats(
|
||||
callback: static fn($entree): string => genere_balise_img_multiformats(
|
||||
id: $entree?->value,
|
||||
lazy: true,
|
||||
),
|
||||
),
|
||||
fn($image) => array_values(array: $image)[0],
|
||||
static fn($image) => array_values(array: $image)[0],
|
||||
);
|
||||
|
||||
return $response;
|
||||
|
|
@ -179,20 +179,18 @@ add_filter('woocommerce_rest_prepare_product_object', 'genere_balises_img_dans_p
|
|||
|
||||
/**
|
||||
* TODO.
|
||||
*
|
||||
* @param WP_REST_Response $reponse
|
||||
* @param WC_Data $_produit
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function genere_prix_maximal_produit_variable_dans_reponse_rest($reponse, $_produit) {
|
||||
function genere_prix_maximal_produit_variable_dans_reponse_rest(
|
||||
WP_REST_Response $reponse,
|
||||
WC_Data $_produit,
|
||||
): WP_REST_Response {
|
||||
// Vérifie que la Réponse a des données
|
||||
if (empty($reponse->data)) {
|
||||
return $reponse;
|
||||
}
|
||||
|
||||
// Si le Produit n'est pas Variable, assigner le prix du Produit comme prix maximal
|
||||
if ('variable' != $reponse->data['type']) {
|
||||
if ('variable' !== $reponse->data['type']) {
|
||||
$reponse->data['prix_maximal'] = $reponse->data['regular_price'];
|
||||
|
||||
return $reponse;
|
||||
|
|
@ -200,7 +198,7 @@ function genere_prix_maximal_produit_variable_dans_reponse_rest($reponse, $_prod
|
|||
|
||||
// Assigne le prix de la Variation la plus chère dans la Réponse
|
||||
$reponse->data['prix_maximal'] = collect($reponse->data['variations'])->map(wc_get_product(...))->map(
|
||||
fn($p) => $p->get_price(),
|
||||
static fn($p) => $p->get_price(),
|
||||
)->max();
|
||||
|
||||
return $reponse;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,8 @@ declare(strict_types=1);
|
|||
|
||||
/**
|
||||
* Génère la balise `<img>` d'un Média attaché à un Produit selon son ID.
|
||||
*
|
||||
* @param int $id_image
|
||||
* @return string
|
||||
*/
|
||||
function genere_balise_img($id_image) {
|
||||
function genere_balise_img(int $id_image): string {
|
||||
return wp_get_attachment_image(
|
||||
attachment_id: $id_image,
|
||||
size: 'full',
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ require_once __DIR__ . '/src/inc/TraitementInformations.php';
|
|||
$contexte = Timber::context();
|
||||
$modeles = ['boutique.twig'];
|
||||
|
||||
/** @var array<WC_Product> $informations_produits Les informations brutes des Produits. */
|
||||
/** @var list<WC_Product> $informations_produits Les informations brutes des Produits. */
|
||||
$informations_produits = wc_get_products([
|
||||
'category' => [get_queried_object()?->slug],
|
||||
'limit' => 12,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Illuminate\Support\Str;
|
|||
use Timber\Timber;
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialise Timber
|
||||
|
|
@ -23,10 +23,10 @@ Timber::$dirname = ['views'];
|
|||
$contexte = Timber::context();
|
||||
$modeles = ['email-commande-envoyee.twig'];
|
||||
|
||||
// @var Order $commande La Commande issue du contexte contenu dans la variable $order.
|
||||
/** @var Order $commande La Commande issue du contexte contenu dans la variable $order. */
|
||||
$commande = $order;
|
||||
|
||||
// @var Carbon $date
|
||||
/** @var Carbon $date */
|
||||
$date = new Carbon($commande->get_date_created());
|
||||
|
||||
$email = [
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Illuminate\Support\Str;
|
|||
use Timber\Timber;
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialise Timber
|
||||
|
|
@ -41,7 +41,7 @@ $email = [
|
|||
'numero_suivi' => $commande->get_meta('tracking_number'),
|
||||
],
|
||||
'paiement' => ['methode' => ''],
|
||||
'produits' => collect($commande->get_items())->map(function (WC_Order_Item_Product $article) {
|
||||
'produits' => collect($commande->get_items())->map(static function (WC_Order_Item_Product $article) {
|
||||
$produit = $article->get_product();
|
||||
|
||||
if (is_bool($produit) || $produit === null) {
|
||||
|
|
@ -52,7 +52,7 @@ $email = [
|
|||
// 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) => [
|
||||
->mapWithKeys(static fn($_atr, $cle): array => [
|
||||
'nom' => Str::lower(wc_attribute_label($cle, $produit)),
|
||||
'valeur' => $produit->get_attribute($cle),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use Illuminate\Support\Str;
|
|||
use Timber\Timber;
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialise Timber
|
||||
|
|
@ -37,7 +37,7 @@ $email = [
|
|||
],
|
||||
'commande' => ['date' => $date->toDateString(), 'id' => $commande->get_id()],
|
||||
'paiement' => ['methode' => ''],
|
||||
'produits' => collect($commande->get_items())->map(function (WC_Order_Item_Product $article) {
|
||||
'produits' => collect($commande->get_items())->map(static function (WC_Order_Item_Product $article) {
|
||||
$produit = $article->get_product();
|
||||
|
||||
if (is_bool($produit) || $produit === null) {
|
||||
|
|
@ -48,7 +48,7 @@ $email = [
|
|||
// Récupère l'Attribut d'un Produit variable ou renvoie un tableau vide
|
||||
'attribut' => $article->is_type('variable')
|
||||
? collect($produit->get_attributes())
|
||||
->mapWithKeys(fn($_atr, $cle) => [
|
||||
->mapWithKeys(static fn($_atr, $cle): array => [
|
||||
'nom' => Str::lower(wc_attribute_label($cle, $produit)),
|
||||
'valeur' => $produit->get_attribute($cle),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* WordPress View Bootstrapper.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Do not edit this file. Edit the config files found in the config/ dir instead.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue