Sha256: b9762cd185c285c669f50a344f341a27f18089e53d8b6f520945d2324ef859d9

Contents?: true

Size: 889 Bytes

Versions: 2

Compression:

Stored size: 889 Bytes

Contents

module PiggybakFreeShippingByProduct
  module PiggybakOrdersControllerDecorator
    extend ActiveSupport::Concern

    included do
      alias :piggybak_shipping :shipping
      def shipping; custom_shipping; end
    end

    def custom_shipping
      cart = Piggybak::Cart.new(request.cookies["cart"])
      cart.set_extra_data(params)
      shipping_methods = Piggybak::ShippingMethod.lookup_methods(cart)
      
      free_shipping_method = Piggybak::ShippingMethod.all.detect { |s| s.klass == "::PiggybakFreeShippingByProduct::FreeShippingByProduct" }
      if free_shipping_method.present?
        free_shipping_available = shipping_methods.detect { |s| s[:id] == free_shipping_method.id }
        if free_shipping_available.present?
          render :json => [free_shipping_available]
          return 
        end
      end

      render :json => shipping_methods
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
piggybak_free_shipping_by_product-0.0.2 lib/piggybak_free_shipping_by_product/piggybak_orders_controller_decorator.rb
piggybak_free_shipping_by_product-0.0.1 lib/piggybak_free_shipping_by_product/piggybak_orders_controller_decorator.rb