Class: Stall::AddToCartService
- Inherits:
-
BaseService
- Object
- BaseService
- Stall::AddToCartService
- Defined in:
- app/services/stall/add_to_cart_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) ⇒ AddToCartService
constructor
A new instance of AddToCartService.
- #line_item ⇒ Object
Constructor Details
#initialize(cart, params) ⇒ AddToCartService
Returns a new instance of AddToCartService.
5 6 7 8 |
# File 'app/services/stall/add_to_cart_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/add_to_cart_service.rb', line 3 def cart @cart end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'app/services/stall/add_to_cart_service.rb', line 3 def params @params end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/stall/add_to_cart_service.rb', line 10 def call return false unless line_item.valid? unless assemble_identical_line_items cart.line_items << line_item end cart.save.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 |
#line_item ⇒ Object
26 27 28 29 30 |
# File 'app/services/stall/add_to_cart_service.rb', line 26 def line_item @line_item ||= sellable.to_line_item.tap do |line_item| line_item.quantity = params[:quantity] end end |