Class: ProductUpdateSingleton
- Inherits:
-
Object
- Object
- ProductUpdateSingleton
- Includes:
- Singleton
- Defined in:
- lib/product_update_single.rb
Instance Method Summary collapse
- #count_update ⇒ Object
- #hit_counter ⇒ Object
-
#initialize ⇒ ProductUpdateSingleton
constructor
A new instance of ProductUpdateSingleton.
- #product_hit_update_on_order_confirmation ⇒ Object
- #refresh_quantity ⇒ Object
Constructor Details
#initialize ⇒ ProductUpdateSingleton
Returns a new instance of ProductUpdateSingleton.
7 8 9 10 11 |
# File 'lib/product_update_single.rb', line 7 def initialize #@count = Array.new(10, 0) #@product_id = Array.new end |
Instance Method Details
#count_update ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/product_update_single.rb', line 33 def count_update @order_confirmed = Order.last @order_record = OrderItem.where(order_id: @order_confirmed.id) @order_record.each do |order_record| @product_count_update = Product.find(order_record.product_id) puts("inside count update function and order item should have been initiated by now") @product_count_update.count += order_record.quantity @product_count_update.quantityAvailable -= order_record.quantity @product_count_update.save end puts("count update should be completed by now and quantity of product ordered should be have been subtracted in the product") self.hit_counter end |
#hit_counter ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/product_update_single.rb', line 47 def hit_counter @count_iterate = 1 @prod = Product.all @sorted_hit = @prod.order('count desc') puts("Inside hit update function and product is initiated now, it should start updated the hit ranking") @sorted_hit.each do |pro| pro.hit = @count_iterate @count_iterate += 1 pro.save end end |
#product_hit_update_on_order_confirmation ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/product_update_single.rb', line 13 def product_hit_update_on_order_confirmation #@count[@product_update.id - 1] = @count[@product_update.id - 1] + @order_record.quantity #@count_sort = @count.sort { |x,y| y <=> x } #@product_hit = Product.all #@result = @product_hit.order('hit asc') #@product_hit.each do |hit_value| #@product_id << hit_value.id #hit_value.hit = #end #@order_record = OrderItem.last #@product_hit_update = Product.find(@order_record.product_id) @order_record = OrderItem.last @product_hit_update = Product.find(@order_record.product_id) @product_hit_update.hit += @order_record.quantity @product_hit_update.quantityAvailable -= @order_record.quantity @product_hit_update.save end |
#refresh_quantity ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/product_update_single.rb', line 59 def refresh_quantity @prod = Product.all @prod.each do |p| p.quantityAvailable = 120 p.count = 0 p.price = 12 p.offerPrice = 5 p.save end end |