Class: Item::SpecificationsMasher
- Inherits:
-
BaseService
- Object
- BaseService
- Item::SpecificationsMasher
- Defined in:
- app/services/item/specifications_masher.rb
Overview
specification masher takes an item or catalog item and iterates through
its specifications to render them
Defined Under Namespace
Classes: Result
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
#process(item:, tokens: [], locale: Mobility.locale) ⇒ Object
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/specifications_masher.rb', line 8 def process(item:, tokens: [], locale: Mobility.locale) specifications = {} filters = {} Mobility.with_locale(locale) do filters[:token] = tokens if tokens.present? filters[:template] = false item_specifications_definitions = item.product_specifications(filters) ActiveRecord::Associations::Preloader.new(records: item_specifications_definitions, associations: [:product_line]).call # Filter item specifications which have the name set, this is an indication # of localization present or not since mobility will query the right column item_specifications_definitions.select { |ps| ps.name.present? }.sort_by(&:render_priority).each do |ps| token = ps.token.presence || ps.name.parameterize.underscore result = ps.get_specification_data(item, skip_validation: true) next unless result.present? || ps.template_product_specification_id specifications[token.to_sym] = { id: token.to_s.camelize(:lower), name: ps.name.presence, output: result.formatted, raw: result.raw, units: ps.units.presence, product_specification_id: ps.id, visibility: ps.visibility, grouping: ps.grouping.presence, image_id: ps.image_id, static: ps.text_method?, description: ps.description, print_on_item_label: ps.print_on_item_label, locale: locale } end end Result.new(specifications: specifications.deep_symbolize_keys) end |