bianjunhui 16 horas atrás
pai
commit
25746a1eb9

+ 9 - 4
packages/Webkul/BagistoApi/src/Models/AttributeOption.php

@@ -47,13 +47,18 @@ class AttributeOption extends \Webkul\Attribute\Models\AttributeOption
     /**
      * Number of visible products associated with this option within the
      * current category context. Populated by FilterableAttributesProvider.
-     *
-     * Uses the Laravel accessor naming convention (get...Attribute) so that
-     * API Platform discovers it as a virtual attribute.
+     */
+    #[ApiProperty(writable: false, readable: true)]
+    public int $product_count = 0;
+
+    /**
+     * Laravel accessor for the product_count virtual attribute. The accessor
+     * naming convention makes API Platform discover it as a virtual attribute,
+     * while the public property above lets PropertyInfo infer the int type.
      */
     public function getProductCountAttribute(): int
     {
-        return (int) ($this->attributes['product_count'] ?? 0);
+        return (int) ($this->product_count ?? 0);
     }
 
     #[ApiProperty(identifier: true, writable: false)]