Class: ShippingOption
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ShippingOption
- Defined in:
- app/models/shipping_option.rb
Overview
== Schema Information
Table name: shipping_options
Database name: primary
id :integer not null, primary key
carrier :string(255)
country :string(255)
days_commitment :float default(3.5), not null
delivery_commitment :text
description :string(255)
information :text
is_freight :boolean default(FALSE), not null
is_inactive :boolean default(FALSE), not null
is_third_party_only :boolean default(FALSE), not null
jde_shipping_stop_code :string(255)
name :string(255)
service_code :string(255)
service_level :string(255)
supported_for_st :boolean default(FALSE), not null
tax_class :string(3) not null
created_at :datetime
updated_at :datetime
item_id :integer
Indexes
index_shipping_options_on_service_level (service_level)
Constant Summary collapse
- SERVICE_LEVELS =
{ standard: 3, expedited: 2, express: 1 }
- OPTIONS_FOR_RMAS =
[1, 139, 207, 4, 30, 63, 146]
Has many collapse
Belongs to collapse
Class Method Summary collapse
-
.:CAN ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :CAN.
-
.:NLD ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :NLD.
-
.:USA ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :USA.
-
.active ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are active.
-
.by_days_commitment ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are by days commitment.
- .carrier_options_for_select(country_iso3 = nil) ⇒ Object
-
.for_country_iso ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for country iso.
-
.for_country_iso3 ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for country iso3.
-
.for_rmas ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for rmas.
-
.freight ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are freight.
- .get_appropriate(country_code, is_residential, purolator_ltl = nil) ⇒ Object
-
.non_freight ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are non freight.
-
.non_override ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are non override.
- .options_for_preferred_shipping_method_select(country = 'USA') ⇒ Object
- .select_options(country_iso3 = nil, supported = nil, include_override = false) ⇒ Object
-
.supported ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are supported.
- .supported_carrier_options_for_rmas(country = 'US') ⇒ Object
- .supported_carrier_options_for_select(country = nil) ⇒ Object
Instance Method Summary collapse
- #country_iso3 ⇒ Object
- #is_economy? ⇒ Boolean
- #is_fedex_ca? ⇒ Boolean
- #is_freightquote? ⇒ Boolean
- #is_override? ⇒ Boolean
- #is_postal? ⇒ Boolean
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.:CAN ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :CAN. Active Record Scope
43 |
# File 'app/models/shipping_option.rb', line 43 scope :CAN, -> { for_country_iso('CA') } |
.:NLD ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :NLD. Active Record Scope
44 |
# File 'app/models/shipping_option.rb', line 44 scope :NLD, -> { for_country_iso('NL') } |
.:USA ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are :USA. Active Record Scope
42 |
# File 'app/models/shipping_option.rb', line 42 scope :USA, -> { for_country_iso('US') } |
.active ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are active. Active Record Scope
38 |
# File 'app/models/shipping_option.rb', line 38 scope :active, -> { where('shipping_options.is_inactive IS NOT TRUE') } |
.by_days_commitment ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are by days commitment. Active Record Scope
41 |
# File 'app/models/shipping_option.rb', line 41 scope :by_days_commitment, -> { order('shipping_options.days_commitment DESC') } |
.carrier_options_for_select(country_iso3 = nil) ⇒ Object
84 85 86 87 88 |
# File 'app/models/shipping_option.rb', line 84 def self.(country_iso3 = nil) opts = ShippingOption.active.where.not(carrier: nil).order(:carrier) opts = opts.where(country: country_iso3[0..1]) if country_iso3.present? opts.pluck(:carrier).uniq end |
.for_country_iso ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for country iso. Active Record Scope
45 |
# File 'app/models/shipping_option.rb', line 45 scope :for_country_iso, ->(country_iso) { where(country: country_iso).by_days_commitment } |
.for_country_iso3 ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for country iso3. Active Record Scope
46 |
# File 'app/models/shipping_option.rb', line 46 scope :for_country_iso3, ->(country_iso3) { for_country_iso(Country.iso3_to_iso_map[country_iso3]) } |
.for_rmas ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are for rmas. Active Record Scope
47 |
# File 'app/models/shipping_option.rb', line 47 scope :for_rmas, -> { where('shipping_options.id IN (?)', OPTIONS_FOR_RMAS) } |
.freight ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are freight. Active Record Scope
48 |
# File 'app/models/shipping_option.rb', line 48 scope :freight, -> { where("shipping_options.carrier = 'UPSFreight'") } |
.get_appropriate(country_code, is_residential, purolator_ltl = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/shipping_option.rb', line 51 def self.get_appropriate(country_code, is_residential, purolator_ltl = nil) opts = [] if country_code.in?(Country::EU_COUNTRIES_ISO) opts = ShippingOption.active.NLD.to_a # This should be more generic and add any european country? elsif country_code == 'CA' # puts "ShippingOption.get_appropriate: country_code: CA, purolator_ltl: #{purolator_ltl}" opts = ShippingOption.active.CAN.to_a unless purolator_ltl # puts "ShippingOption.get_appropriate: purolator_ltl IS NOT TRUE" purolator_freight_sos = ShippingOption.where(carrier: 'PurolatorFreight') purolator_freight_sos.each do |purolator_freight_so| opts.delete(purolator_freight_so) end end else opts = ShippingOption.active.USA.to_a end opts end |
.non_freight ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are non freight. Active Record Scope
49 |
# File 'app/models/shipping_option.rb', line 49 scope :non_freight, -> { where("shipping_options.carrier <> 'UPSFreight'") } |
.non_override ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are non override. Active Record Scope
40 |
# File 'app/models/shipping_option.rb', line 40 scope :non_override, -> { where.not(shipping_options: { carrier: nil }) } |
.options_for_preferred_shipping_method_select(country = 'USA') ⇒ Object
79 80 81 82 |
# File 'app/models/shipping_option.rb', line 79 def self.(country = 'USA') # must only use supported shipping options here or free shipping becomes almost default ShippingOption.active.supported.for_country_iso3(country).where.not(carrier: nil).order(days_commitment: :desc).map { |so| ["#{so.description} #{so.country}, code: #{so.service_code}", so.name] } end |
.select_options(country_iso3 = nil, supported = nil, include_override = false) ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/models/shipping_option.rb', line 71 def self.(country_iso3 = nil, supported = nil, include_override = false) opts = ShippingOption.active opts = opts.non_override unless include_override == true opts = opts.supported if supported == true opts = opts.send(country_iso3.to_sym) if country_iso3.present? opts.order('carrier asc,days_commitment desc,description asc,country desc').map { |so| ["#{so.carrier}: #{so.description} (#{so.country}), code: #{so.service_code}", so.id] } end |
.supported ⇒ ActiveRecord::Relation<ShippingOption>
A relation of ShippingOptions that are supported. Active Record Scope
39 |
# File 'app/models/shipping_option.rb', line 39 scope :supported, -> { where('shipping_options.is_third_party_only IS NOT TRUE and shipping_options.carrier IS NOT NULL') } |
.supported_carrier_options_for_rmas(country = 'US') ⇒ Object
102 103 104 105 106 |
# File 'app/models/shipping_option.rb', line 102 def self.(country = 'US') supported_carriers = opts = ShippingOption.active.for_rmas.where(carrier: supported_carriers).where(country: country) opts.order('carrier asc,days_commitment desc,description asc,country desc').map { |so| ["#{so.carrier}: #{so.description} (#{so.country}), code: #{so.service_code}", so.id] } end |
.supported_carrier_options_for_select(country = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/shipping_option.rb', line 90 def self.(country = nil) if country SUPPORTED_SHIPPING_CARRIERS[country.to_sym] || [] else = [] SUPPORTED_SHIPPING_CARRIERS.each do |country, | .concat() end .uniq end end |
Instance Method Details
#country_iso3 ⇒ Object
130 131 132 |
# File 'app/models/shipping_option.rb', line 130 def country_iso3 Country.find_by(iso: country).iso3 end |
#is_economy? ⇒ Boolean
108 109 110 111 |
# File 'app/models/shipping_option.rb', line 108 def is_economy? %w[ground standard fedex_ground fedex_ground_residential usps_media_mail usps_standard_post usps_parcel_select usps_priority_mail canada_post_regular_parcel canpar_ground purolator_ground purolator_ground_evening].include? name end |
#is_fedex_ca? ⇒ Boolean
117 118 119 120 |
# File 'app/models/shipping_option.rb', line 117 def is_fedex_ca? nm = name.to_s.downcase nm.index('fedex_').present? && nm.index('_ca').present? end |
#is_freightquote? ⇒ Boolean
122 123 124 |
# File 'app/models/shipping_option.rb', line 122 def is_freightquote? carrier.to_s.downcase.index('freightquote').present? end |
#is_override? ⇒ Boolean
126 127 128 |
# File 'app/models/shipping_option.rb', line 126 def is_override? name.to_s.downcase == 'override' end |
#is_postal? ⇒ Boolean
113 114 115 |
# File 'app/models/shipping_option.rb', line 113 def is_postal? POSTAL_CARRIERS.include? carrier end |
#rooms ⇒ ActiveRecord::Relation<Room>
32 |
# File 'app/models/shipping_option.rb', line 32 has_many :rooms, through: :shipping_costs |
#shipping_costs ⇒ ActiveRecord::Relation<ShippingCost>
31 |
# File 'app/models/shipping_option.rb', line 31 has_many :shipping_costs |