Class: Stay::Store

Inherits:
ApplicationRecord show all
Includes:
TranslatableResource
Defined in:
app/models/stay/store.rb

Constant Summary collapse

TRANSLATABLE_FIELDS =

acts_as_paranoid

%i[meta_description meta_keywords seo_title facebook
twitter instagram customer_support_email description
address contact_phone new_order_notifications_email].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_localesObject



50
51
52
53
54
# File 'app/models/stay/store.rb', line 50

def self.available_locales
  Rails.cache.fetch('stores_available_locales') do
    Stay::Store.all.map(&:supported_locales_list).flatten.uniq
  end
end

.defaultObject



40
41
42
43
44
45
46
47
48
# File 'app/models/stay/store.rb', line 40

def self.default
  Rails.cache.fetch('default_store') do
    if where(default: true).any?
      where(default: true).first
    else
      new(default: true)
    end
  end
end

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/stay/store.rb', line 80

def can_be_deleted?
  self.class.where.not(id: id).any?
end

#formatted_urlObject



60
61
62
63
64
65
66
67
68
# File 'app/models/stay/store.rb', line 60

def formatted_url
  return if url.blank?

  @formatted_url ||= if url.match(/http:\/\/|https:\/\//)
                       url
                     else
                       Rails.env.development? || Rails.env.test? ? "http://#{url}" : "https://#{url}"
                     end
end

#seo_meta_descriptionObject



84
85
86
87
88
89
90
91
92
# File 'app/models/stay/store.rb', line 84

def seo_meta_description
  if meta_description.present?
    meta_description
  elsif seo_title.present?
    seo_title
  else
    name
  end
end

#supported_currencies_listObject



74
75
76
77
78
# File 'app/models/stay/store.rb', line 74

def supported_currencies_list
  @supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).sort.map(&:to_s).map do |code|
    ::Money::Currency.find(code.strip)
  end.uniq.compact
end

#supported_locales_listObject



70
71
72
# File 'app/models/stay/store.rb', line 70

def supported_locales_list
  @supported_locales_list ||= (read_attribute(:supported_locales).to_s.split(',') << default_locale).compact.uniq.sort
end

#unique_nameObject



56
57
58
# File 'app/models/stay/store.rb', line 56

def unique_name
  @unique_name ||= "#{name} (#{code})"
end