Class: FlexCommerce::PaypalExpress::ShippingMethodsForCart
- Inherits:
-
Object
- Object
- FlexCommerce::PaypalExpress::ShippingMethodsForCart
- Includes:
- Enumerable
- Defined in:
- lib/paypal_express/shipping_methods_for_cart.rb
Overview
This deals with free shipping promotions and updates the shipping methods accordingly
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(cart:, shipping_methods:) ⇒ ShippingMethodsForCart
constructor
A new instance of ShippingMethodsForCart.
Constructor Details
#initialize(cart:, shipping_methods:) ⇒ ShippingMethodsForCart
Returns a new instance of ShippingMethodsForCart.
11 12 13 14 15 |
# File 'lib/paypal_express/shipping_methods_for_cart.rb', line 11 def initialize(cart:, shipping_methods:) self.cart = cart self.shipping_methods = shipping_methods self.shipping_promotions = cart.available_shipping_promotions end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/paypal_express/shipping_methods_for_cart.rb', line 17 def call free_shipping_method_ids = [ ] shipping_promotions.reverse.each do |promotion| # See if promotion is having a shipping method, # and also see if that cart total is eligible for promotion if promotion.shipping_methods && can_apply_promotion_to_cart?(promotion: promotion) free_shipping_method_ids << promotion.shipping_methods.map(&:id) end end free_shipping_method_ids.flatten! updated_shipping_methods = [] shipping_methods.each do |shipping_method| shipping_method_free = free_shipping_method_ids.include?(shipping_method.id) updated_shipping_methods << CartShippingMethod.new(shipping_method, shipping_method_free) end updated_shipping_methods end |