postnl / postnl-magento2

This is the official Magento 2 extension for the logistics company PostNL. Add shipping options and parcelshops to your checkout. Create labels with track and trace functionality from the backend.
58 stars 60 forks source link

[BUG] 500 error for postnl/deliveryoptions/save/ action #273

Closed boris1988 closed 2 years ago

boris1988 commented 2 years ago

Sometimes I got a 500 error for action postnl/deliveryoptions/save/

To Reproduce Steps to reproduce the behavior:

  1. Go to Details Product Page and add product to the cart
  2. Go to the Checkout page and fill shipping information
  3. Select the Shipping via PostNL method
  4. Select Pick-up point from the list without House Nr. Ext. Screenshot from 2021-10-13 14-56-27

Expected result postnl/deliveryoptions/save/ should return 200 status and pick up point saved

Actual result postnl/deliveryoptions/save/ return 500 status with the error Exception #0 (Exception): Notice: Array to string conversion ... Screenshot from 2021-10-13 14-57-26

Workaround I got an error only for pick-up points without House Nr. Ext. The issue was caused by vendor/tig/postnl-magento2/Helper/DeliveryOptions/PickupAddress.php::164 and vendor/magento/module-customer/Model/Address/AbstractAddress.php::_implodeArrayValues. According to PickupAddress.php we can get NULL in the last element in Street Array. NULL is not a scalar value, AbstractAddress.php::_implodeArrayValues return array instead of string. Solution: change the default value to empty string instead of NULL Screenshot from 2021-10-13 15-05-31

Please complete the following information

tig-jeffreybranderhorst commented 2 years ago

Hi @boris1988 ,

Thank you for this perfect filled out template! We will investigate this further, thank you for the submission!

Have a great day. Jeffrey

tig-jeffreybranderhorst commented 2 years ago

Hi @boris1988 ,

Do you have an example address for us where we can test with? Because I cannot reproduce it until now. So I would like to test with address where this happens with.

Have a great day, Jeffrey

boris1988 commented 2 years ago

Hi @tig-jeffreybranderhorst I cant get pick up points today But you can check the address on a screenshot Screenshot from 2021-10-14 10-19-28 I don't know why but today pickup points are not available Regards, Boris

tig-jeffreybranderhorst commented 2 years ago

Hi Boris,

Just tested and the pickup points should still work there is no server-side error so far we can see, we also get responses when we test. PostNL does the support themselves and if needed they ask us for more info and to help them, with that said could you please contact PostNL about these 2 issues, so we can fix it for you, because it seems I cannot reproduce it on our test environments. You can contact PostNL at digitaleklantsupport@postnl.nl

Have a great day, Jeffrey

boris1988 commented 2 years ago

HI @tig-jeffreybranderhorst I have reproduced it again Arent Krijtsstraat 15 DIEMEN throw an error because we don't have House Nr. Ext. Screenshot from 2021-10-14 11-05-22

Diemerplein 34 -36 Diemen works fine. House Nr. Ext. -36 Screenshot from 2021-10-14 11-08-21 Regards, Boris

tig-jeffreybranderhorst commented 2 years ago

Hey @boris1988 ,

Maybe it is a combination with a other extension on your site. Because we don't get this error: image

It is possible to maybe update the PostNL extension on a staging?

Have a great day, Jeffrey

boris1988 commented 2 years ago

PHP Version 7.4.19 magento 2.4.3

I will ask about access to staging Also, I can try to update Postnl to the latest one 1.9.9 Could you pls show the function vendor/magento/module-customer/Model/Address/AbstractAddress.php::_implodeArrayValues


    {
        if (is_array($value)) {
            if (!count($value)) {
                return '';
            }

            $isScalar = true;
            foreach ($value as $val) {
                if (!is_scalar($val)) {
                    $isScalar = false;
                    break;
                }
            }
            if ($isScalar) {
                $value = trim(implode("\n", $value));
            }
        }
        return $value;
    }
tig-jeffreybranderhorst commented 2 years ago

Hi @boris1988 ,

I'm testing on the same Magento version, so this will be the same. This is possibly fixed in the newest PostNL version therefore you can test that on a staging. If that is not it, it would need to be investigated and for that I would like to ask you to contact PostNL, you can contact them on: digitaleklantsupport@postnl.nl

The function: `if (is_array($value)) { if (!count($value)) { return ''; }

        $isScalar = true;
        foreach ($value as $val) {
            if (!is_scalar($val)) {
                $isScalar = false;
                break;
            }
        }
        if ($isScalar) {
            $value = trim(implode("\n", $value));
        }
    }
    return $value;
}`

Have a great day, Jeffrey

boris1988 commented 2 years ago

Thanks for the update

boris1988 commented 2 years ago

Hi @tig-jeffreybranderhorst Issue solved in the newest version Thanks