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

checkout: unserialize() Exception #134

Closed
CarelNantcho opened this issue Dec 5, 2017 · 6 comments
Closed

checkout: unserialize() Exception #134

CarelNantcho opened this issue Dec 5, 2017 · 6 comments

Comments

@CarelNantcho
Copy link

CarelNantcho commented Dec 5, 2017

Magento 2.1.7
PHP 5.6

  • Payone is just installed, not set up.
  • A product is added to the cart.
  • Click on "view all articles"

Then:

1 exception(s):
Exception #0 (Exception): Notice: unserialize(): Error at offset 0 of 751 bytes in /xxx/xxx/xxx/vendor/payone-gmbh/magento-2/Helper/Base.php on line 139

Exception #0 (Exception): Notice: unserialize(): Error at offset 0 of 751 bytes in /xxx/xxx/xxx/vendor/payone-gmbh/magento-2/Helper/Base.php on line 139
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8, 'unserialize(): ...', '/xxx/xxx/xxx/...', 139, Array)
#1 /xxx/xxx/xxx/vendor/payone-gmbh/magento-2/Helper/Base.php(139): unserialize('{"Number_type":...')

This is the original function unserialize():

/**
 * @param  string $sValue
 * @return mixed
 */
public function unserialize($sValue) {	
    if (version_compare($this->shopHelper->getMagentoVersion(), '2.2.0', '>=')) { // Magento 2.2.0 and above
        return json_decode($sValue, true);
    }
    return unserialize($sValue);
}

The Problem i think is, you are expecting here that all Magento2 versions under 2.2.0 do not deal here with json objects. But the version i am using can not deal with the returned serialized version because it is expecting here a json object.

i updated the if condition
if (version_compare($this->shopHelper->getMagentoVersion(), '2.2.0', '>='))
to
(version_compare($this->shopHelper->getMagentoVersion(), '2.1.7', '>='))
and it is works.

I have to see now, if i will get another errors because of the wrong version or wrong returned data type after i configurated Payone.

I am waiting for your feedback.

Regards.

@fjbender fjbender added bug and removed bug labels Dec 6, 2017
@fjbender
Copy link
Contributor

fjbender commented Dec 6, 2017

At first I thought this was a bug. But I can't really reproduce it in a freshly installed Mage 2.1.7, mainly because I can't find the "Show all articles" link you described.

As a background, why we introduced this change: Mage 2.2 doesn't allow serialized values anymore and prefers json, while we used serialized values in our plugin prior to Mage 2.2 compatibility. However, I'm not quite sure why our module is getting active in the stage you're describing. Do you maybe have a complete stacktrace?

@CarelNantcho
Copy link
Author

Sorry, with "Show all articles" i mean checkout/cart.

I sent you a complete stacktrace in a private mail (me@fbender.de)

Thank you

@nixn
Copy link

nixn commented Jan 12, 2018

I have that issue too. A fresh completely untouched installation of Payone 2.0.2 (dc9ff4e) on Magento 2.1.10, PHP 7.0. Added an article to the cart and called /checkout/cart.

The stack trace is as follows:

Exception #0 (Exception): Notice: unserialize(): Error at offset 0 of 751 bytes in /var/www/magento/vendor/payone-gmbh/magento-2/Helper/Base.php on line 139
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8, 'unserialize(): ...', '/var/www/magent...', 139, Array)
#1 /var/www/magento/vendor/payone-gmbh/magento-2/Helper/Base.php(139): unserialize('{"Number_type":...')
#2 /var/www/magento/vendor/payone-gmbh/magento-2/Helper/HostedIframe.php(84): Payone\Core\Helper\Base->unserialize('{"Number_type":...')
#3 /var/www/magento/vendor/payone-gmbh/magento-2/Helper/HostedIframe.php(165): Payone\Core\Helper\HostedIframe->getHostedParams()
#4 /var/www/magento/vendor/payone-gmbh/magento-2/Model/ConfigProvider.php(195): Payone\Core\Helper\HostedIframe->getHostedFieldConfig()
#5 /var/www/magento/vendor/payone-gmbh/magento-2/Model/ConfigProvider.php(234): Payone\Core\Model\ConfigProvider->getPayoneConfig()
#6 /var/www/magento/vendor/magento/module-checkout/Model/CompositeConfigProvider.php(32): Payone\Core\Model\ConfigProvider->getConfig()
#7 /var/www/magento/vendor/magento/module-checkout/Block/Cart/Shipping.php(54): Magento\Checkout\Model\CompositeConfigProvider->getConfig()
#8 /var/www/magento/vendor/magento/module-checkout/view/frontend/templates/cart/shipping.phtml(28): Magento\Checkout\Block\Cart\Shipping->getCheckoutConfig()
#9 /var/www/magento/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/magent...')
#10 /var/www/magento/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Checkout\Block\Cart\Shipping), '/var/www/magent...', Array)
#11 /var/www/magento/vendor/magento/framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/var/www/magent...')
#12 /var/www/magento/vendor/magento/framework/View/Element/AbstractBlock.php(659): Magento\Framework\View\Element\Template->_toHtml()
#13 /var/www/magento/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#14 /var/www/magento/vendor/magento/framework/View/Layout.php(518): Magento\Framework\View\Layout->_renderBlock('checkout.cart.s...')
#15 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.s...')
#16 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('checkout.cart.s...')
#17 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('checkout.cart.s...', true)
#18 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('checkout.cart.s...')
#19 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('cart.summary')
#20 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('cart.summary')
#21 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('cart.summary')
#22 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('cart.summary', true)
#23 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('cart.summary')
#24 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('checkout.cart.c...')
#25 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.c...')
#26 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('checkout.cart.c...')
#27 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('checkout.cart.c...', true)
#28 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('checkout.cart.c...')
#29 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('checkout.cart.i...')
#30 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart.i...')
#31 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('checkout.cart.i...')
#32 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('checkout.cart.i...', true)
#33 /var/www/magento/vendor/magento/framework/View/Element/AbstractBlock.php(499): Magento\Framework\View\Layout\Interceptor->renderElement('checkout.cart.i...', true)
#34 /var/www/magento/vendor/magento/module-checkout/view/frontend/templates/cart.phtml(15): Magento\Framework\View\Element\AbstractBlock->getChildHtml('with-items')
#35 /var/www/magento/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/magent...')
#36 /var/www/magento/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Checkout\Block\Cart), '/var/www/magent...', Array)
#37 /var/www/magento/vendor/magento/framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/var/www/magent...')
#38 /var/www/magento/vendor/magento/framework/View/Element/AbstractBlock.php(659): Magento\Framework\View\Element\Template->_toHtml()
#39 /var/www/magento/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#40 /var/www/magento/vendor/magento/framework/View/Layout.php(518): Magento\Framework\View\Layout->_renderBlock('checkout.cart')
#41 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('checkout.cart')
#42 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('checkout.cart')
#43 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('checkout.cart', true)
#44 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('checkout.cart')
#45 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('content')
#46 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('content')
#47 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('content')
#48 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('content', true)
#49 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('content')
#50 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main')
#51 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main')
#52 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main')
#53 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main', true)
#54 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main')
#55 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('columns')
#56 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#57 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('columns')
#58 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('columns', true)
#59 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('columns')
#60 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main.content')
#61 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#62 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main.content')
#63 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main.content', true)
#64 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main.content')
#65 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('page.wrapper')
#66 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#67 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper')
#68 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('page.wrapper', true)
#69 /var/www/magento/vendor/magento/framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper')
#70 /var/www/magento/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('root')
#71 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('root')
#72 /var/www/magento/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root')
#73 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('root', true)
#74 /var/www/magento/vendor/magento/framework/View/Layout.php(938): Magento\Framework\View\Layout\Interceptor->renderElement('root')
#75 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Framework\View\Layout->getOutput()
#76 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#77 /var/www/magento/vendor/magento/framework/View/Result/Page.php(243): Magento\Framework\View\Layout\Interceptor->getOutput()
#78 /var/www/magento/vendor/magento/framework/View/Result/Layout.php(164): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#79 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#80 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#81 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-varnish-...')
#82 /var/www/magento/vendor/magento/module-page-cache/Model/Controller/Result/VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#83 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#84 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-builtin-...')
#85 /var/www/magento/vendor/magento/module-page-cache/Model/Controller/Result/BuiltinPlugin.php(67): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#86 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(142): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#87 /var/www/magento/var/generation/Magento/Framework/View/Result/Page/Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#88 /var/www/magento/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#89 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#90 /var/www/magento/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#91 {main}

Tracing with xdebug led me to some more information: the full value in #1 is {"Number_type":"tel","Number_count":"30","Number_max":"16","Number_iframe":"standard","Number_style":"standard","CVC_type":"tel","CVC_count":"30","CVC_max":"4","CVC_iframe":"standard","CVC_style":"standard","Month_type":"select","Month_count":"3","Month_max":"2","Month_iframe":"custom","Month_width":"120px","Month_height":"20px","Month_style":"standard","Year_type":"select","Year_count":"5","Year_max":"4","Year_iframe":"custom","Year_width":"120px","Year_height":"20px","Year_style":"standard","Standard_input":"width:223px;height:30px;padding: 0 9px;font-size:14px;font-family:'Helvetica Neue',Verdana,Arial,sans-serif;","Standard_selection":"width:100px;","Iframe_width":"365px","Iframe_height":"30px","Errors_active":"false","Errors_lang":"de"} and is loaded from config creditcard/cc_template in getHostedParams (#3). Then it is tried to be unserialized with the PHP function unserialize, but not json_decode, since the Magento version is less than 2.2.0, which leads to the (notice) exception.

That renders the Payone extension unusable, I have no idea how to fix or work-around that.

@fjbender
Copy link
Contributor

@nixn As a workaround you can patch Helper/Base.php to always use json_decode() instead of unserialize():

    /**
     * Handle the serialization of strings depending on the Magento version
     *
     * @param  mixed $mValue
     * @return string
     */
    public function serialize($mValue) {
        return json_encode($mValue);
    }

    /**
     * @param  string $sValue
     * @return mixed
     */
    public function unserialize($sValue) {
        return json_decode($sValue, true);
    }

This is not ideal and we'll take a look why the data is stored in json in the database the first place.

@nixn
Copy link

nixn commented Jan 15, 2018

Thanks for your hint, I've written a plugin to override these two methods:

<?php
namespace Vendor\Module\Plugin;

use Payone\Core\Helper\Base;

class HelperBase
{
	public function aroundSerialize(Base $subject, callable $proceed, $mValue)
	{
		return json_encode($mValue);
	}

	public function aroundUnserialize(Base $subject, callable $proceed, $sValue)
	{
		if (preg_match('/^[a-z][:;]/i', $sValue))
			return unserialize($sValue);
		return json_decode($sValue, true);
	}
}

I'm using this plugin for Helper\HostedIframe only, but it could be used for every class deriving from Helper\Base. I did not had any other wrong calls for this yet, so it's sufficient for now.

di.xml:

<config>
    <type name="Payone\Core\Helper\HostedIframe">
        <plugin name="JsonFix" type="Vendor\Module\Plugin\HelperBase" />
    </type>
</config>

@fjbender
Copy link
Contributor

Can any of you confirm that #144 fixes this issue? Basically, we don't really care anymore whether the objects were saved with serialize() or as JSON.

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

No branches or pull requests

3 participants