Created
June 24, 2012 02:40
-
-
Save iloveitaly/2981156 to your computer and use it in GitHub Desktop.
Remove annoying shipping weight messages from spree_active_shipping
This file contains hidden or 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
# for now, all USPS shipments cannot exceed 70 lbs | |
# this is also a bit sneaky b/c it relies on a particular load order | |
# should require_dependency or something | |
# http://www.uship.com/freight/articles/parcel-weight-restrictions/ | |
# Spree::ShippingMethod.all.map(&:calculator).select { |m| m.class.to_s.start_with? 'Spree::Calculator::Usps' }.each do |calculator| | |
[ | |
Spree::Calculator::Usps::PriorityMail, | |
Spree::Calculator::Usps::MediaMail, | |
Spree::Calculator::Usps::ExpressMail, | |
Spree::Calculator::Usps::PriorityMailInternational | |
].each do |calculator_class| | |
calculator_class.class_eval do | |
def available?(order) | |
multiplier = Spree::ActiveShipping::Config[:unit_multiplier] | |
weight = order.line_items.inject(0) do |weight, line_item| | |
weight + (line_item.variant.weight ? (line_item.quantity * line_item.variant.weight * multiplier) : 0) | |
end | |
# all usps cannot ship out unless 70lbs | |
# this prevents us from getting a stupid error message that makes the user think they did somethign wrong | |
weight < 1120 | |
end | |
end | |
end | |
[ | |
Spree::Calculator::Ups::Ground, | |
Spree::Calculator::Ups::SecondDayAir, | |
Spree::Calculator::Ups::NextDayAir | |
].each do |calculator_class| | |
calculator_class.class_eval do | |
def available?(order) | |
multiplier = Spree::ActiveShipping::Config[:unit_multiplier] | |
weight = order.line_items.inject(0) do |weight, line_item| | |
weight + (line_item.variant.weight ? (line_item.quantity * line_item.variant.weight * multiplier) : 0) | |
end | |
# all usps cannot ship out unless 150lb | |
weight < 2400 | |
end | |
end | |
end |
I don't do that, but that is something you could do.
For the clients situation, it made more sense to redirect them to a separate checkout process which redirected their order to a live sales personell's number.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok so you're making those Calculators unavailable for excessively heavy orders. But do you have other Calculators that are considered "available" for large size orders? Like Freight ones or something?