Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
* @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Florian Sydekum <f.sydekum@techdivision.com>
* @author Jürgen "Atlan" Schuch <juergen@atmage.de>
*/
namespace Magenerds\BasePrice\Helper;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Class Data
* @package Magenerds\BasePrice\Helper
Expand Down Expand Up @@ -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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inject necessary classes via di.xml and constructor instead of the object manager :-)

$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
Expand Down
15 changes: 14 additions & 1 deletion Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Florian Sydekum <f.sydekum@techdivision.com>
* @author Jürgen "Atlan" Schuch <juergen@atmage.de>
*/
namespace Magenerds\BasePrice\Setup;

use Magento\Eav\Setup\EavSetup;
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
Expand Down Expand Up @@ -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
);
Expand Down