diff --git a/packages/core/src/Models/Carrier.php b/packages/core/src/Models/Carrier.php index 1b3d8dd0e..2db15259e 100755 --- a/packages/core/src/Models/Carrier.php +++ b/packages/core/src/Models/Carrier.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Shopper\Core\Traits\HasSlug; +use Shopper\Core\Traits\HasZones; /** * @property-read int $id @@ -25,6 +26,7 @@ class Carrier extends Model { use HasFactory; use HasSlug; + use HasZones; protected $fillable = [ 'name', diff --git a/packages/core/src/Models/Country.php b/packages/core/src/Models/Country.php index 1b125771b..6c689995b 100755 --- a/packages/core/src/Models/Country.php +++ b/packages/core/src/Models/Country.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphOne; +use Shopper\Core\Traits\HasZones; /** * @property-read int $id @@ -27,6 +27,7 @@ class Country extends Model { use HasFactory; + use HasZones; public $timestamps = false; @@ -64,9 +65,4 @@ public function svgFlag(): Attribute fn () => url(shopper()->prefix() . '/images/flags/' . mb_strtolower($this->cca2) . '.svg') ); } - - public function zone(): MorphOne - { - return $this->morphOne(ZoneRelation::class, 'zonable'); - } } diff --git a/packages/core/src/Models/PaymentMethod.php b/packages/core/src/Models/PaymentMethod.php index 01050c7e6..99d85366b 100755 --- a/packages/core/src/Models/PaymentMethod.php +++ b/packages/core/src/Models/PaymentMethod.php @@ -5,9 +5,11 @@ namespace Shopper\Core\Models; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Shopper\Core\Traits\HasSlug; +use Shopper\Core\Traits\HasZones; /** * @property-read int $id @@ -21,6 +23,7 @@ class PaymentMethod extends Model { use HasFactory; use HasSlug; + use HasZones; protected $guarded = []; @@ -37,13 +40,11 @@ public function getTable(): string return shopper_table('payment_methods'); } - public function getLogoUrlAttribute(): ?string + public function LogoUrl(): ?Attribute { - if ($this->logo) { - return shopper_asset($this->logo); - } - - return null; + return Attribute::make( + get: fn () => $this->logo ? shopper_asset($this->logo) : null, + ); } public function scopeEnabled(Builder $query): Builder diff --git a/packages/core/src/Models/Zone.php b/packages/core/src/Models/Zone.php index 66d007aeb..a769c29de 100644 --- a/packages/core/src/Models/Zone.php +++ b/packages/core/src/Models/Zone.php @@ -27,6 +27,7 @@ * @property \Shopper\Core\Models\Currency $currency * @property \Illuminate\Database\Eloquent\Collection $carriers * @property \Illuminate\Database\Eloquent\Collection $shippingOptions + * @property \Illuminate\Database\Eloquent\Collection $paymentMethods */ class Zone extends Model { diff --git a/packages/core/src/Traits/HasZones.php b/packages/core/src/Traits/HasZones.php new file mode 100644 index 000000000..6770ea599 --- /dev/null +++ b/packages/core/src/Traits/HasZones.php @@ -0,0 +1,16 @@ +morphToMany(Zone::class, 'zonable', shopper_table('zone_has_relations')); + } +}