does it make sense to override build_packages method inside Stock Coordinator

35 views
Skip to first unread message

Nima Shariatian

unread,
Sep 24, 2014, 6:09:28 PM9/24/14
to spree...@googlegroups.com
hi guys,

trying to get rid of the annoying split shipping charge for our customers
they are getting charged twice for shipping since some of their orders might come from multiple stock locations
when choosing a "flat rate' shipping

so if the shipping charge is 5$ but they have 1 item from one stock location and another from a different one
they are charged 10$ for shipping 

does it make sense to override the build_packages methods to return only one package to avoid the double charge?

has anyone done this properly?


here is the method i am trying to override.
Spree
  Stock
     Coordinator
def build_packages(packages = Array.new)
        StockLocation.active.each do |stock_location|
          next unless stock_location.stock_items.where(:variant_id => order.line_items.pluck(:variant_id)).exists?

          packer = build_packer(stock_location, order)
          packages += packer.packages
        end
        packages
 end
    end
  end
end

Peter Berkenbosch

unread,
Sep 29, 2014, 5:00:51 AM9/29/14
to spree...@googlegroups.com
Not sure if that's the best solution Nima, you would still need 2 packages right? The shipping calculator should be the place to fix this I think. Every shipment will have the same cost, but you could decorate that to check if there is already a shipping adjustment on the order and return 0 if that's the case.

Hope this helps.
Peter.
--

Peter Berkenbosch
Spree Commerce, Inc.

br...@newdistrict.ca

unread,
Aug 2, 2017, 3:25:30 AM8/2/17
to Spree
I know it's been a couple years, but I'm running into this exact situation, and was hoping to see someone update with the recommended workflow.

I have been trying to inspect the order's shipments every time "compute" is called in my custom calculator, but not having much luck.  In my case, I've got an order with two shipments.  Each time "compute" is called, i have a binding.pry breakpoint set.  I am inspecting the database and local variables and not finding anything useful.  Only after both compute calls have finished can i see the adjustments appear in the database.

If someone has a recipe to follow to achieve this that would be very helpful

Brad
Reply all
Reply to author
Forward
0 new messages