Skip to content

Should AmazonMerchantShipment::parseXML really set ShipmentId like this? #176

@mehgcap

Description

@mehgcap

Hello,
I've found what might be a bug, or might just be something I am not fully understanding. I'm working with the AmazonMerchantShipment and AmazonMerchantShipmentCreator classes, trying to get a ship response (including label) from Amazon. I can set everything in the Creator instance, but when I try to call AmazonMerchantShipmentCreator::getShipment(), an error is logged that "Shipment ID must be set in order to fetch it!"

After some poking around the two classes, here's my tentative bug report.

When AmazonMerchantShipmentCreator::getShipment() is called, it gets an XML response which it passes to the class's parseXML function. In that function, the constructor of AmazonMerchantShipment gets the XML as AmazonMerchantShipmentCreator makes a new AmazonMerchantShipment instance. In that constructor, AmazonMerchantShipment calls its own parseXML function, which assigns things from the given XML to the class's $data array. This includes setting $data["ShipmentId"] to the shipment ID in the xml. In other words, when AmazonMerchantShipmentCreator::getShipment() is called, it basically gives XML to AmazonMerchantShipment's constructor, which sets AmazonMerchantShipment::data to the values it needs from that XML. Among these values is ShipmentId.

However, in AmazonMerchantShipment::fetchShipment(), a check is performed to see whether AmazonMerchantShipment::options has a key called ShipmentId. Finally we arrive at the bug: AmazonMerchantShipment::parseXML only sets the ShipmentId in the data array, not the options array. Thus, the check for that ID in the options array always fails, even though the XML that made the instance had the ID set.

Put simply, when given valid XML from AmazonMerchantShipmentCreator, AmazonMerchantShipment sets its data array with ShipmentID, but never sets its options array with that same ID. Then, when it tries to use the ID, it checks in its options array--the array that never got the ID placed in it. It seems like AmazonMerchantShipment::parseXML should set both arrays with a value for ShipmentID to fix this problem. That, or every check should inspect both options and data.

Again, I may be mistaken here. I'm not an expert, and I haven't gone through the entire library. Still, when I call AmazonMerchantShipment::fetchShipment() with the stock code, I get the warning that the shipment ID isn't set. If I add my fix, the warning goes away. Of course, I don't have a label yet, so I might be completely off base here. :) Still, I thought I would bring this up in case it really is a bug. Thanks for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions