Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CarriergroupShippingDetails json decode syntax error #7

Closed
cheelahim opened this issue Jun 2, 2016 · 2 comments
Closed

CarriergroupShippingDetails json decode syntax error #7

cheelahim opened this issue Jun 2, 2016 · 2 comments

Comments

@cheelahim
Copy link

Hello. There is an issue with decoding empty Carriergroup Shipping Details inside the ShippingInformationPlugin::saveCarrierGroupInformation() on PHP7 (Magento 2.0.7 EE) when found rate has 'carriergroup_shipping_details' key set to null.

  1. ShipperHQ\Shipper\Helper\Data::decodeShippingDetails() utilizes Magento Json helper which uses Zend_Json::decode() implementation under the hood.
$shipDetails = $this->shipperDataHelper->decodeShippingDetails($foundRate->getCarriergroupShippingDetails());

In case php json extension is installed on the host system, json_decode() will be used to decode the shipping details. But, in PHP7 json_decode() will produce a syntax error upon empty string decoding.

This issue could be temporary mitigated by setting Zend_Json::$useBuiltinEncoderDecoder to true from outside the method in order to avoid using json_decode(). But this is not a best way to address the issue.

  1. Even if you would manage to decode the shipping details by utilizing Zend_Json::$useBuiltinEncoderDecoder flag you will get NULL which will break the array key check, producing the error: "Warning: array_key_exists() expects parameter 2 to be array, null given..."
if(array_key_exists('carrierGroupId', $shipDetails)) {
    $arrayofShipDetails = array();
    $arrayofShipDetails[] = $shipDetails;
    $shipDetails = $arrayofShipDetails;
    $encodedShipDetails = $this->shipperDataHelper->encodeShippingDetails($arrayofShipDetails);
}
else {
    $encodedShipDetails = $this->shipperDataHelper->encodeShippingDetails($shipDetails);
 }
@wsagen
Copy link
Contributor

wsagen commented Jun 2, 2016

We've raised internally and have a fix coming out this week to resolve. Added additional checks to prevent decoding when value is null

@wsagen
Copy link
Contributor

wsagen commented Jun 7, 2016

This is included in release version 20.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants