I'm kind of making my first baby-steps into Magento2. I'm trying to migrate a Magento 1 module to Magento 2. I need to be able to get the configuration values, and read/edit them from my module. I created a plugin, using this on di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\Config\ScopeConfigInterface">
<plugin name="MyCompany_MyModule_config_override_plugin" type="\MyCompany\MyModule\Plugin\Config" sortOrder="1" disabled="false"/>
</type>
</config>
And this is on Plugin/Config.php:
<?php
namespace MyCompany\MyModule\Plugin;
class Config
{
protected $logger;
public function __construct(
\Psr\Log\LoggerInterface $loggerInterface
) {
$this->logger = $loggerInterface;
}
public function afterGetValue($path, $scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
{
$this->logger->debug('enter to after event');
return true;
}
}
When I use that, I'm getting lots of different issues each time on the frontend, for example this one:
1 exception(s):
Exception #0 (Exception): Notice: unserialize(): Error at offset 0 of 1 bytes in E:\MyCompany\code\magento2\vendor\magento\framework\View\DesignExceptions.php on line 68
I'm seeing on my debug log that the logger is working, here is the info:
[2017-03-29 19:31:56] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:31:59] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:00] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:00] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:01] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:02] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:02] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:03] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:04] main.DEBUG: enter to after {"is_exception":false} []
[2017-03-29 19:32:04] main.DEBUG: enter to after {"is_exception":false} []
Am I making the right approach to the task? My final goal is to be able to intercept the config options and being able to modify them from my plugin. Thanks in advance!