HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Products/AbstractProductable.php
<?php declare(strict_types=1);


namespace App\Products;


use App\Categories\Models\Category;
use App\Vat\FinancialProperties;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Sites\HasSitesInterface;
use Komma\KMS\Sites\Models\Site;

abstract class AbstractProductable extends AbstractTranslatableModel implements ProductableInterface, HasSitesInterface, DisplayNameInterface
{
    use FinancialProperties;
    use DisplayNameTrait;

    /**
     * Returns the enum value for the productable
     *
     * @return int
     */
    abstract public function enum(): int;

    /**
     * Get the sites for this model
     *
     * @return BelongsToMany
     */
    public function sites(): BelongsToMany
    {
        return $this->belongsToMany(Site::class);
    }

    /**
     * We belong to many categories
     *
     * @return MorphToMany
     */
    public function categories(): MorphToMany
    {
        return $this->morphToMany(Category::class, 'categorizable');
    }


    /**
     * @return string|null
     */
    public function getDisplayName(): ?string
    {
        if($this->relationLoaded('translation')) return $this->translation->name;
        else return '';
    }
}