Class: Commands::Approval::InitiateCartApproval

Inherits:
Base
  • Object
show all
Defined in:
app/commands/approval/initiate_cart_approval.rb

Instance Method Summary collapse

Instance Method Details

#import_details(cart, params) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
# File 'app/commands/approval/initiate_cart_approval.rb', line 4

def import_details(cart, params)
  unless params['properties'].blank?
    cart.set_props(params['properties'])
  end
  unless params['cartItems'].blank?
    cart.import_cart_items(params['cartItems'])
  end
  unless params['initiationComment'].blank?
    cart.import_initial_comments(params['initiationComment'])
  end
end

#perform(params) ⇒ Object


37
38
39
40
41
42
# File 'app/commands/approval/initiate_cart_approval.rb', line 37

def perform(params)
  cart = self.setup_cart(params)
  Dispatcher.deliver_new_cart_emails(cart)

  cart
end

#setup_cart(params) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/commands/approval/initiate_cart_approval.rb', line 16

def setup_cart(params)
  cart = Cart.initialize_cart_with_items(params)
  cart.save!

  # Reload needed because of caching of the associations.
  # TODO Remove need for this.
  cart.reload

  if params['approvalGroup'].present?
    unless cart.approvals.any?
      cart.process_approvals_from_approval_group
    end
  else
    cart.process_approvals_without_approval_group(params)
  end

  self.import_details(cart, params)

  cart
end