Class: Edi::MiraklSeller::Bricomarche::ProductDataPresenter

Inherits:
Edi::MiraklSeller::BaseMiraklPresenter show all
Defined in:
app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb

Overview

Service object: product data presenter.

Instance Attribute Summary

Attributes inherited from Edi::MiraklSeller::BaseMiraklPresenter

#image_locales

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from Edi::MiraklSeller::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



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 169

def bar_shape_tw
  # Carré 112396
  # Plat 112397
  # Rond 112398
  shape = item.spec_value(:bar_shape)
  if shape == 'Square'
    112_396
  elsif shape == 'Round'
    112_398
  else
    @error_list << "Bar Shape TW missing for item #{item.sku}. Bricomarche "
  end
end

#brandObject



91
92
93
94
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 91

def brand
  # WarmlyYours 18092
  'WARMLYYOURS'
end

#colorObject



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 295

def color
  color = item.finish
  case color
  when /Polished|Brushed|Stainless|Steel/i
    117_974
  when /Bronze/i
    117_968
  when /Gold/i
    117_976
  when /Black/i
    117_975
  when /White/i
    117_964
  when /Mirror|Glass/i
    117_974
  else
    @error_list << "Color #{color} not mapped for item #{item.sku}. Bricomarche "
  end
end

#depthObject



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

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

  depth.to_i
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
49
50
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 6

def generic_data
  {
    required: {
      category: mirakl_product_category,
      shop_sku: ean13,
      name: name(locale: :fr),
      main_image: images[0],
      code: ean13,
      brand: brand,
      description: detailed_description_html(locale: :fr),
      dangerous: 'ID_0002'
    },
    optional: {
      advantages_1: feature_1(locale: :fr),
      advantages_2: feature_2(locale: :fr),
      advantages_3: feature_3(locale: :fr),
      advantages_4: feature_4(locale: :fr),
      advantages_5: feature_5(locale: :fr),
      madeIn: coo,
      guarantee: warranty_months,
      conditionedWeight: product_weight,
      conditionedWidth: width,
      conditionedDepth: depth,
      conditionedHeight: height,
      'Image 2': images[1],
      'Image 3': images[2],
      'Image 4': images[3],
      'Image 5': images[4],
      'Image 6': images[5],
      'Image 7': images[6],
      'Image 8': images[7],
      PDF_1: nil,
      PDF_2: nil,
      PDF_3: nil,
      pdf_4: nil,
      ind_reparabilite_not: nil,
      etiquette_nrj_erp: nil,
      Video_1: nil,
      Video_2: nil,
      Video_3: nil,
      PDF_5: nil,
      vente_vp: 'No'
    }
  }
end

#heating_areaObject



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
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 330

def heating_area
  ha = item.spec_value(:heating_area)
  return nil if ha.blank?

  if ha < 10
    122_727
  elsif ha >= 10 && ha < 20
    122_728
  elsif ha >= 20 && ha < 40
    122_729
  elsif ha >= 40 && ha < 60
    122_730
  elsif ha >= 60 && ha < 80
    122_731
  elsif ha >= 80 && ha < 100
    122_732
  elsif ha >= 100 && ha < 125
    122_733
  elsif ha >= 125 && ha < 150
    122_734
  elsif ha >= 150 && ha < 175
    122_735
  elsif ha >= 175 && ha < 200
    122_736
  elsif ha > 200
    122_737
  end
end

#heightObject



183
184
185
186
187
188
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 183

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

  height.to_i
end

#height_rangeObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 190

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

  if height < 5
    118_196
  elsif height >= 5 && height < 10
    118_197
  elsif height >= 10 && height < 20
    118_198
  elsif height >= 20 && height < 30
    118_199
  elsif height >= 30 && height < 40
    118_200
  elsif height >= 40 && height < 50
    118_201
  elsif height >= 50 && height < 60
    118_202
  elsif height >= 60 && height < 70
    118_203
  elsif height >= 70 && height < 80
    118_204
  elsif height >= 80 && height < 90
    118_205
  elsif height >= 90 && height < 100
    118_206
  elsif height >= 100 && height < 125
    118_207
  elsif height >= 125 && height < 150
    118_208
  elsif height >= 150 && height < 175
    118_209
  elsif height >= 175 && height < 200
    118_210
  elsif height >= 200 && height < 300
    118_211
  elsif height >= 300 && height < 400
    118_212
  elsif height >= 400 && height < 600
    118_213
  elsif height >= 600 && height < 800
    118_214
  elsif height >= 800 && height < 1000
    118_215
  elsif height > 1000
    118_216
  end
end

#infrared_heating_panel_dataObject



71
72
73
74
75
76
77
78
79
80
81
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 71

def infrared_heating_panel_data
  {
    optional: {
      CARAC_ID_1787: power_range,
      CARAC_ID_0399: heating_area,
      CARAC_ID_1621: color,
      CARAC_ID_2217: production,
      CARAC_ID_1706: nil
    }
  }
end

#materialObject



157
158
159
160
161
162
163
164
165
166
167
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 157

def material
  material = item.rendered_product_specifications.dig(:material, :raw)
  case material
  when 'Steel'
    117_851
  when 'Glass'
    117_871
  else
    @error_list << "Material #{material} not mapped for item #{item.sku}. Bricomarche "
  end
end

#mirakl_product_categoryObject



83
84
85
86
87
88
89
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 83

def mirakl_product_category
  if item.is_infrared_heating_panel?
    129_846
  elsif item.is_towel_warmer?
    129_852
  end
end

#power_rangeObject



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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 103

def power_range
  watts = item.watts
  return nil if watts.blank?

  if watts < 30
    119_086
  elsif watts.between?(30, 50)
    119_087
  elsif watts.between?(50, 80)
    119_088
  elsif watts.between?(80, 100)
    119_089
  elsif watts.between?(100, 250)
    119_090
  elsif watts.between?(250, 400)
    119_091
  elsif watts.between?(400, 600)
    119_092
  elsif watts.between?(600, 800)
    119_093
  elsif watts.between?(800, 1000)
    119_094
  elsif watts.between?(1000, 1300)
    119_095
  elsif watts.between?(1300, 1500)
    119_096
  elsif watts.between?(1500, 1700)
    119_097
  elsif watts.between?(1700, 1900)
    119_098
  elsif watts.between?(1900, 2100)
    119_099
  elsif watts.between?(2100, 2400)
    119_100
  elsif watts.between?(2400, 2800)
    119_101
  elsif watts.between?(2800, 3000)
    119_102
  elsif watts > 3000
    119_103
  else
    @error_list << "Power Watts missing for item #{item.sku}. Bricomarche "
  end
end

#product_weightObject



319
320
321
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 319

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

#productionObject



359
360
361
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 359

def production
  121_592
end

#programmable_twObject



148
149
150
151
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 148

def programmable_tw
  # No 120038
  120_038
end

#towel_warmer_dataObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 52

def towel_warmer_data
  {
    optional: {
      CARAC_ID_0281: tw_type,
      CARAC_ID_1787: power_range,
      CARAC_ID_1655: height_range,
      CARAC_ID_1651: width_range,
      CARAC_ID_0427: bar_shape_tw,
      CARAC_ID_1613: material,
      CARAC_ID_1958: programmable_tw,
      CARAC_ID_1621: color,
      CARAC_ID_0428: nil,
      CARAC_ID_0286: nil,
      CARAC_ID_2217: production,
      CARAC_ID_1706: nil
    }
  }
end

#tw_typeObject



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

def tw_type
  111_930
end

#warranty_monthsObject



96
97
98
99
100
101
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 96

def warranty_months
  raw_warranty = spec(:warranty)&.dig(:raw)
  return nil if raw_warranty.blank? || raw_warranty.to_f.zero?

  (raw_warranty.to_f * 12).to_i
end

#wattsObject



315
316
317
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 315

def watts
  item.spec_value(:watts)
end

#widthObject



239
240
241
242
243
244
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 239

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

  width.to_i
end

#width_rangeObject



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 246

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

  if width < 5
    118_112
  elsif width >= 5 && width < 10
    118_113
  elsif width >= 10 && width < 20
    118_114
  elsif width >= 20 && width < 30
    118_115
  elsif width >= 30 && width < 40
    118_116
  elsif width >= 40 && width < 50
    118_117
  elsif width >= 50 && width < 60
    118_118
  elsif width >= 60 && width < 70
    118_119
  elsif width >= 70 && width < 80
    118_120
  elsif width >= 80 && width < 90
    118_121
  elsif width >= 90 && width < 100
    118_122
  elsif width >= 100 && width < 125
    118_123
  elsif width >= 125 && width < 150
    118_124
  elsif width >= 150 && width < 175
    118_125
  elsif width >= 175 && width < 200
    118_126
  elsif width >= 200 && width < 300
    118_127
  elsif width >= 300 && width < 400
    118_128
  elsif width >= 400 && width < 600
    118_129
  elsif width >= 600 && width < 800
    118_130
  elsif width >= 800 && width < 1000
    118_131
  elsif width > 1000
    118_132
  end
end