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();
}
}