Class: Item::SpecFixer

Inherits:
BaseService show all
Defined in:
app/services/item/spec_fixer.rb

Overview

This is a utility class you can use to serve as baseline for
mass update of product secifications

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#fix_spec(query, approvals) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/services/item/spec_fixer.rb', line 53

def fix_spec(query, approvals)
  query.select { |i| i.spec_output(:approvals) != approvals }.map do |i|
    old_val = i.spec_output(:approvals)
    i.create_or_set_spec_value(token: :approvals, name: 'Approvals', grouping: 'Warranty / Certifications', text_blurb: approvals)
    i.update_rendered_product_specifications(tokens: %i[approvals])
    [i.sku, old_val, approvals]
  end
end

#processObject



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
# File 'app/services/item/spec_fixer.rb', line 4

def process
  # Use ltree on denormalized pc_path_ids - no JOIN needed
  base_tw_query = Item.towel_warmers.where(is_kit: false).non_publications # .active
  r = []
  Item.transaction do
    # all the tws models are CULUS
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TWS%")), 'cULus listed')
    # # all the TW HP models are CETLUS
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-HP")), 'cETLus listed')
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-HP-BTK")), 'cETLus listed')
    # # barcelona FS2 model is CETLUS
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-FS2")), 'cETLus listed')
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-FS2-BTK")), 'cETLus listed')
    # # all the TWE models are CE
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TWE%")), 'CE')
    # # all the old HW and PL models are CULUS
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-HW")), 'cULus listed')
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TW%-HW-BTK")), 'cULus listed')
    # r += fix_spec(base_tw_query.where(Item[:sku].matches("TWHBX%")), 'cULus listed')

    # cULus overrides
    skus = %w[TW-BC-08BS-FS
              TW-BC-08BS-FS-BTK
              TW-E2CP
              TW-E3CP
              TW-E4PCP
              TW-E4PCP-BTK
              TW-F10BS-HP
              TW-F10BS-HW-CE
              TW-F10BS-PL
              TW-F10BS-PL-BTK
              TW-MD-08BS-DO-LW
              TW-MT-10PS-HW-HD
              TW-PCP
              TW-ST-06BS-PL
              TW-ST-C06BS-PL
              TW-ST-C06PS-PL]
    r += fix_spec(base_tw_query.where(sku: skus), 'cULus listed')
  end
  r
end

#reportObject



46
47
48
49
50
51
# File 'app/services/item/spec_fixer.rb', line 46

def report
  # Use ltree scope instead of URL matching - no JOIN needed
  Item.towel_warmers.where(is_kit: false).non_publications.active.where(Item[:sku].matches('TW%')).map do |i|
    [i.spec_output(:approvals) || 'Not Set', i.sku, i.name].join(' , ')
  end.sort.join("\n")
end