The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Interchange6::Schema::Result::Zone

DESCRIPTION

In the context of zones the term 'state' refers to state, province or other principal subdivision of a country as defined in ISO 3116-2. Countries to be added to a zone must already exist in Interchange6::Schema::Result::Country and states in Interchange6::Schema::Result::State.

Zones can contain any of the following:

  • No countries and no states

    An empty zone must be created before countries/states are added but otherwise is probably not useful.

  • Multiple countries

    For example to create a trading group like the European Union.

  • A single country

  • A single country with a single state

    For example Quebec in Canada which has GST + QST

  • A single country with multiple states

    For example a group containing all Canadian provinces that charge only GST.

The following combinations are NOT allowed:

  • Multiple countries with one or more states

  • One or more states with no country

Countries and states should be added to and removed from the zone using these methods which are described further below:

  • add_countries

  • remove_countries

  • add_states

  • remove_states

NOTE: avoid using other methods from DBIx::Class::Relationship::Base since you may inadvertently end up with an invalid zone.

ACCESSORS

zones_id

Primary Key.

zone

For example for storing the UPS/USPS zone code or a simple name for the zone.

Unique constraint.

created

Date and time when this record was created returned as DateTime object. Value is auto-set on insert.

last_modified

Date and time when this record was last modified returned as DateTime object. Value is auto-set on insert and update.

RELATIONS

zone_countries

Type: has_many

Related object: Interchange6::Schema::Result::ZoneCountry

countries

Type: many_to_many

Accessor to related country results ordered by name.

zone_states

Type: has_many

Related object: Interchange6::Schema::Result::ZoneState

states

Type: many_to_many

Accessor to related state results ordered by name.

shipment_destinations

has_many relationship with Interchange6::Schema::Result::ShipmentDestination

shipment_methods

many_to_many relationship to shipment_method. Currently it ignores the active field in shipment_destinations.

METHODS

new

Overloaded method. We allow a form of multi-create here so you can do something like:

    $schema->resultset('Zone')->create({
        zone      => 'some states of the USA',
        countries => [ 'US' ],
        states    => [ 'CA', 'PA' ],
    });

If there is only a single country or state the value can be a scalar instead of a hashref.

add_countries

Argument is one of:

an Interchange6::Schema::Result::Country object
a country ISO code
an arrayref of the above (can include a mixture of both)

Returns the zone object on success.

has_country

Argument can be Interchange6::Schema::Result::Country, country name or iso code. Returns 1 if zone includes that country else 0;

country_count

Takes no args. Returns the number of countries in the zone.

remove_countries

Argument is either a Interchange6::Schema::Result::Country object or an arrayref of the same.

Throws an exception on failure.

add_states

Argument is one of:

an Interchange6::Schema::Result::State object
a state ISO code
an arrayref of the above (can include a mixture of both)

Returns the zone object on success.

has_state

Argument can be Interchange6::Schema::Result::State, state name or iso code. Returns 1 if zone includes that state else 0;

state_count

Takes no args. Returns the number of states in the zone.

remove_states

Argument is either a Interchange6::Schema::Result::State object or an arrayref of the same.

Returns the Zone object or undef on failure. Errors are available via errors method inherited from Interchange6::Schema::Role::Errors.