Let’s initiate a discussion!!
Step :1 Creat a custom attribute of boolean type which will be used to block customer login.
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
<?php declare(strict_types=1); namespace Vendor\Module\Setup\Patch\Data; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetup; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Eav\Model\Entity\Attribute\Set; use Magento\Eav\Model\Entity\Attribute\SetFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; class AddBlockedCustomerAttribute implements DataPatchInterface, PatchRevertableInterface { /** * @var ModuleDataSetupInterface */ private $moduleDataSetup; /** * @var CustomerSetup */ private $customerSetupFactory; /** * @var SetFactory */ private $attributeSetFactory; /** * Constructor * * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory * @param SetFactory $attributeSetFactory */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, CustomerSetupFactory $customerSetupFactory, SetFactory $attributeSetFactory ) { $this->moduleDataSetup = $moduleDataSetup; $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * {@inheritdoc} */ public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet Set */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->addAttribute( Customer::ENTITY, 'blocked', [ 'label' => 'Blocked', 'input' => 'boolean', 'type' => 'static', 'source' => '', 'required' => false, 'position' => 333, 'visible' => true, 'system' => false, 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false, 'backend' => '' ] ); $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'blocked'); $attribute->addData([ 'used_in_forms' => [ 'adminhtml_customer', 'adminhtml_checkout', 'customer_account_create', 'customer_account_edit' ] ]); $attribute->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId ]); $attribute->save(); $this->moduleDataSetup->getConnection()->endSetup(); } public function revert() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'blocked'); $this->moduleDataSetup->getConnection()->endSetup(); } /** * {@inheritdoc} */ public function getAliases() { return []; } /** * {@inheritdoc} */ public static function getDependencies() { return [ ]; } } |
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 |
<?php declare(strict_types=1); namespace Vendor\Module\Observer\Frontend\Customer; class Login implements \Magento\Framework\Event\ObserverInterface { /** * @var \Magento\Framework\App\ResponseFactory */ private $responseFactory; /** * @var \Magento\Framework\UrlInterface */ private $url; /** * @var \Magento\Customer\Model\SessionFactory */ private $customerSession; /** * @var \Magento\Framework\Message\ManagerInterface */ private $messageManager; /** * @var \Magento\Customer\Api\CustomerRepositoryInterface */ private $customerRepositoryInterface; /** * Observer Constructor * * @param \Magento\Framework\App\ResponseFactory $responseFactory * @param \Magento\Framework\UrlInterface $url * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Message\ManagerInterface $messageManager * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface */ public function __construct( \Magento\Framework\App\ResponseFactory $responseFactory, \Magento\Framework\UrlInterface $url, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface ) { $this->responseFactory = $responseFactory; $this->url = $url; $this->customerSession= $customerSession; $this->messageManager = $messageManager; $this->customerRepositoryInterface = $customerRepositoryInterface; } /** * Execute observer * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute( \Magento\Framework\Event\Observer $observer ) { $customer = $observer->getEvent()->getCustomer(); $blocked = $customer->getData('blocked'); if($blocked==1){ $this->customerSession->logout(); $this->messageManager->addErrorMessage(__('Your account has been blocked')); $redirectionUrl = $this->url->getUrl('customer/account/login'); $this->responseFactory->create()->setRedirect($redirectionUrl)->sendResponse(); return $this; } } } |
[crayon-641f0d930338a123131395/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.