Browse files

Fix for "Ready To Ship" in Canada Post API

  • Loading branch information...
1 parent 2ec0b19 commit be56eaea6df2c72d0ffa31457f4b4fdd95a7d1ad @jbourassa jbourassa committed with j15e Jun 26, 2012
Showing with 50 additions and 0 deletions.
  1. +47 −0 lib/spree/active_shipping/canada_post_override.rb
  2. +3 −0 lib/spree_active_shipping/engine.rb
View
47 lib/spree/active_shipping/canada_post_override.rb
@@ -0,0 +1,47 @@
+module Spree
+ module ActiveShipping
+ # Override to fix a bug with readToShip : sending ready_to_ship: nil will
+ # add a <readyToShip/> tag, which means true. The solution is to not
+ # include the tag.
+ module CanadaPostOverride
+ def self.included(base)
+
+ base.class_eval do
+
+ # <!-- List of items in the shopping -->
+ # <!-- cart -->
+ # <!-- Each item is defined by : -->
+ # <!-- - quantity (mandatory) -->
+ # <!-- - size (mandatory) -->
+ # <!-- - weight (mandatory) -->
+ # <!-- - description (mandatory) -->
+ # <!-- - ready to ship (optional) -->
+
+ def build_line_items(line_items)
+ xml_line_items = XmlNode.new('lineItems') do |line_items_node|
+
+ line_items.each do |line_item|
+
+ line_items_node << XmlNode.new('item') do |item|
+ item << XmlNode.new('quantity', 1)
+ item << XmlNode.new('weight', line_item.kilograms)
+ item << XmlNode.new('length', line_item.cm(:length).to_s)
+ item << XmlNode.new('width', line_item.cm(:width).to_s)
+ item << XmlNode.new('height', line_item.cm(:height).to_s)
+ item << XmlNode.new('description', line_item.options[:description] || ' ')
+ # Only this line got changed
+ item << XmlNode.new('readyToShip') if line_item.options[:ready_to_ship]
+
+ # By setting the 'readyToShip' tag to true, Sell Online will not pack this item in the boxes defined in the merchant profile.
+ end
+ end
+ end
+
+ xml_line_items
+ end
+ end
+ end
+ end
+ end
+end
+
View
3 lib/spree_active_shipping/engine.rb
@@ -19,6 +19,9 @@ def self.activate
#Only required until following active_shipping commit is merged (add negotiated rates).
#http://github.com/BDQ/active_shipping/commit/2f2560d53aa7264383e5a35deb7264db60eb405a
ActiveMerchant::Shipping::UPS.send(:include, Spree::ActiveShipping::UpsOverride)
+
+ # Fix Canada Post "Ready to ship" package
+ ActiveMerchant::Shipping::CanadaPost.send(:include, Spree::ActiveShipping::CanadaPostOverride)
end
config.autoload_paths += %W(#{config.root}/lib)

0 comments on commit be56eae

Please sign in to comment.