Hello,
If there is somekind of tutorial telling those information please share it here, i didn't found any, only simple 'hello world' and "news module" which isn't extending modules and aren't telling any useful information on this specific task.
So how to find 'events' (hooks?) and manipulate them? Let's maybe start this on example of Customers magento module. Place of module is: "vendor\magento\module-customer" - so i would like to make something new, let's say save new data when account is creating - how to find this event, and how to extend it?
The preferred way is to use the plugins: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html
Simple example with real data would be more satisfied.
This is what i could do with this guide:
First we neeed to create standard module files: registration.php, composer.json, etc/module.xml,
Second making plugin inside module: Plugin/somefile.php, etc/di.xml
So this plugin in plans need to Block Login every customer.
Inside di.xml:
<?xml version="1.0"?>
<config>
<type name="Customer">
<plugin name="BlockLogin" type="CustomerPlugin" sortOrder="1" disabled="true"/>
</type>
</config>
Inside Plugin/customer.php
(i did found interesting method inside vendor\magento\module-customer\Model\Customer.php - name: validatePassword($password))
<?php namespace Vendor\ModuleName\Plugin; class CustomerPlugin { public function aroundvalidatePassword($password) { return false; } }
and my currently errors looks like that:
[InvalidArgumentException] There are no commands defined in the "cache" namespace.
command : magento -v - drops this error:
[Magento\Framework\Exception\LocalizedException] Invalid Document Element 'config', attribute 'xsi:noNamespaceSchemaLocation': The attribute 'xsi:noNamespaceSchemaLocation' is not allowed. Line: 1
so it's fault in di.xml - but what kind of? wrong place? Guid didn't tell where to put it, so i did use module file structure:
I've found this tutorial: http://www.coolryan.com/magento/2016/01/21/plugins-in-magento-2/
and now there is no errors, with my test module but user still can change password and log in - so it 'doesn't work. I also created tutorial plugins but i don't see anykind of changes also in log file. First of plugin tutorial - was producing error in product edition in admin (error 500), second and thierd didn't do anything.
So what am i missing?
Currently my plugin looks like that:
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="CustomerPlugin" type="\MyPlugs\BlockLogin\Plugin\CustomerPlugin"/> </type> </config>
Plugin/CustomerPlugin.php
<?php namespace MyPlugs\BlockLogin\Plugin; class CustomerPlugin { public function aroundValidatePassword($password) { return false; } }