Skip to content

Shipping Zone Model

DB Table Name{wp_db_prefix}_fct_shipping_zones
SchemaCheck Schema
Source Filefluent-cart/app/Models/ShippingZone.php
Name SpaceFluentCart\App\Models
ClassFluentCart\App\Models\ShippingZone

Attributes

AttributeData TypeComment
idIntegerPrimary Key
nameStringShipping zone name
regionStringRegion/country code
orderIntegerDisplay order
created_atDate TimeCreation timestamp
updated_atDate TimeLast update timestamp

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$shippingZone = FluentCart\App\Models\ShippingZone::find(1);

$shippingZone->id; // returns id
$shippingZone->name; // returns zone name
$shippingZone->region; // returns region code
$shippingZone->order; // returns display order

Relations

This model has the following relationships that you can use

methods

Access all shipping methods in this zone

  • return FluentCart\App\Models\ShippingMethod Model Collection

Example:

php
// Accessing Methods
$methods = $shippingZone->methods;

// For Filtering by methods relationship
$shippingZones = FluentCart\App\Models\ShippingZone::whereHas('methods', function($query) {
    $query->where('status', 'active');
})->get();

Methods

Along with Global Model methods, this model has few helper methods.

getFormattedRegionAttribute()

Get formatted region name (accessor)

  • Parameters
    • none
  • Returns string

Usage

php
$formattedRegion = $shippingZone->formatted_region; // Returns formatted region name

Usage Examples

Get Shipping Zones

php
$shippingZone = FluentCart\App\Models\ShippingZone::find(1);
echo "Zone Name: " . $shippingZone->name;
echo "Region: " . $shippingZone->region;
echo "Formatted Region: " . $shippingZone->formatted_region;

Create Shipping Zone

php
$shippingZone = FluentCart\App\Models\ShippingZone::create([
    'name' => 'United States',
    'region' => 'US',
    'order' => 1
]);

Get Shipping Zones with Methods

php
$shippingZones = FluentCart\App\Models\ShippingZone::with('methods')->get();

foreach ($shippingZones as $zone) {
    echo "Zone: " . $zone->name;
    foreach ($zone->methods as $method) {
        echo "  - Method: " . $method->title;
    }
}

Get Zones by Region

php
$usZones = FluentCart\App\Models\ShippingZone::where('region', 'US')->get();
$euZones = FluentCart\App\Models\ShippingZone::where('region', 'EU')->get();

Get Zones Ordered by Display Order

php
$orderedZones = FluentCart\App\Models\ShippingZone::orderBy('order', 'asc')->get();

Get Zones with Active Methods

php
$zonesWithActiveMethods = FluentCart\App\Models\ShippingZone::whereHas('methods', function($query) {
    $query->where('status', 'active');
})->get();

Update Shipping Zone

php
$shippingZone = FluentCart\App\Models\ShippingZone::find(1);
$shippingZone->update([
    'name' => 'United States & Canada',
    'order' => 2
]);

Get Zone by Name

php
$zone = FluentCart\App\Models\ShippingZone::where('name', 'United States')->first();

Get Zones with Method Count

php
$zonesWithCounts = FluentCart\App\Models\ShippingZone::withCount('methods')->get();

foreach ($zonesWithCounts as $zone) {
    echo "Zone: " . $zone->name . " (" . $zone->methods_count . " methods)";
}

Delete Shipping Zone

php
$shippingZone = FluentCart\App\Models\ShippingZone::find(1);
$shippingZone->delete(); // This will also delete associated methods

FluentCart developer documentation