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.4.27 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.4 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.26 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.3 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.25 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.2 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.24 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.1 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.23 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.22 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.0 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.21 app/seeds/workarea/categories_seeds.rb
workarea-core-3.5.0.beta.1 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.20 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.19 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.18 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.17 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.16 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.15 app/seeds/workarea/categories_seeds.rb
workarea-core-3.4.14 app/seeds/workarea/categories_seeds.rb