Module: SpreeMobility::CoreExt::Spree::TaxonDecorator::TranslationMethods

Defined in:
lib/spree_mobility/core_ext/spree/taxon_decorator.rb

Instance Method Summary collapse

Instance Method Details

#name_uniqueness_validationObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spree_mobility/core_ext/spree/taxon_decorator.rb', line 19

def name_uniqueness_validation
  return unless name.present?
  return unless translated_model
  check_scope =
    ::Spree::Taxon.
    where.not(id: translated_model.id).
    where(parent_id: translated_model.parent_id,
      taxonomy_id: translated_model.taxonomy_id).
    joins(:translations).
    where(spree_taxon_translations: { locale: locale }).
    where('LOWER(spree_taxon_translations.name) = ?', name.downcase)
  if check_scope.exists?
    errors.add(:name, :taken, value: name)
  end
end


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spree_mobility/core_ext/spree/taxon_decorator.rb', line 3

def permalink_uniqueness_validation
  return unless permalink.present?
  return unless translated_model
  check_scope =
    ::Spree::Taxon.
    where.not(id: translated_model.id).
    where(parent_id: translated_model.parent_id,
      taxonomy_id: translated_model.taxonomy_id).
    joins(:translations).
    where(spree_taxon_translations: { locale: locale }).
    where('LOWER(spree_taxon_translations.permalink) = ?', permalink.downcase)
  if check_scope.exists?
    errors.add(:permalink, :taken, value: permalink)
  end
end