> */ private static array $resolvedProductCounts = []; /** * Store the resolved product counts for the given attribute's options. * * @param array $counts option id => count */ public static function setResolvedProductCounts(int $attributeId, array $counts): void { static::$resolvedProductCounts[$attributeId] = $counts; } /** * Number of visible products associated with this option within the * current category context. * * Prefer the value computed and cached by FilterableAttributesProvider; * this keeps the count correct even when the option is fetched through * the GraphQL cursor-connection relation instead of the eager-loaded * collection. */ public function getProductCountAttribute(): int { $attributeId = (int) ($this->attribute_id ?? 0); if (isset(static::$resolvedProductCounts[$attributeId][(int) $this->id])) { return (int) static::$resolvedProductCounts[$attributeId][(int) $this->id]; } return 0; } #[ApiProperty(identifier: true, writable: false)] public function getId(): ?int { return $this->id; } #[ApiProperty(readableLink: true)] public function getTranslations() { return $this->translations; } #[ApiProperty(readableLink: true, description: 'Current locale translation')] public function getTranslation(?string $locale = null, ?bool $withFallback = null): ?EloquentModel { return $this->translation; } }