Class: Stall::CartUpdateService

Inherits:
BaseService show all
Defined in:
app/services/stall/cart_update_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cart, params) ⇒ CartUpdateService

Returns a new instance of CartUpdateService.



5
6
7
8
# File 'app/services/stall/cart_update_service.rb', line 5

def initialize(cart, params)
  @cart = cart
  @params = params
end

Instance Attribute Details

#cartObject (readonly)

Returns the value of attribute cart.



3
4
5
# File 'app/services/stall/cart_update_service.rb', line 3

def cart
  @cart
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/services/stall/cart_update_service.rb', line 3

def params
  @params
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
# File 'app/services/stall/cart_update_service.rb', line 10

def call
  cart.update(params).tap do |saved|
    return false unless saved

    # Recalculate shipping fee if available for calculation to ensure
    # that the fee us always up to date when displayed to the customer
    shipping_fee_service.call if shipping_fee_service.available?
  end
end