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

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

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



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

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



88
89
90
91
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 88

def brand
  # WarmlyYours 18092
  'WARMLYYOURS'
end

#colorObject



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

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



320
321
322
323
324
325
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 320

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

  depth.to_i
end

#generic_dataObject



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

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



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

def heating_area
  ha = item.spec_value(:heating_area)
  return nil unless ha.present?

  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



180
181
182
183
184
185
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 180

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

  height.to_i
end

#height_rangeObject



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

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

  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

#materialObject



154
155
156
157
158
159
160
161
162
163
164
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 154

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



80
81
82
83
84
85
86
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 80

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

#power_rangeObject



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

def power_range
  watts = item.watts
  return nil unless watts.present?

  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



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

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

#productionObject



356
357
358
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 356

def production
  121_592
end

#programmable_twObject



145
146
147
148
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 145

def programmable_tw
  # No 120038
  120_038
end

#radiant_panel_dataObject



68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 68

def radiant_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

#towel_warmer_dataObject



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

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



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

def tw_type
  111_930
end

#warranty_monthsObject



93
94
95
96
97
98
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 93

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



312
313
314
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 312

def watts
  item.spec_value(:watts)
end

#widthObject



236
237
238
239
240
241
# File 'app/services/edi/mirakl_seller/bricomarche/product_data_presenter.rb', line 236

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

  width.to_i
end

#width_rangeObject



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

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

  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