Refactor the pricing calculation service and shipping rate import logic to improve consistency and reliability. This includes updating direction naming conventions, enhancing model casting, and adding comprehensive test suites. - Update `ShippingRatesImport` to use 'outbound' and 'inbound' instead of 'export' and 'import' - Refactor `PriceCalculatorService` to use a more modular calculation structure - Update `ShippingRate` model to use explicit property casting for zones - Add `HasFactory` trait to `Country` and `ShippingRate` models - Add new database factories for `Country` and `ShippingRate` - Implement new feature tests for API endpoints and service logic - Add new service tests for `PriceCalculatorService`
44 lines
941 B
PHP
44 lines
941 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; // این خط را اضافه کنید
|
|
|
|
|
|
class Country extends Model
|
|
{
|
|
|
|
|
|
use HasFactory; // این خط را اضافه کنید
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'iso_code',
|
|
'export_zone_parcel',
|
|
'export_zone_doc',
|
|
'import_zone_parcel',
|
|
'import_zone_doc',
|
|
'is_active',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function fromShipments(): HasMany
|
|
{
|
|
return $this->hasMany(Shipment::class, 'from_country_id');
|
|
}
|
|
|
|
public function toShipments(): HasMany
|
|
{
|
|
return $this->hasMany(Shipment::class, 'to_country_id');
|
|
}
|
|
}
|