module-shipper icon indicating copy to clipboard operation
module-shipper copied to clipboard

Address formatting issue in request when street address is empty

Open lstellway opened this issue 8 years ago • 4 comments

I was receiving issues of a "malformatted" request error when requesting shipping methods using only the postal code from the following method:

\ShipperHQ\Shipper\Model\Carrier\Shipper::setRequest()

The error I received:

Could not read document: Can not deserialize instance of java.lang.String out of START_ARRAY token

The error while in debug mode:

Malformed Request. The request was not formed correctly.

I was able to trace the issue down to the destination address being passed in the request. The issue was that the destination street passed from the quote address was an empty array.

To mediate the issue, I created an event to observe the shipperhq_carrier_set_request event and turn the destination street into a string.

public function execute(Observer $observer)
{
    $request = $observer->getData('request');
    if (is_array($request->getDestStreet())) {
        $request->setDestStreet(implode(' ', $request->getDestStreet()));
    }
}

The observer works, but not sure if you have a better idea?

Thanks!

lstellway avatar Dec 15 '17 01:12 lstellway

Hi - thanks for the contribution. We are currently looking at this. Could you let me know what version of Magento you are running?

wsagen avatar Dec 19 '17 13:12 wsagen

I am currently on Magento 2.1.9

lstellway avatar Dec 19 '17 19:12 lstellway

Hi - This was addressed in the latest version of the extension, 20.12.0. Updating to that version should resolve.

wsajason avatar Jan 03 '18 10:01 wsajason

Great, thank you!

lstellway avatar Jan 04 '18 18:01 lstellway