module C80Yax class ItemDecorator < ::ApplicationDecorator decorates 'C80Yax::Item' delegate_all def my_url "/katalog/#{model.strsubcat.slug}/#{model.id}" end def main_image(thumb_size = 'thumb_md', options = {}) rel = options.fetch(:rel, 'follow') a_href = options.fetch(:a_href, my_url) ww = fetch_ww(thumb_size) hh = fetch_hh(thumb_size) h.render_image_link_lazy({ :alt_image => model.title, # :image => main_image_tag(thumb_size), :image => self.fetch_first_photo(thumb_size), :a_href => a_href, :rel => rel, :a_class => 'item_main_image', :a_css_style => "width:#{ww}px;height:#{hh}px", :image_width => ww, :image_height => hh }) end def h3_title(thumb_size = 'thumb_md') ww = fetch_ww(thumb_size) h.content_tag :h3, model.title, style: "width:#{ww}px" end def div_prices # Rails.logger.debug '[TRACE] ------[begin]--------' result = '' if model.is_ask_price result = "

Уточнить цену

" else # props = { titles: [], values: [], uoms: [], values_old: [] } model.item_props.each do |ip| # Rails.logger.debug "[TRACE] ip.prop_name.related.present? = #{ip.prop_name.related.present?}" if ip.prop_name.is_normal_price props[:titles] << ip.prop_name.title props[:values] << ip.value props[:uoms] << ip.prop_name.uom_title # у свойства "нормальная цена" может быть "старый вариант" if ip.prop_name.related.present? # фиксируем айдишник свойства "старый вариант этой цены" related_id = ip.prop_name.related.id # и зафиксирем его значение model.item_props.each do |iip| # Rails.logger.debug "[TRACE] iip.prop_name.id = #{iip.prop_name.id} VS #{related_id}" if iip.prop_name.id == related_id # props[:titles] << iip.prop_name.title props[:values_old] << iip.value # props[:uoms] << iip.prop_name.uom_title break end end end end end # Rails.logger.debug "[TRACE] props: #{props}" # # res = '' props[:titles].each_with_index do |title, i| e = "

#{props[:values_old][i]} #{_uom(props[:uoms][i])}

" # 1212,80 руб e += "

#{props[:values][i]} #{_uom(props[:uoms][i])}

" # 1212,80 руб e = "
  • #{e}
  • " res += e end # Rails.logger.debug '[TRACE] ------- [end] ------- ' result = "
      #{res}
    " #
    end "
    #{result}
    ".html_safe end def _uom(v) return '' if v.nil? v end def btn_order h.link_to '', '#', class: 'add_to_bucket_sm' end def h1_title h.content_tag :h1, model.title end def props_list res = '' ps = %w(customer price duration when) ds = %w(клиент бюджет срок\ выполнения дата) ps.each_with_index do |p, index| v = model.send(p) next if v.blank? res += "
  • #{ds[index]}: #{model.send(p)}
  • " end "".html_safe end def images_no_main(thumb_size = 'thumb_sm') res = '' model.iphotos.each_with_index do |wp, index| next if index.zero? img = h.image_tag wp.image.send(thumb_size).url lnk = h.link_to img, wp.image.thumb_lg.url res += "
  • #{lnk}
  • " end "".html_safe end def div_p_desc res = '' res = model.desc.html_safe if model.desc.present? "
    #{res}
    ".html_safe end # выдать url миниатюры указанного +thumb_size+ типа # первой попавшейся фотки обьекта def fetch_first_photo(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] ' res = '' if model.iphotos.size > 0 res = model.iphotos.first.image.send(thumb_size) end res end def fetch_ww(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] ' @ww ||= ItemPhotosSizesCache.instance.thumb_width(thumb_size) end def fetch_hh(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] ' @hh ||= ItemPhotosSizesCache.instance.thumb_height(thumb_size) end end end