Class: Stall::ShippingFeeCalculatorService
- Inherits:
-
BaseService
- Object
- BaseService
- Stall::ShippingFeeCalculatorService
- Defined in:
- app/services/stall/shipping_fee_calculator_service.rb
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #call ⇒ Object
-
#initialize(cart) ⇒ ShippingFeeCalculatorService
constructor
A new instance of ShippingFeeCalculatorService.
Constructor Details
#initialize(cart) ⇒ ShippingFeeCalculatorService
Returns a new instance of ShippingFeeCalculatorService.
5 6 7 |
# File 'app/services/stall/shipping_fee_calculator_service.rb', line 5 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
3 4 5 |
# File 'app/services/stall/shipping_fee_calculator_service.rb', line 3 def cart @cart end |
Instance Method Details
#available? ⇒ Boolean
26 27 28 29 30 |
# File 'app/services/stall/shipping_fee_calculator_service.rb', line 26 def available? cart.line_items.length > 0 && cart.try(:shipping_address) && cart.try(:shipment).try(:shipping_method) end |
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/stall/shipping_fee_calculator_service.rb', line 9 def call return unless cart.shipment && cart.shipment.shipping_method calculator_identifier = cart.shipment.shipping_method.identifier calculator_class = Stall::Shipping::Calculator.for(calculator_identifier) if calculator_class calculator = calculator_class.new(cart, cart.shipment.shipping_method) cart.shipment.update_attributes( price: calculator.price, eot_price: calculator.eot_price, vat_rate: calculator.vat_rate ) end end |