Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add order note if present for Shipwire fulfillments #15

Merged
merged 1 commit into from

3 participants

@BlakeMesdag
Collaborator

Changes

This adds a note to the Order xml as a CDATA element when provided with a note in the options hash. Has tests for when options[:note] is and isn't set.

Review

@Soleone @jduff

@Soleone
Collaborator

How would the XML look? The CDATA block needs to be inside of a new element I think is what they said.

lib/active_fulfillment/fulfillment/services/shipwire.rb
@@ -133,6 +133,7 @@ def add_order(xml, order_id, shipping_address, line_items, options)
Array(line_items).each_with_index do |line_item, index|
add_item(xml, line_item, index)
end
+ xml.cdata! options[:note] unless options[:note].blank?
@Soleone Collaborator
Soleone added a note

I try to avoid negations as much as possible, maybe change it to: if options[:note].present?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@BlakeMesdag
Collaborator

Modified it to add a Note node with a CDATA element. Extra XML will look like this:

<Note>
  <![CDATA[Some Order Note Content]]>
</Note>

It would have just been a <![CDATA[...]]> at the end of the Order node before.

@jduff
Admin

I think what you have now is what they are looking for, is there any way to send them a request and verify that this is what they are expecting?

@jduff
Admin

lgtm, would be nice to have verification on their end..even just spit out some xml and send them an email.

@BlakeMesdag
Collaborator

I sent a sample over to Shipwire. I'll wait to see what they think and then merge this in when they get back to me.

@Soleone
Collaborator

:+1:

@BlakeMesdag BlakeMesdag merged commit 113d3e7 into from
@kevinhughes27 kevinhughes27 deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  lib/active_fulfillment/fulfillment/services/shipwire.rb
@@ -133,6 +133,9 @@ def add_order(xml, order_id, shipping_address, line_items, options)
Array(line_items).each_with_index do |line_item, index|
add_item(xml, line_item, index)
end
+ xml.tag! 'Note' do
+ xml.cdata! options[:note] unless options[:note].blank?
+ end
end
end
View
13 test/unit/services/shipwire_test.rb
@@ -157,6 +157,19 @@ def test_company_name_in_request
assert_equal 'MyCorp', company_node.text
end
+ def test_order_excludes_note_by_default
+ xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
+ note_node = REXML::XPath.first(xml, "//Note").cdatas.first
+ assert_nil note_node
+ end
+
+ def test_order_includes_note_when_present
+ @options[:note] = "A test note"
+ xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
+ note_node = REXML::XPath.first(xml, "//Note").cdatas.first
+ assert_equal "A test note", note_node.to_s
+ end
+
private
def successful_empty_tracking_response
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<TrackingUpdateResponse><Status>Test</Status><TotalOrders></TotalOrders><TotalShippedOrders></TotalShippedOrders><TotalProducts></TotalProducts><Bookmark></Bookmark></TrackingUpdateResponse>"
Something went wrong with that request. Please try again.