Class: Spree::ExactorSetting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/exactor_setting.rb

Defined Under Namespace

Classes: COMMIT_OPTIONS, SKU_SOURCES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_settingsObject



134
135
136
137
# File 'app/models/spree/exactor_setting.rb', line 134

def self.get_settings
  settings = Spree::ExactorSetting.all
  return settings.empty?() ? nil:settings.first()
end

Instance Method Details

#all_commit_optionsObject



106
107
108
109
110
111
112
# File 'app/models/spree/exactor_setting.rb', line 106

def all_commit_options
  return [
      ExactorOption.new(COMMIT_OPTIONS::TRANSACTION_STATE, "Commit based on transaction state"),
      ExactorOption.new(COMMIT_OPTIONS::PAYMENT_STATE, "Commit based on payment state"),
      ExactorOption.new(COMMIT_OPTIONS::SHIPMENT_STATE, "Commit based on shipping state")
  ]
end

#all_sku_sourcesObject



114
115
116
117
118
119
# File 'app/models/spree/exactor_setting.rb', line 114

def all_sku_sources
  return  [
    ExactorOption.new(SKU_SOURCES::SKU_FIELD, "Use SKU field for SKU"),
    ExactorOption.new(SKU_SOURCES::TAX_CATEGORY, "Use product tax category for SKU")
  ]
end

#create_additional_entitiesObject

called after create



93
94
95
# File 'app/models/spree/exactor_setting.rb', line 93

def create_additional_entities
  TaxRate.find_or_create_exactor_tax_rate()
end

#get_ship_fromObject



121
122
123
124
125
126
127
128
129
130
131
# File 'app/models/spree/exactor_setting.rb', line 121

def get_ship_from
  companyAddress = AddressType.new
  companyAddress.FullName= ship_from_name
  companyAddress.Street1= ship_from_street1
  companyAddress.Street2= ship_from_street2
  companyAddress.City= ship_from_city
  companyAddress.StateOrProvince= state_id.nil?() ? state_name : state
  companyAddress.PostalCode= ship_from_zip
  companyAddress.Country= country
  return companyAddress
end

#is_valid_state?Boolean

Returns:

  • (Boolean)


86
87
88
89
90
# File 'app/models/spree/exactor_setting.rb', line 86

def is_valid_state?
  if state_id.nil?  and state_name.to_s.empty?
    errors[:state] << "is required field"
  end
end

#set_statesObject

called before validation



98
99
100
101
102
103
104
# File 'app/models/spree/exactor_setting.rb', line 98

def set_states
  unless country.states.include?(state) or state.nil?
    @attributes["state_id"] = nil
  else
    @attributes["state_name"] = nil
  end
end