Sha256: 82b388b5df23dbc408fbe277afc508d737c599ef9d1ca82e8d17e0fbefd3947d

Contents?: true

Size: 1.44 KB

Versions: 62

Compression:

Stored size: 1.44 KB

Contents

module Workarea
  class CategoriesSeeds
    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

    # TODO remove in v3.5 as this is no longer used
    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
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.26 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.45 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.25 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.23 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.44 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.22 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.43 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.21 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.42 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.20 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.41 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.19 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.40 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.18 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.39 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.17 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.38 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.16 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.37 app/seeds/workarea/categories_seeds.rb