Class: ShoppingCart::CreateOrder

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/shopping_cart/create_order.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CreateOrder

Returns a new instance of CreateOrder.



3
4
5
6
7
# File 'app/commands/shopping_cart/create_order.rb', line 3

def initialize(params)
  @id = params[:productable_id].to_i
  @type = params[:productable_type]
  @quantity = params[:quantity].to_i
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
# File 'app/commands/shopping_cart/create_order.rb', line 9

def call
  return broadcast(:invalid) unless @id && @type && @quantity
  transaction do
    add_item_to_order
  end
  broadcast :ok
end