'Published', self::STATUS_DRAFT => 'Draft', self::STATUS_PENDING => 'Pending review', self::STATUS_PRIVATE => 'Private', ]; protected $fillable = [ 'woo_store_id', 'external_id', 'name', 'slug', 'sku', 'status', 'type', 'regular_price_minor', 'sale_price_minor', 'stock_quantity', 'manage_stock', 'category_external_ids', 'images', 'short_description', 'description', 'wc_updated_at', 'metadata', ]; protected $casts = [ 'manage_stock' => 'boolean', 'category_external_ids' => 'array', 'images' => 'array', 'wc_updated_at' => 'datetime', 'metadata' => 'array', ]; public function store(): BelongsTo { return $this->belongsTo(WooStore::class, 'woo_store_id'); } public function priceMinor(): ?int { return $this->sale_price_minor ?? $this->regular_price_minor; } public function priceFormatted(): string { $minor = $this->priceMinor(); if ($minor === null) { return '—'; } $currency = strtoupper((string) ($this->store?->metadata['currency'] ?? 'GHS')); return $currency.' '.number_format($minor / 100, 2); } public function statusLabel(): string { return self::STATUSES[$this->status] ?? ucfirst((string) $this->status); } /** @return array{id?: int, src?: string, alt?: string, position?: int}|null */ public function featuredImage(): ?array { $images = (array) $this->images; return $images[0] ?? null; } /** @return list */ public function galleryImages(): array { $images = array_values((array) $this->images); return array_slice($images, 1); } public function thumbnailUrl(): ?string { $featured = $this->featuredImage(); return is_array($featured) && ! empty($featured['src']) ? (string) $featured['src'] : null; } /** @return list */ public function categoryNames(): array { $ids = array_filter((array) $this->category_external_ids); if ($ids === []) { return []; } return WooCategory::query() ->where('woo_store_id', $this->woo_store_id) ->whereIn('external_id', $ids) ->orderBy('name') ->pluck('name') ->all(); } }