From 6ea00a234778d4ca74e28d64ecfd84fe8798d238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Schuch?= Date: Tue, 3 Oct 2017 01:38:36 +0200 Subject: [PATCH 1/2] Update InstallData.php --- Setup/InstallData.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Setup/InstallData.php b/Setup/InstallData.php index 33b7ca2..c4c1478 100644 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -14,6 +14,7 @@ * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) * @link http://www.techdivision.com/ * @author Florian Sydekum + * @author Jürgen "Atlan" Schuch */ namespace Magenerds\BasePrice\Setup; @@ -21,6 +22,8 @@ use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\ModuleContextInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; /** * Class InstallData @@ -265,10 +268,20 @@ protected function _setSystemConfiguration() } } + $objectManager = ObjectManager::getInstance(); + $productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface'); + $version = $productMetadata->getVersion(); + + if($version < 2.2) { + $serializedData = serialize($data); + } else { + $serializedData = $objectManager->get(Json::class)->serialize($data); + } + // save system configuration $this->_configResource->saveConfig( \Magenerds\BasePrice\Helper\Data::CONVERSION_CONFIG_PATH, - serialize($data), + $serializedData, \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0 ); From cbe103ab144f355f4a9adad812a532a34c1a6617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Schuch?= Date: Tue, 3 Oct 2017 16:26:48 +0200 Subject: [PATCH 2/2] Update Data.php --- Helper/Data.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 23b071b..71ffb28 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -14,9 +14,13 @@ * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) * @link http://www.techdivision.com/ * @author Florian Sydekum + * @author Jürgen "Atlan" Schuch */ namespace Magenerds\BasePrice\Helper; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; + /** * Class Data * @package Magenerds\BasePrice\Helper @@ -58,10 +62,20 @@ public function getConversion($product) $productUnit = $product->getData('baseprice_product_unit'); $referenceUnit = $product->getData('baseprice_reference_unit'); - $configArray = unserialize($this->scopeConfig->getValue( + $scopeConfig = $this->scopeConfig->getValue( self::CONVERSION_CONFIG_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )); + ); + + $objectManager = ObjectManager::getInstance(); + $productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface'); + $version = $productMetadata->getVersion(); + $objectManager->get('Psr\Log\LoggerInterface')->info('Version('.var_export($version,true).')'); + if($version < 2.2) { + $configArray = unserialize($scopeConfig); + } else { + $configArray = $objectManager->get(Json::class)->unserialize($scopeConfig); + } foreach ($configArray as $config) { if ($config['product_unit'] == $productUnit