Class: C80Catoffers::Offer

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/c80_catoffers/offer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_widgetedObject

выдать список тех предложений, которые должны выводиться в виджете



55
56
57
# File 'app/models/c80_catoffers/offer.rb', line 55

def self.all_widgeted
  self.joins(:props)
end

.without_categoryObject

добавил возможность получить предложения, которым не назначена категория



48
49
50
51
52
# File 'app/models/c80_catoffers/offer.rb', line 48

def self.without_category
  habtm_table = Arel::Table.new(:c80_catoffers_categories_offers)
  join_table_with_condition = habtm_table.project(habtm_table[:offer_id])
  where(Offer.arel_table[:id].not_in(join_table_with_condition))
end

Instance Method Details

#categoryObject



39
40
41
42
43
44
45
# File 'app/models/c80_catoffers/offer.rb', line 39

def category
  res = nil
  if self.has_category?
    res = self.categories.first
  end
  res
end

#has_category?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/c80_catoffers/offer.rb', line 35

def has_category?
  self.categories.count > 0
end

#normalize_friendly_id(input) ⇒ Object



27
28
29
# File 'app/models/c80_catoffers/offer.rb', line 27

def normalize_friendly_id(input)
  input.to_s.to_slug.normalize(transliterations: :russian).to_s
end

#ophoto_thumb(thumb_size = 'thumb_sm') ⇒ Object

выдать обложку предложения указанного размера используется, например, при формировании списка предложений с картинками в виджете



70
71
72
73
74
75
76
# File 'app/models/c80_catoffers/offer.rb', line 70

def ophoto_thumb(thumb_size='thumb_sm')
  res = ''
  if ophotos.count > 0
    res = ophotos.first.image_thumb(thumb_size)
  end
  res
end

#ophoto_thumb_smObject

NOTE

пока используется в list_iconed, устарел, т.к. появился ophoto_thumb



60
61
62
63
64
65
66
# File 'app/models/c80_catoffers/offer.rb', line 60

def ophoto_thumb_sm
  res = ''
  if ophotos.count > 0
    res = ophotos.first.image.thumb_sm
  end
  res
end

#price_integerObject



78
79
80
81
# File 'app/models/c80_catoffers/offer.rb', line 78

def price_integer
  d = self.price.match '\d+'
  d.present? ? d[0].to_i : 0
end

#recalc_parent_sample_priceObject



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/c80_catoffers/offer.rb', line 83

def recalc_parent_sample_price
  # если Пример состоит в Строке
  if crows.count > 0
    # переберём его Строки
    crows.each do |crow|
      Rails.logger.debug "[TRACE] <Offer.recalc_parent_sample_price> Пересчитать стоимость Примера id=#{crow.csample.id}."
      # добираемся до Примера, в чьём составе находится Строка, которая "содержит" данное Преложение, и просим его пересчитать цену
      crow.csample.recalc_summ_price
    end
  else
    Rails.logger.debug '[TRACE] <Offer.recalc_parent_sample_price> У Предложения нет Строк.'
  end
end

#slug_candidatesObject



31
32
33
# File 'app/models/c80_catoffers/offer.rb', line 31

def slug_candidates
  [:title] + Array.new(6) {|index| [:title, index+2]}
end