Class: Edi::MiraklSeller::Castorama::ProductDataPresenter

Inherits:
BaseMiraklPresenter show all
Defined in:
app/services/edi/mirakl_seller/castorama/product_data_presenter.rb

Overview

Service object: product data presenter.

Instance Attribute Summary

Attributes inherited from BaseMiraklPresenter

#image_locales

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BaseMiraklPresenter

#images, #initialize, #to_h, #video

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from Edi::MiraklSeller::BaseMiraklPresenter

Instance Method Details

#bar_shape_twObject



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 225

def bar_shape_tw
  # Circular 6
  # Curved 1
  # Flat 2
  # Half moon 8
  # Oval 5
  # Rectangular 4
  # Square 3
  # Triangular 7
  bar_shape = item.spec_value(:bar_shape)
  case bar_shape
  when 'Round'
    6
  when 'Square'
    3
  else
    @error_list << "TW Tube shape #{bar_shape} not mapped for item #{item.sku}."
  end
end

#colorObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 330

def color
  # Beige 1
  # Black 20
  # Blue 2
  # Bronze 3
  # Brown 4
  # Copper 6
  # Cream 191
  # Gold 8
  # Green 9
  # Grey 10
  # Multicolour 11
  # Natural 190
  # Orange 13
  # Pink 14
  # Purple 15
  # Red 16
  # Silver 17
  # Transparent 32
  # White 18
  # Yellow 19
  fetched_color = spec_value(:finish) || spec_value(:color)
  case fetched_color
  when /Polished|Brushed|Stainless|Steel/i
    17
  when /Bronze/i
    3
  when /Gold/i
    8
  when /Black/i
    20
  when /White/i
    18
  when /Mirror|Glass/i
    11
  else
    @error_list << "Color #{fetched_color} not mapped for item #{item.sku}."
  end
end

#connectivity_infrared_heating_panelObject



398
399
400
401
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 398

def connectivity_infrared_heating_panel
  # Not connected object 16
  16
end

#connectivity_twObject



245
246
247
248
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 245

def connectivity_tw
  # Not connected object 16
  16
end

#core_packObject



190
191
192
193
194
195
196
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 190

def core_pack
  # Each 3
  # Pack 6
  # Pair 65
  # Set 4
  3
end

#core_product_typeObject



213
214
215
216
217
218
219
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 213

def core_product_type
  if item.is_infrared_heating_panel?
    12_912
  elsif item.is_towel_warmer?
    13_120
  end
end

#depthObject



421
422
423
424
425
426
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 421

def depth
  depth = item.spec_value(:depth, output_unit: 'mm')
  return nil if depth.blank?

  depth.to_i
end

#display_infrared_heating_panelObject



296
297
298
299
300
301
302
303
304
305
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 296

def display_infrared_heating_panel
  # Backlit LCD 65
  # Digital 5
  # Digital display 125
  # LCD 15
  # LED 113
  # Touchscreen 72
  # Without display 86
  86
end

#display_twObject



250
251
252
253
254
255
256
257
258
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 250

def display_tw
  # Digital 5
  # LCD colour display 12
  # LCD touchscreen colour display 143
  # LED colour 10
  # LED touchscreen colour display 144
  # No display 75
  75
end

#facet_infrared_heating_panelObject

INFRARED HEATING PANEL RELATED METHODS



276
277
278
279
280
281
282
283
284
285
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 276

def facet_infrared_heating_panel
  # Boîtier connectable pour radiateur 10976
  # Panneau rayonnant 4822
  # Radiateur inertie sèche 13399
  # Radiateur électrique double cœur de chauffe 13396
  # Radiateur électrique inertie fluide 14262
  # Radiateur électrique inertie sèche 14263
  # Radiateur électrique rayonnant 13397
  13_397
end

#facet_twObject



205
206
207
208
209
210
211
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 205

def facet_tw
  # Sèche-serviettes eau chaude non soufflant 13608
  # Sèche-serviettes eau chaude soufflant 13609
  # Sèche-serviettes non soufflant 6121
  # Sèche-serviettes mixte 16594
  6121
end

#generic_dataObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 6

def generic_data
  {
    required: {
      category: mirakl_product_category,
      shop_sku: ean13,
      name: name(locale: :fr),
      image_main_1: images[0],
      ean: ean13,
      'Acquisition brand': 10_375,
      Guarantee: guarantee,
      'Body Copy': detailed_description_html(locale: :fr)
    },
    optional: {
      image_secondary_1: images[1],
      image_secondary_2: images[2],
      image_secondary_3: images[3],
      image_secondary_4: images[4],
      image_secondary_5: images[5],
      image_secondary_6: images[6],
      image_secondary_7: images[7],
      image_secondary_8: images[8],
      image_back_of_pack: nil,
      video: video&.cms_url,
      pdf_product_guide: nil,
      pdf_product_instruction_manual: nil,
      pdf_safety_manual: nil,
      pdf_sds_document: nil,
      pdf_dop_document: nil,
      pdf_ids_document: nil,
      pdf_repairabilty_index_document: nil,
      Mirakl_ProductGroup_ID: nil,
      MIRAKL_Legal_notices: nil,
      'Unique Selling Point 01': feature_1(locale: :fr),
      'Unique Selling Point 02': feature_2(locale: :fr),
      'Unique Selling Point 03': feature_3(locale: :fr),
      'Unique Selling Point 04': feature_4(locale: :fr),
      'Unique Selling Point 05': feature_5(locale: :fr),
      'Core_Pack quantity': 1,
      'Core_Pack type': core_pack,
      'Selling Copy': short_description(locale: :fr)
    }
  }
end

#guaranteeObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 158

def guarantee
  return unless (w = item.spec_output(:warranty))

  y = w.match(/\d+/)[0].to_i
  {
    1 => 76,
    2 => 78,
    3 => 79,
    4 => 80,
    5 => 81,
    6 => 82,
    7 => 83,
    8 => 84,
    9 => 85,
    10 => 86,
    11 => 110,
    12 => 97,
    13 => 123,
    14 => 124,
    15 => 87,
    16 => 125,
    17 => 126,
    18 => 127,
    19 => 128,
    20 => 88,
    21 => 129,
    22 => 130,
    23 => 131,
    25 => 89
  }[y]
end

#heat_outputObject

This is expressed in kilowatt hours



408
409
410
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 408

def heat_output
  item.spec_value(:thermal_power)
end

#heater_infrared_heating_panelObject



287
288
289
290
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 287

def heater_infrared_heating_panel
  # Infrared 21
  15
end

#heater_product_type_twObject

TOWEL WARMER RELATED METHODS



200
201
202
203
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 200

def heater_product_type_tw
  # Heating Wire
  36
end

#heating_areaObject



438
439
440
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 438

def heating_area
  item.spec_value(:heating_area)
end

#heightObject

END INFRARED HEATING PANEL RELATED METHODS



316
317
318
319
320
321
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 316

def height
  height = item.spec_value(:height, output_unit: 'mm')
  return nil if height.blank?

  height.to_i
end

#infrared_heating_panel_dataObject



90
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
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 90

def infrared_heating_panel_data
  {
    required: {
      Facet_product_type: facet_infrared_heating_panel,
      Heater_product_type: heater_infrared_heating_panel,
      Type_Range: range_infrared_heating_panel,
      'Tech_Heating surface area': heating_area,
      Product_height: height,
      Product_width: width,
      'Vdesc_Colour group': color,
      Tech_Material: 6039,
      Tech_Connectivity: connectivity_infrared_heating_panel,
      Heat_output: heat_output,
      Product_weight: product_weight,
      Tech_Wattage: watts,
      pdf_product_guide: publication,
      'Tech_Room use': room_use_infrared_heating_panel,
      'Core_Product type': core_product_type
    },
    optional: {
      pdf_product_guide: nil,
      Heating_element_type: nil,
      Product_depth: depth,
      'Std_IP rating': nil,
      Std_Standard: nil,
      'Vdesc_Product shape': shape_infrared_heating_panel,
      Programme_facility: programmable,
      'Tech_Fittings & fixings included': nil,
      'Function(s)': nil,
      'Tech_Maximum heat output': watts,
      'Tech_Model name/number': item.sku,
      Mounting_orientation: mounting_orientation,
      Open_window_detection: 'No',
      Presence_sensor: 'No',
      Tech_Programmes: nil,
      Remote_controlled: 'No',
      Smart: 'No',
      Smartphone_compatibility: nil
    }
  }
end

#ip_ratingObject



140
141
142
143
144
145
146
147
148
149
150
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 140

def ip_rating
  return unless (ir = item.spec_output(:ingress_protection_ipxx_rating))

  {
    IP20: '3',
    IP44: '1', # Towel warmers
    IP55: '89',
    IP65: '7', # Infrared heating panels
    IP66: '12'
  }.with_indifferent_access[ir]
end

#materialObject



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 370

def material
  # ABS plastic, aluminium, copper & sheet metal 11998
  # Aluminium 6039
  # Aluminium & plastic 7575
  # Aluminium, glass & steel 10785
  # Cast iron 11448
  # Ceramic 6789
  # Glass 8078
  # Glass & steel 7727
  # Low carbon steel 10680
  # Metal & plastic 7803
  # Metal & steel 7802
  # Mild steel 7813
  # Plastic 6441
  # Stainless steel 6793
  # Steel 6016

  material = item.rendered_product_specifications.dig(:material, :raw)
  case material
  when /Steel/i
    6793
  when /Glass/i
    8078
  else
    @error_list << "Material #{material} not mapped for item #{item.sku}."
  end
end

#mirakl_product_categoryObject



132
133
134
135
136
137
138
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 132

def mirakl_product_category
  if item.is_infrared_heating_panel?
    'PIM_10550'
  elsif item.is_towel_warmer?
    'PIM_10552'
  end
end

#mounting_orientationObject



307
308
309
310
311
312
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 307

def mounting_orientation
  # Horizontal 1
  # Horizontal or vertical 2
  # Vertical 3
  2
end

#product_weightObject



412
413
414
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 412

def product_weight
  item.base_weight_converted(unit: 'kg').round(2)
end

#programmableObject



433
434
435
436
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 433

def programmable
  # Non-programmable 11
  11
end

#publicationObject



152
153
154
155
156
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 152

def publication
  Item::PublicationRetriever.new.process(item.sku, locale: :fr, publication_category_paths: LtreePaths::PC_PUBLICATIONS_INSTALLATION).all_publications&.first&.publication_url
rescue StandardError
  ''
end

#range_infrared_heating_panelObject



292
293
294
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 292

def range_infrared_heating_panel
  'Electric Radiant Panel'
end

#range_twObject



221
222
223
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 221

def range_tw
  'Electric Towel Warmers'
end

#room_use_infrared_heating_panelObject



416
417
418
419
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 416

def room_use_infrared_heating_panel
  # Bathroom, bedroom, kitchen & living room 76
  76
end

#shape_infrared_heating_panelObject



428
429
430
431
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 428

def shape_infrared_heating_panel
  # Flat 582
  582
end

#thermostat_twObject



260
261
262
263
264
265
266
267
268
269
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 260

def thermostat_tw
  # Digital 5
  # Manual 2
  # No thermostat control 7
  # Thermostat temperature control 6
  # Thermostatic 1
  # With thermostat 3
  # Without thermostat 4
  4
end

#towel_warmer_dataObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 50

def towel_warmer_data
  {
    required: {
      Facet_product_type: facet_tw,
      Heater_product_type: heater_product_type_tw,
      Type_Range: range_tw,
      'Tech_Heating surface area': heating_area,
      Product_height: height,
      Product_width: width,
      'Vdesc_Colour group': color,
      Tech_Material: material,
      Heat_output: watts,
      Product_weight: product_weight,
      Tech_Wattage: watts,
      'Core_Product type': core_product_type,
      pdf_product_guide: publication,
      IEC_protection_class: 1
    },
    optional: {
      pdf_product_guide: nil,
      Product_depth: depth,
      'Std_IP rating': ip_rating,
      Bar_shape: bar_shape_tw,
      Programme_facility: programmable,
      Child_protection: 'No',
      Tech_Connectivity: connectivity_tw,
      Tech_Display: display_tw,
      'Tech_Fittings & fixings included': nil,
      'Tech_Maximum heat output': watts,
      'Tech_Maximum timer time': nil,
      'Tech_Model name/number': sku,
      Motion_sensor: 'No',
      Open_window_detection: 'No',
      Presence_sensor: 'No',
      Remote_controlled: 'No',
      'Tech_Thermostatic control': thermostat_tw
    }
  }
end

#wattsObject



403
404
405
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 403

def watts
  item.spec_value(:watts)
end

#widthObject



323
324
325
326
327
328
# File 'app/services/edi/mirakl_seller/castorama/product_data_presenter.rb', line 323

def width
  width = item.spec_value(:width, output_unit: 'mm')
  return nil if width.blank?

  width.to_i
end