Class: Stall::CartUpdateService
- Inherits:
-
BaseService
- Object
- BaseService
- Stall::CartUpdateService
- Defined in:
- app/services/stall/cart_update_service.rb
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(cart, params = {}) ⇒ CartUpdateService
constructor
A new instance of CartUpdateService.
- #refresh_associated_services! ⇒ Object
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
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
3 4 5 |
# File 'app/services/stall/cart_update_service.rb', line 3 def cart @cart end |
#params ⇒ Object (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
#call ⇒ Object
10 11 12 13 14 15 |
# File 'app/services/stall/cart_update_service.rb', line 10 def call cart.update(params).tap do |saved| return false unless saved refresh_associated_services! end end |
#refresh_associated_services! ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/services/stall/cart_update_service.rb', line 17 def refresh_associated_services! # 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? # Recalculate the credit usage amount if already used to avoid negative # cart totals credit_usage_service.ensure_valid_or_remove! if credit_usage_service.available? && credit_usage_service.credit_used? end |