We can do it by using preference if we need to add or edit some information in createPost controller.
To do that we will need a module : Magemonkeys_General
We have need two files.
Create di.xml file in this folder app/code/Magemonkeys/General/etc/
1 2 3 4 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Customer\Controller\Account\CreatePost" type="Magemonkeys\General\Controller\Magento\Customer\Account\CreatePost" /> </config> |
Create CreatePost.php in this folder app/code/Magemonkeys/General/Controller/Magento/Customer/Account/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
<?php namespace Magemonkeys\General\Controller\Magento\Customer\Account; use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository; use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Customer\Model\Account\Redirect as AccountRedirect; use Magento\Customer\Api\Data\AddressInterface; use Magento\Framework\Api\DataObjectHelper; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\CsrfAwareActionInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\Request\InvalidRequestException; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Phrase; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Helper\Address; use Magento\Framework\UrlFactory; use Magento\Customer\Model\Metadata\FormFactory; use Magento\Newsletter\Model\SubscriberFactory; use Magento\Customer\Api\Data\RegionInterfaceFactory; use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\CustomerInterfaceFactory; use Magento\Customer\Model\Url as CustomerUrl; use Magento\Customer\Model\Registration; use Magento\Framework\Escaper; use Magento\Customer\Model\CustomerExtractor; use Magento\Framework\Exception\StateException; use Magento\Framework\Exception\InputException; use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Customer\Controller\AbstractAccount; class CreatePost extends \Magento\Customer\Controller\Account\CreatePost { /** * @var Validator */ private $formKeyValidator; protected $inlineTranslation; /** * @var \Magento\Framework\Stdlib\Cookie\PhpCookieManager */ private $cookieMetadataManager; /** * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory */ private $cookieMetadataFactory; public function __construct( Context $context, Session $customerSession, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $accountManagement, Address $addressHelper, UrlFactory $urlFactory, FormFactory $formFactory, SubscriberFactory $subscriberFactory, RegionInterfaceFactory $regionDataFactory, AddressInterfaceFactory $addressDataFactory, CustomerInterfaceFactory $customerDataFactory, CustomerUrl $customerUrl, Registration $registration, Escaper $escaper, CustomerExtractor $customerExtractor, DataObjectHelper $dataObjectHelper, AccountRedirect $accountRedirect, CustomerRepository $customerRepository, Validator $formKeyValidator = null ) { $this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->get(Validator::class); $this->accountRedirect = $accountRedirect; return parent::__construct($context,$customerSession,$scopeConfig,$storeManager,$accountManagement,$addressHelper,$urlFactory,$formFactory,$subscriberFactory,$regionDataFactory,$addressDataFactory,$customerDataFactory,$customerUrl,$registration,$escaper,$customerExtractor,$dataObjectHelper,$accountRedirect,$customerRepository,$formKeyValidator); } public function execute() { /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } // We can write our login here } } |
we will also need to add private function in this file as we used execute method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/** * Retrieve cookie manager * * @deprecated 100.1.0 * @return \Magento\Framework\Stdlib\Cookie\PhpCookieManager */ private function getCookieManager() { if (!$this->cookieMetadataManager) { $this->cookieMetadataManager = ObjectManager::getInstance()->get( \Magento\Framework\Stdlib\Cookie\PhpCookieManager::class ); } return $this->cookieMetadataManager; } |
That’s it.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62838e574bb1e136378082/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...