Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure that all tracking numbers for a fulfillment are retrieved

In order to not fully hose the API, we return all tracking numbers
as a comma separated string.  This should fix any issues related with
having an order be fulfilled via multiple fulfillment centers (hence
the requirement for different tracking numbers)
  • Loading branch information...
commit 4383e43e7bf6eef68cb09bc8634d8e5f4136b987 1 parent 113d3e7
Christopher Saunders csaunders authored
14 lib/active_fulfillment/fulfillment/services/amazon_mws.rb
View
@@ -227,11 +227,15 @@ def parse_response(service, op, xml)
def parse_tracking_response(document)
response = {}
response[:tracking_numbers] = {}
-
- tracking_node = REXML::XPath.first(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
- if tracking_node
- id_node = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId")
- response[:tracking_numbers][id_node.text.strip] = tracking_node.text.strip
+ order_id = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId").text.strip
+ tracking_numbers = REXML::XPath.match(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
+
+ if tracking_numbers.present?
+ response[:tracking_numbers][order_id] = ''
+ tracking_numbers.each do |tracking_number|
+ response[:tracking_numbers][order_id] += ',' if response[:tracking_numbers][order_id].length > 0
+ response[:tracking_numbers][order_id] += tracking_number.text.strip
+ end
end
response[:response_status] = SUCCESS
121 test/fixtures/xml/amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers.xml
View
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+<GetFulfillmentOrderResponse
+ xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
+ <GetFulfillmentOrderResult>
+ <FulfillmentOrderItem>
+ <member>
+ <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
+ <GiftMessage>test_giftwrap_message</GiftMessage>
+ <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
+ </SellerFulfillmentOrderItemId>
+ <EstimatedShipDateTime>2008-03-08T07:07:53Z
+ </EstimatedShipDateTime>
+ <DisplayableComment>test_displayable_comment</DisplayableComment>
+ <OrderItemDisposition>Sellable</OrderItemDisposition>
+ <UnfulfillableQuantity>0</UnfulfillableQuantity>
+ <CancelledQuantity>1</CancelledQuantity>
+ <Quantity>5</Quantity>
+ <EstimatedArrivalDateTime>2008-03-08T08:07:53Z
+ </EstimatedArrivalDateTime>
+ </member>
+ <member>
+ <SellerSKU>ssof_dev_drt_keep_this_afn_always</SellerSKU>
+ <GiftMessage>test_giftwrap_message</GiftMessage>
+ <SellerFulfillmentOrderItemId>test_merchant_order_item_id_1
+ </SellerFulfillmentOrderItemId>
+ <EstimatedShipDateTime>2008-03-09T07:07:53Z
+ </EstimatedShipDateTime>
+ <DisplayableComment>test_displayable_comment
+ </DisplayableComment>
+ <OrderItemDisposition>Sellable</OrderItemDisposition>
+ <UnfulfillableQuantity>2</UnfulfillableQuantity>
+ <CancelledQuantity>1</CancelledQuantity>
+ <Quantity>5</Quantity>
+ <EstimatedArrivalDateTime>2008-03-09T08:07:53Z
+ </EstimatedArrivalDateTime>
+ </member>
+ </FulfillmentOrderItem>
+ <FulfillmentOrder>
+ <ShippingSpeedCategory>Standard</ShippingSpeedCategory>
+ <NotificationEmailList>
+ <member>o8c2EXAMPLsfr7o@marketplace.amazon.com</member>
+ </NotificationEmailList>
+ <StatusUpdatedDateTime>2006-09-28T23:48:48Z
+ </StatusUpdatedDateTime>
+ <SellerFulfillmentOrderId>extern_id_1154539615776
+ </SellerFulfillmentOrderId>
+ <DestinationAddress>
+ <PostalCode>98101</PostalCode>
+ <PhoneNumber>206-555-1928</PhoneNumber>
+ <Name>Greg Miller</Name>
+ <CountryCode>US</CountryCode>
+ <Line1>123 Some St.</Line1>
+ <StateOrProvinceCode>WA</StateOrProvinceCode>
+ <City>Seattle</City>
+ <Line2>Apt. 321</Line2>
+ </DestinationAddress>
+ <FulfillmentMethod>Consumer</FulfillmentMethod>
+ <DisplayableOrderDateTime>2006-08-02T17:26:56Z
+ </DisplayableOrderDateTime>
+ <FulfillmentPolicy>FillOrKill</FulfillmentPolicy>
+ <ReceivedDateTime>2006-08-02T17:26:56Z</ReceivedDateTime>
+ <DisplayableOrderId>test_displayable_id</DisplayableOrderId>
+ <DisplayableOrderComment>Sample comment.
+ </DisplayableOrderComment>
+ <FulfillmentOrderStatus>PROCESSING</FulfillmentOrderStatus>
+ </FulfillmentOrder>
+ <FulfillmentShipment>
+ <member>
+ <FulfillmentShipmentStatus>SHIPPED</FulfillmentShipmentStatus>
+ <FulfillmentShipmentItem>
+ <member>
+ <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
+ <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
+ </SellerFulfillmentOrderItemId>
+ <Quantity>2</Quantity>
+ <PackageNumber>0</PackageNumber>
+ </member>
+ </FulfillmentShipmentItem>
+ <AmazonShipmentId>DnMDLWJWN</AmazonShipmentId>
+ <ShippingDateTime>2006-08-04T07:00:00Z</ShippingDateTime>
+ <FulfillmentShipmentPackage>
+ <member>
+ <TrackingNumber>93YY00</TrackingNumber>
+ <CarrierCode>UPS</CarrierCode>
+ <PackageNumber>1</PackageNumber>
+ </member>
+ </FulfillmentShipmentPackage>
+ <FulfillmentCenterId>RNO1</FulfillmentCenterId>
+ <EstimatedArrivalDateTime>2006-08-12T07:00:00Z
+ </EstimatedArrivalDateTime>
+ </member>
+ <member>
+ <FulfillmentShipmentStatus>SHIPPED</FulfillmentShipmentStatus>
+ <FulfillmentShipmentItem>
+ <member>
+ <SellerSKU>ssof_dev_drt_afn_item</SellerSKU>
+ <SellerFulfillmentOrderItemId>test_merchant_order_item_id_2
+ </SellerFulfillmentOrderItemId>
+ <Quantity>1</Quantity>
+ <PackageNumber>1</PackageNumber>
+ </member>
+ </FulfillmentShipmentItem>
+ <AmazonShipmentId>DKMKLXJmN</AmazonShipmentId>
+ <ShippingDateTime>2006-08-03T07:00:00Z</ShippingDateTime>
+ <FulfillmentShipmentPackage>
+ <member>
+ <TrackingNumber>93ZZ00</TrackingNumber>
+ <CarrierCode>UPS</CarrierCode>
+ <PackageNumber>1</PackageNumber>
+ </member>
+ </FulfillmentShipmentPackage>
+ <FulfillmentCenterId>TST1</FulfillmentCenterId>
+ <EstimatedArrivalDateTime>2006-08-12T07:00:00Z
+ </EstimatedArrivalDateTime>
+ </member>
+ </FulfillmentShipment>
+ </GetFulfillmentOrderResult>
+ <ResponseMetadata>
+ <RequestId>5e5e5694-8e76-11df-929f-87c80302f8f6</RequestId>
+ </ResponseMetadata>
+</GetFulfillmentOrderResponse>
9 test/unit/services/amazon_mws_test.rb
View
@@ -221,6 +221,15 @@ def test_fetch_tracking_numbers
assert_nil response.tracking_numbers['extern_id_1154539615777']
end
+
+ def test_fetch_multiple_tracking_numbers
+ @service.expects(:ssl_post).returns(xml_fixture('amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers'))
+
+ response = @service.fetch_tracking_numbers(['extern_id_1154539615776'])
+ assert response.success?
+ assert_equal '93YY00,93ZZ00', response.tracking_numbers['extern_id_1154539615776']
+ end
+
def test_that_generated_requests_do_not_double_escape_spaces
fulfillment_request = @service.send(:build_fulfillment_request, "12345", @address, @line_items, @options)
result = @service.build_full_query(:post, URI.parse("http://example.com/someservice/2011"), fulfillment_request)
Please sign in to comment.
Something went wrong with that request. Please try again.