Sha256: d078286f21dc5b1020bc3fc1ae8dadce48cbb60a4867289106595f433e4659de

Contents?: true

Size: 806 Bytes

Versions: 2

Compression:

Stored size: 806 Bytes

Contents

module PiggybakFreeShippingByProduct
  class FreeShippingByProduct
    # This assumes that your product has a method defined by your configuration
    KEYS = ["product_method_name"]

    def self.description
      "Free Shipping by Product"
    end 

    def self.available?(method, object)
      product_method = method.metadata.detect { |m| m.key == "product_method_name" }.value

      if object.is_a?(Piggybak::Cart)
        return object.sellables.all? { |s| s[:sellable].item.respond_to?(product_method) && s[:sellable].item.send(product_method) }
      else
        return object.line_items.sellables.all? { |s| s.sellable.item.respond_to?(product_method) && s.sellable.item.send(product_method) }
      end
      return false
    end

    def self.rate(method, object)
      0.00
    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/free_shipping_by_product.rb
piggybak_free_shipping_by_product-0.0.1 lib/piggybak_free_shipping_by_product/free_shipping_by_product.rb