Method: Order2cb::Order#fitting_centre

Defined in:
lib/order2cb/order.rb

#fitting_centreObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/order2cb/order.rb', line 91

def fitting_centre
  channel_fields = $db_client.query("SELECT exp_channel_fields.* FROM exp_channel_fields JOIN exp_channels on exp_channels.channel_id = exp_channel_fields.group_id WHERE exp_channels.channel_name = 'branches'")
  data_field_id = $db_client.query("SELECT exp_channel_fields.field_id FROM exp_channel_fields JOIN exp_channels on exp_channels.channel_id = exp_channel_fields.group_id WHERE exp_channels.channel_name = 'branches' and exp_channel_fields.field_name = 'dataflex_id'").first["field_id"]
  fitting_centre_fields = $db_client.query("SELECT * FROM exp_channel_data WHERE field_id_#{data_field_id} = '#{@data['fitting_centre_id']}'")

  fitting_centre_hash = {}
  channel_fields.map{|f| fitting_centre_hash[f['field_name']] = fitting_centre_fields.first["field_id_#{f['field_id']}"]}

  is_mobile_fitting = fitting_centre_hash['is_mobile_fitting'].upcase == "YES"
  details = {
              'phone_number' => fitting_centre_hash['phone_number'],
              'branch_number' => fitting_centre_hash['dataflex_id'],
              'mobile_fitting' => is_mobile_fitting
  }
  if is_mobile_fitting

    address_components = [fitting_centre_hash['street'], fitting_centre_hash['street2'], fitting_centre_hash['town'], fitting_centre_hash['postcode']]
    address = address_components.reject{|comp| comp.strip.empty?}.join(", ")

    details['mobile_fitter'] = fitting_centre_hash['name']
    details['customer_contact_name'] = 'Unknown'
    details['fitting_address'] = address
  else
    details['name'] = fitting_centre_hash['name']
  end

  details
end