fix: retourne un tableau pour les Options d'un Attribut

This commit is contained in:
gcch 2026-04-14 11:30:27 +02:00
commit 2d7ee36398
3 changed files with 9 additions and 2 deletions

View file

@ -20,6 +20,9 @@ final readonly class Attribute {
public array $options, public array $options,
) {} ) {}
/**
* Créé une nouvelle instance de `Attribut` depuis un `WC_Product_Attribute`.
*/
public static function new(WC_Product_Attribute $attribute): self { public static function new(WC_Product_Attribute $attribute): self {
$name = wc_attribute_label($attribute->get_name()); $name = wc_attribute_label($attribute->get_name());
$slug = $attribute->get_name(); $slug = $attribute->get_name();
@ -27,7 +30,8 @@ final readonly class Attribute {
$terms = $attribute->get_terms() ?? []; $terms = $attribute->get_terms() ?? [];
/** @var list<AttributeOption> */ /** @var list<AttributeOption> */
$options = Arr::map($terms, AttributeOption::new(...)) $options = Arr::map($terms, AttributeOption::new(...))
|> (static fn($options) => Arr::sort($options, static fn($attribute) => $attribute->id)); |> (static fn($options) => Arr::sort($options, static fn($attribute) => $attribute->id))
|> array_values(...);
return new self(name: $name, slug: $slug, options: $options); return new self(name: $name, slug: $slug, options: $options);
} }

View file

@ -13,6 +13,9 @@ final readonly class AttributeOption {
public string $slug, public string $slug,
) {} ) {}
/**
* Créé une nouvelle instance de `AttributeOption` depuis un `WP_Term`.
*/
public static function new(WP_Term $term): self { public static function new(WP_Term $term): self {
$id = $term->term_taxonomy_id; $id = $term->term_taxonomy_id;
$name = $term->name; $name = $term->name;

View file

@ -19,7 +19,7 @@ final readonly class ProductVariation {
) {} ) {}
/** /**
* Créé une nouvelle instance de `ProductVariation` à partir d'un `WC_Product`. * Créé une nouvelle instance de `ProductVariation` depuis un `WC_Product`.
*/ */
public static function new(WC_Product $product): self { public static function new(WC_Product $product): self {
$id = $product->get_id(); $id = $product->get_id();