class ProductUpdateSingleton

Public Class Methods

new() click to toggle source
# File lib/product_update_single.rb, line 7
def initialize
  #@count = Array.new(10, 0)
  #@product_id = Array.new
  
end

Public Instance Methods

count_update(order_records) click to toggle source

this method updates the count column in the product model based on the quantity of products sold.

# File lib/product_update_single.rb, line 34
def count_update(order_records)
  #@order_confirmed = Order.last
  #@order_record = OrderItem.where(order_id: @order_confirmed.id)
  @store_memory = []
  @order_record = order_records
  @order_record.each do |order_record|
   @product_count_update = Product.find(order_record.product_id)
   if(@product_count_update.count?)
     puts(@product_count_update)
     @product_count_update.count += order_record.quantity
   else
     @product_count_update.count = 0
     @product_count_update.count += order_record.quantity
   end
   puts("inside count update function and order item should have been initiated by now")
   #@product_count_update.quantityAvailable -= order_record.quantity
   @product_count_update.save
   @store_memory << @product_count_update.store_detail_id
  end
  puts("count update should be completed by now and quantity of product ordered should be have been subtracted in the product")
  @store_memory.uniq.each do |call_hit|
    self.hit_counter(call_hit)
  end
end
hit_counter(store_id) click to toggle source

this method is triggered by the count update method internally to rank the products by its count updated previously.

# File lib/product_update_single.rb, line 60
def hit_counter(store_id)
  @count_iterate = 1
  @prod = Product.where(store_detail_id: store_id)
  @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() click to toggle source
# 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() click to toggle source
# File lib/product_update_single.rb, line 72
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