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/blijegasten/blijegasten.be/app/Komma/Shop/ShippingCosts/ShippingCosts.php
<?php declare(strict_types=1);


namespace App\Komma\Shop\ShippingCosts;


use App\Komma\Globalization\RegionInfo;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasThumbnailInterface;
use App\Komma\Kms\Core\Attributes\Models\Traits\HasThumbnailTrait;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use Illuminate\Database\Eloquent\Model;

/**
 * Class ShipmentCosts
 *
 * @property string $code
 * @property int $cost
 * @property bool $is_default
 *
 * @package App\Komma\Shop\ShippingCosts
 */
class ShippingCosts extends Model implements DisplayNameInterface, HasThumbnailInterface
{
    use DisplayNameTrait;
    use HasThumbnailTrait;

    protected $fillable = [
        'code',
        'cost',
        'is_default',
    ];

    /** @var RegionInfo $neutralCulture */
    public $neutralCulture;

    public function setCodeAttribute(string $value)
    {
        $this->attributes['code'] = $value;
        $this->updateNeutralCulture();
    }

    public function getNameAttribute()
    {
        $this->updateNeutralCulture();
        if($this->neutralCulture) return $this->neutralCulture->getDisplayName();
        return $this->country;
    }

    private function updateNeutralCulture()
    {
        $this->neutralCulture = RegionInfo::getNeutralCultures()->filter(function(RegionInfo $regionInfo) {
            return $regionInfo->getThreeLetterISORegionName() == $this->getAttribute('code');
        })->first();
    }
}