How to check if a plugin really work?
files are:
app/code/Vendor/Module/etc/di.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<type name="Magento\Store\Model\Store">
<plugin name="set_default_currency" type="Vendor\Module\Plugin\Store\Model\Store" disabled="false" />
</type>
</config>
app/code/Vendor/Module/Plugin/Store/Model/Store.php
<?php
namespace Vendor\Module\Plugin\Store\Model;
class Store
{
private $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger
)
{
$this->_logger = $logger;
}
public function afterGetDefaultCurrencyCode(
\Magento\Store\Model\Store $subject,
$result
)
{
$this->_logger->debug("GEOIP::".$result);
}
....
The plugin seems to never been called.
The method Magento\Store\Model\Store->getDefaultCurrencyCode() is one in the Limitation of plugins?
Limitations
Plugins can not be used on following:
- Final methods
- Final classes
- Non-public methods
- Class methods (such as static methods)
- __construct
- Virtual types
- Objects that are instantiated before Magento\Framework\Interception is bootstrapped
EDIT
The reason was a silly typo mistake in registration.php file.
I want to add a note for those who find themselves in this situation.
My aim was to update the default currency based on the user's geo location.
Although it is a good method to create a plugin for the getDefaultCurrencyCode
function, I ran into the issue of Full Page Cache, that literally drove me crazy.
Remembering the famous acronym "RTFM" I found an easy solution in: Configure page variations
Hope Will Help Someone...
$this->_logger->debug
for$this->_logger->critical
if you are not in developer mode the debug won't log anything