Class: Edi::MiraklSeller::BaseMiraklPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/services/edi/mirakl_seller/base_mirakl_presenter.rb

Overview

Service object: base mirakl presenter.

Instance Attribute Summary collapse

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

#initialize(item, options = {}) ⇒ BaseMiraklPresenter

def self.required_attributes=(*attributes)
self.required_attributes = attributes
end

Parameters:

  • item (CatalogItem)

    the item being presented

  • options (Hash) (defaults to: {})

    presenter options

Options Hash (options):

  • image_locales (Array<String>, nil)

    locales to select images for



17
18
19
20
21
# File 'app/services/edi/mirakl_seller/base_mirakl_presenter.rb', line 17

def initialize(item, options = {})
  @image_locales = options.delete(:image_locales)
  @error_list = []
  super(item, nil, options)
end

Instance Attribute Details

#image_localesObject (readonly)

Returns the value of attribute image_locales.



7
8
9
# File 'app/services/edi/mirakl_seller/base_mirakl_presenter.rb', line 7

def image_locales
  @image_locales
end

Instance Method Details

#imagesObject



34
35
36
37
38
39
40
41
42
# File 'app/services/edi/mirakl_seller/base_mirakl_presenter.rb', line 34

def images
  # Use website image profiles (up to 9 images for Mirakl)
  item.image_profiles
      .website_image_profiles
      .image_order
      .includes(:image)
      .limit(9)
      .map { |p| p.image.image_url(width: 2000, height: 2000, encode_format: :jpeg) }
end

#to_hObject



23
24
25
26
27
28
29
30
31
32
# File 'app/services/edi/mirakl_seller/base_mirakl_presenter.rb', line 23

def to_h
  category_data = if is_towel_warmer?
                    towel_warmer_data
                  elsif is_infrared_heating_panel?
                    infrared_heating_panel_data
                  end
  return if category_data.nil?

  generic_data.deep_merge(category_data)
end

#videoObject



44
45
46
# File 'app/services/edi/mirakl_seller/base_mirakl_presenter.rb', line 44

def video
  Item::VideoRetriever.new(tags: 'for-product-page').process(item).all_videos[0]
end