Skip to content

Instantly share code, notes, and snippets.

@rterbush
Last active December 17, 2015 19:59
Show Gist options
  • Save rterbush/5664732 to your computer and use it in GitHub Desktop.
Save rterbush/5664732 to your computer and use it in GitHub Desktop.
class Spree::Calculator::Shipping::QualifiedFreeShipping < Spree::Calculator
preference :minpurchase, :decimal, :default => 0
attr_accessible :preferred_minpurchase
def self.description
Spree.t(:qualified_free_shipping)
end
def compute(package)
return 0
end
def available?(package)
item_total = 0
package.contents.each do | item |
item_total += (item.variant.price * item.quantity)
end
(item_total >= BigDecimal(self.preferred_minpurchase.to_s)) ? true : false
end
end
@rterbush
Copy link
Author

Load in config/initializers/spree.rb with the following:

Rails.application.config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::QualifiedFreeShipping

@rterbush
Copy link
Author

Try this in 1.3
in config/application.rb

        config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::QualifiedFreeShipping

@Lordnibbler
Copy link

@rterbush have you made any more adjustments on this calculator for Spree 2.0.3 update? It seems to be throwing an error now when I continue past /checkout/address: undefined methodeach' for #Spree::Stock::Package:0x007fb7e0c43c50` at line 17 of this file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment