I have seen plenty of solutions for Magento 1.9, but I have not been able to find any conclusive way of disabling user accounts for Magento 2.
I'm developing a custom theme whose parent is Magento/blank
.
I have no problem removing the login,signup,wishlist etc. from the frontend using XML and I've managed to remove any mention of customer accounts from the orders page (though I don't remember which process I followed to do so).
However, when my site loads I get an error in the console: Password fields present on an insecure (http://) page. This is a security risk that allows user login credentials to be stolen
. Further, if the site is rendered as plain html then the login form is visible.
There will never be any customer accounts allowed on the store, so I'd like to remove all references to accounts on all pages.
I have followed 7ochem's answer to create a custom module for registration removal, modified for Magento 2 as follows:
app/code/[Vendor_name]/[Module_name]/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'[Vendor_name]_[Module_name]',
__DIR__
);
app/code/[Vendor_name]/[Module_name]/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="[Vendor_name]_[Module_name]" setup_version="1.0.0">
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/[Vendor_name]/[Module_name]/Plugin/RegistrationPlugin.php
namespace [Vendor_name]\[Module_name]\Plugin;
use Magento\Customer\Model\Registration;
class RegistrationPlugin
{
/**
* @param Registration $subject
*/
public function afterIsAllowed(Registration $subject)
{
return false;
}
}
Using the code inspector (firefox-aurora), I can see a script which contains the variable window.authenticationPopup = ...
, so I presume that this module is not working properly.
EDIT:
Following JoshCarter's comments, I have added the following file:
app/code/[Vendor_name]/[Module_name]/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\Model\Registration">
<plugin name="[Vendor_name]_[Module_name]::after" type="[Vendor_name]\[Module_name]\Plugin\RegistrationPlugin"/>
</type>
</config>
After uploading this to the server, I executed the following commands:
$ php bin/magento indexer:reindex
$ php bin/magento setup:upgrade
$ php bin/magento setup:di:compile
During compilation, I receive the following error:
[InvalidArgumentException] Plugin class [Vendor_name][Module_name]\Plugin\RegistrationPlugin doesn't exist.
Best Answer
Just wanted to add a bit of information as an answer here on di.xml, what it is, and some new concepts of Magento 2 introduced by the file. I get this doesn't completely answer the question, but Joshua looks to have missed this file out and if you read our discussion in the comments you can see that he wasn't sure of the file because he hadn't used it before.
di = Dependency Injection - It allows us to declare a whole host of new classes and class types. It might be worth having a read up on the docs for Dependency Injection by Magento
It can be included inside
etc/
etc/frontend/
oretc/adminhtml
Pretty self explanatory but, classes declared in
etc/frontend/
would only be executed on the frontend of the site and vise versa foretc/adminhtml
- similar to the config nodes in Magento 1.x'setc/config.xml
..Inside etc/di.xml we can declare:
And probably a few more things i've not mentioned. For further reading have a look at the docs page for the file itself - http://devdocs.magento.com/guides/v2.0/extension-dev-guide/build/di-xml-file.html
In your case, you're declaring a Plugin, which you could call an Interceptor, they can then intercept before/after/around any public function. This makes Magento 2.x massively flexible and really allows Magento developers to almost completely disregard Observers and class rewrites in Magento 2.
However, sometimes, theres nothing you can do but have to rewrite a class, like in Magento 1.x. For this you can use a preference in Magento 2 as described in the docs in the link above.
From the comments we've had - it looks as though you've forgot the di.xml and once you created it there's probably just a simple mistake in the Plugin class itself.
Hopefully this helps demystify the new concept of the di.xml file a bit!
EDIT:
Adding the line
<referenceBlock name="customer_form_login" remove="true"/>
to the body of
default.xml
removes the input fields from /customer/account/login, which is where the user is redirected if they attempt to access /customer/account/create following the addition of the module in OP.Further to this, adding the line
<referenceBlock name="authentication-popup" remove="true"/>
removes the hidden username/password fields from pages, not including the checkout.