0

Here am trying to add some condition before customer login. but I'm not able put plugin for Login. Here is my code

app/code/Praveenn/Pvnn/etc/di.xml
<?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\Customer\Controller\Account\LoginPost">
        <plugin name="MyCucomtLoginAccountLoginPost" type="Praveenn\Pvnn\Plugin\Customer\LoginPost" sortOrder="10" disabled="false"/>
    </type>
</config>

Plugin code

<?php

namespace Praveenn\Pvnn\Plugin\Customer;

class LoginPost
{
    public function aroundExecute(\Magento\Customer\Controller\Account\LoginPost $subject,$result)
    {   
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/PRAVLogin.log'); 
        $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); 
        $logger->info('here'); 
    }
}

Where am doing wrong. Can I get Help? Thank you in advance.

0

Your di.xml code seems right. But issue have at your Praveenn\Pvnn\Plugin\Customer\LoginPost.php

As your are using around plugin .your second parameter $result type is callable or \Closure. and After That if you want call original execute method then use $returnValue = $result(); and return $returnValue

<?php

namespace Praveenn\Pvnn\Plugin\Customer;

class LoginPost
{
    public function aroundExecute(\Magento\Customer\Controller\Account\LoginPost $subject,callable $result)
    {   
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/PRAVLogin.log'); 
        $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); 
        $logger->info('here'); 
        $returnValue = $result();
        return $returnValue;
    }
}
3
  • Thank you @Amit Bera for helping, I updated LoginPost.php and checked with callable or \Closure but its not still logging. – Praveen Negimani Oct 5 '20 at 5:39
  • i think for permission issue PRAVLogin.log is not creating.So create PRAVLogin.log at var/log folder and give rewrite permission to this file – Amit Bera Oct 5 '20 at 5:41
  • I run sudo chmod -R 777 generated/code/ pub/static/ pub/media/ var/ before and after running upgrade,deploy & c:f but still same, not logging – Praveen Negimani Oct 5 '20 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.