Class: Workarea::CategoriesSeeds
- Inherits:
-
Object
- Object
- Workarea::CategoriesSeeds
- Defined in:
- app/seeds/workarea/categories_seeds.rb
Instance Method Summary collapse
-
#find_unique_name ⇒ Object
TODO remove in v3.5 as this is no longer used.
- #perform ⇒ Object
Instance Method Details
#find_unique_name ⇒ Object
TODO remove in v3.5 as this is no longer used
39 40 41 42 43 44 45 46 47 48 |
# File 'app/seeds/workarea/categories_seeds.rb', line 39 def find_unique_name department = Faker::Commerce.department(1) categories = Catalog::Category.all.to_a until categories.select { |c| c.name == department }.empty? department = Faker::Commerce.department(2) end department end |
#perform ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/seeds/workarea/categories_seeds.rb', line 3 def perform puts 'Adding categories...' rules = [ { name: 'price', operator: 'greater_than', value: 40 }, { name: 'price', operator: 'less_than', value: 40 }, { name: 'search', operator: 'equals', value: '*' }, { name: 'search', operator: 'equals', value: 'awesome' }, { name: 'search', operator: 'equals', value: 'intelligent OR sleek' }, { name: 'available_inventory', operator: 'less_than', value: '25' } ] Sidekiq::Callbacks.disable do Catalog::Category.create!( name: 'New', default_sort: Sort.newest, product_rules: [ { name: 'search', operator: 'equals', value: 'created_at:[now-30d TO now]' } ] ) Workarea.config.default_seeds_taxonomy.values.flatten.each do |name| Catalog::Category.create!( name: name, product_rules: [rules.sample], default_sort: Search::CategoryBrowse.available_sorts.sample ) end end end |