bianjunhui 1 giorno fa
parent
commit
ff82f0e31f
1 ha cambiato i file con 11 aggiunte e 10 eliminazioni
  1. 11 10
      packages/Webkul/BagistoApi/src/Models/AttributeOption.php

+ 11 - 10
packages/Webkul/BagistoApi/src/Models/AttributeOption.php

@@ -44,6 +44,17 @@ use Illuminate\Database\Eloquent\Model as EloquentModel;
 )]
 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.
+     */
+    public function getProductCountAttribute(): int
+    {
+        return (int) ($this->attributes['product_count'] ?? 0);
+    }
 
     #[ApiProperty(identifier: true, writable: false)]
     public function getId(): ?int
@@ -63,14 +74,4 @@ class AttributeOption extends \Webkul\Attribute\Models\AttributeOption
         return $this->translation;
     }
 
-    /**
-     * Number of visible products associated with this option within the
-     * current category context. Populated by FilterableAttributesProvider.
-     */
-    #[ApiProperty(writable: false, readable: true)]
-    public function getProductCount(): int
-    {
-        return (int) ($this->product_count ?? 0);
-    }
-
 }