Last active
December 17, 2015 19:59
-
-
Save rterbush/5664732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Try this in 1.3
in config/application.rb
config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::QualifiedFreeShipping
@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 method
each' 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
Load in config/initializers/spree.rb with the following: