cirandas.net

ref: master

plugins/orders/controllers/public/orders_plugin_controller.rb


 1
 2
 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
34
35
36
37
class OrdersPluginController < PublicController

  include OrdersPlugin::TranslationHelper

  helper OrdersPlugin::TranslationHelper
  helper OrdersPlugin::DisplayHelper

  def repeat
    @orders = previous_orders.last(5).reverse
    @orders.each{ |o| o.enable_product_diff }
  end

  def clear_orders_session
    return if user
    previous_orders.update_all session_id: nil
  end

  protected

  def session_id
    session['session_id']
  end

  # reimplement on subclasses
  def supplier
  end

  def previous_orders
    if user
      supplier.orders.where consumer_id: user.id
    else
      supplier.orders.where session_id: session_id
    end
  end

end