Class: Workarea::WishListSeeds

Inherits:
Object
  • Object
show all
Defined in:
app/seeds/workarea/wish_list_seeds.rb

Instance Method Summary collapse

Instance Method Details

#performObject



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
# File 'app/seeds/workarea/wish_list_seeds.rb', line 3

def perform
  puts 'Adding wish lists...'

  5.times do
    user = Workarea::User.sample
    wish_list = Workarea::WishList.for_user(user.id)
    Workarea::Catalog::Product.limit(5).each do |product|
      sku = product.skus.sample
      quantity = rand(3) + 1

      next unless sku
      wish_list.add_item(product.id, sku, quantity)

      Metrics::ProductByDay.inc(
        key: { product_id: product.id },
        wish_list_adds: 1
      )

      if rand(2).zero?
        purchased_quantity = rand(quantity) + 1
        wish_list.mark_item_purchased(sku, purchased_quantity)

        Metrics::ProductByDay.inc(
          key: { product_id: product.id },
          wish_list_units_sold: purchased_quantity,
          wish_list_revenue: rand(10000) / 100.0
        )
      end
    end
  end
end