magepal / magento2-custom-shipping-rate

Create your own Custom Shipping rates for admin order or a predefined sets of shipping methods for frontend customers.
http://www.magepal.com
93 stars 32 forks source link

'Unable to unserialize value.' Error after upgrading to latest version in 2.2.4 #7

Closed im-jc closed 6 years ago

im-jc commented 6 years ago

Magento version #: 2.2.4

Edition (EE, CE, OS, etc): CE

Expected behavior: Extension should work properly and should not give error when i go to MAGENTO ADMIN -> STORES -> CONFIGURATION ->SALES -> SHIPPING METHODS

Actual behavior: It gives following error when i go to MAGENTO ADMIN -> STORES -> CONFIGURATION ->SALES -> SHIPPING METHODS

https://prnt.sc/jowf9p

Steps to reproduce:

  1. Upgrade magento 2.1.7 to 2.2.4
  2. Go to MAGENTO ADMIN -> STORES -> CONFIGURATION ->SALES -> SHIPPING METHODS

Preconditions

Magento 2.2.4 PHP Version 7.0.28 MySQL 5.0.12

im-jc commented 6 years ago

Hi! I got the solution. To fix the issue following file needs to be override. \vendor\magento\framework\Serialize\Serializer\json.php

Extension can be created to do this. Extension is attached. Fixunserialization.zip

im-jc commented 6 years ago

Issue is fixed by above solution.

srenon commented 6 years ago

@im-jc .. I'm not aware of any current issue, Magento 2.2.x/2.1.9 change from Serializer data to JSON which was address in https://github.com/magepal/magento2-custom-shipping-rate/releases/tag/1.3.0

So if you are using v1.4.0 you should not have any issue.

im-jc commented 6 years ago

Hi! Thanks for response.

I am have upgraded magento version from 2.1.7 to 2.2.4.

In magento 2.1.7 i ahve installed 'magepal/magento2-customshippingrate' version 1.3.2 and it was working perfactly. But after upgrade it stated giving an error as posted in issue defination. So i have upgraded extension version to 1.4.0 and still got an error. It was fixed by overriding the file i have mentioned in solution.

Thank you for your time! :)

srenon commented 6 years ago

This seems to be a one-off issue caused by the sorting functionality.

Try disabling the Fixunserialization module and see if it still work. The issue should get fixed after the first shipping rate save and convert it to JSON

im-jc commented 6 years ago

Yes it is working after disabling the Fixunserialization module. and yes it may be caused by the sorting functionality.

srenon commented 6 years ago

When I originally wrote this after Magento changing the way they storing values (JSON instead of serializing array) Serialize\Serializer\json.php was still there for backward compatibility but eventually removed got removed. So they why you ran into this issue.

Couple ways to fix this:

  1. delete in core config data the value for shipping_typeand recreate them (not ideal)
  2. Add the module that you bulld (@im-jc thanks for figuring it out). The code only needs to run once.
  3. copy the value from the db then decode and re-encode using JSON by run json_encode(unserialize(shipping_type text here)) and copy the update to shipping_type row and save.

I should have done something like this instead app/code/Magento/Braintree/Setup/UpgradeData.php

    private function convertSerializedDataToJson(ModuleDataSetupInterface $setup)
    {
        $fieldDataConverter = $this->fieldDataConverterFactory->create(
            \Magento\Framework\DB\DataConverter\SerializedToJson::class
        );

        $queryModifier = $this->queryModifierFactory->create(
            'in',
            [
                'values' => [
                    'path' => ['payment/braintree/countrycreditcard']
                ]
            ]
        );

        $fieldDataConverter->convert(
            $setup->getConnection(),
            $setup->getTable('core_config_data'),
            'config_id',
            'value',
            $queryModifier
        );
    }