Class: Spree::DeliveryZoneMember

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/delivery_zone_member.rb

Constant Summary collapse

MEMBER_TYPES =
%w[country state postal_code].freeze

Instance Method Summary collapse

Instance Method Details

#match?(address) ⇒ Boolean

A state member compares the country too: a subdivision code is only unique within its country, so "CA" alone would match California and several other places.

Parameters:

Returns:

  • (Boolean) —

    whether the address falls inside this member



40
41
42
43
44
45
46
47
# File 'app/models/spree/delivery_zone_member.rb', line 40

def match?(address)
  case member_type
  when 'country' then same_country?(address)
  when 'state' then same_country?(address) && address.state_code.present? && address.state_code == state_code
  when 'postal_code' then same_country?(address) && postal_match?(address.normalized_postal_code)
  else false
  end
end

#postal_range? ⇒ Boolean

Returns whether this member defines a from/to range (vs a prefix).

Returns:

  • (Boolean) —

    whether this member defines a from/to range (vs a prefix)



50
51
52
# File 'app/models/spree/delivery_zone_member.rb', line 50

def postal_range?
  postal_code_from.present? || postal_code_to.present?
end