Class: Workarea::Lint::InconsistentDetails

Inherits:
Workarea::Lint show all
Defined in:
lib/workarea/lint/inconsistent_details.rb

Instance Attribute Summary

Attributes inherited from Workarea::Lint

#errors, #warnings

Instance Method Summary collapse

Methods inherited from Workarea::Lint

#catalog_skus, #error, #initialize, #inventory_skus, lint_classes, lints_paths, load_lint_classes, #pricing_skus, run, #warn

Constructor Details

This class inherits a constructor from Workarea::Lint

Instance Method Details

#check_details(all_options, variant) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/workarea/lint/inconsistent_details.rb', line 19

def check_details(all_options, variant)
  if variant.details.blank?
    warn("#{variant.product.id},#{variant.sku},missing details")
  else
    all_options.each do |option|
      if variant.details[option].blank?
        warn("#{variant.product.id},#{variant.sku},missing detail `#{option}`")
      end
    end
  end
end

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/workarea/lint/inconsistent_details.rb', line 4

def run
  Catalog::Product.all.each_by(100) do |product|
    all_options = product
                    .variants
                    .map { |v| v.details.keys }
                    .flatten
                    .uniq
                    .sort

    product.variants.each do |variant|
      check_details(all_options, variant)
    end
  end
end