0

I wrote a plugin to Customer.php, for testing purpose, I added the error_log statement, but it had not been executed when I do the login action. Customer.php in my plugin:

<?php
namespace Vendor\PluginTest\Model\Plugin;

class Customer
{        
    public function afterValidatePassword(\Magento\Customer\Model\Customer $subject,$result)
    {
        error_log('afterValidatePassword');
        return $result;
    }
}

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\Model\Customer">
        <plugin name="customer-test-module" type="Vendor\PluginTest\Model\Plugin\Customer" sortOrder="1"/>
    </type>
</config>

I can't figure out where's wrong. Anyone can help? Anything I forgot to set? Thanks

2 Answers 2

0

i hope you wrote custom module inside vendor, second thing after creating module did you run upgrade cli and you module entry is in app/etc/config.php

Magento 2: rewrite controller

in above link check my post my, module is inside /app/Sugarcode/Test not inside vendor module

2
  • I wrote it in namespace XXX\PluginTest\Model\Plugin; I've ran the upgrade cli. and got module entry in app/etc/config.php. I've tried examples in this tutorial, and they work. Thanks
    – Ricky.C
    Commented Nov 24, 2015 at 4:37
  • i tried to put exit in core validatePassword function in customer.php , but its not exiting at the time of login can you test plugin for other function Commented Nov 24, 2015 at 5:09
0

Make sure your extension is registered by running php bin/magento module:status.

I don't think Magento\Customer\Model\Customer::validatePassword is used for login password validation. Magento\Customer\Model\AccountManagement::authenticate is where the password is validated when you login on the frontend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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