0

Using Spree 2.0.5, I am trying to offer USPS first class parcel service on packages less than 13 ounces, and priority mail on packages >= 13 ounces.

I found this, possibly dated, solution http://madebydna.com/all/code/2010/05/26/setting-up-usps-shipping-with-spree.html, which, when pasted verbatim, does properly limit the availability of the first class parcel method. However, making seemingly obvious adjustments doesn't impact priority mail.

The following code apparently isn't even getting called. The original available? method isn't getting overwritten and the the priority mail shipping method is available regardless of the weight.

#app/models/spree/calculator/hideprioritymail.rb
class Calculator::Usps::PriorityMail < Calculator::Usps::Base
  def self.description
    "USPS Priority Mail"
  end

  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
    weight >= 13 ? false : true
  end
end
Tony Busch
  • 17
  • 3
  • just a side note: `weight >= 13` already returns a boolean – phoet Oct 16 '13 at 19:46
  • i don't know anything about spree, but maybe this blogpost might help you debug the problem by yourself: http://nofail.de/2013/10/debugging-rails-applications-in-development/ – phoet Oct 16 '13 at 19:47
  • Just a guess, but shouldn't you override [that class](https://github.com/spree/spree_active_shipping/blob/master/app/models/spree/calculator/shipping/usps/priority_mail.rb#L4)? – zrl3dx Oct 17 '13 at 08:24

0 Answers0