diff --git a/Block/Adminhtml/Edit/Approve.php b/Block/Adminhtml/Edit/Approve.php index f087b25..cf89c33 100755 --- a/Block/Adminhtml/Edit/Approve.php +++ b/Block/Adminhtml/Edit/Approve.php @@ -63,7 +63,7 @@ public function __construct( Data $helperData ) { $this->customerAccountManagement = $customerAccountManagement; - $this->helperData = $helperData; + $this->helperData = $helperData; parent::__construct($context, $registry); } diff --git a/Block/Adminhtml/Edit/NotApprove.php b/Block/Adminhtml/Edit/NotApprove.php index 7552495..cf1ea2a 100755 --- a/Block/Adminhtml/Edit/NotApprove.php +++ b/Block/Adminhtml/Edit/NotApprove.php @@ -63,7 +63,7 @@ public function __construct( Data $helperData ) { $this->customerAccountManagement = $customerAccountManagement; - $this->helperData = $helperData; + $this->helperData = $helperData; parent::__construct($context, $registry); } diff --git a/Block/Adminhtml/Edit/Tab/View.php b/Block/Adminhtml/Edit/Tab/View.php index 0fb3994..fbb47f1 100755 --- a/Block/Adminhtml/Edit/Tab/View.php +++ b/Block/Adminhtml/Edit/Tab/View.php @@ -63,7 +63,7 @@ public function __construct( public function getApprovedLabel() { $customerId = $this->getRequest()->getParam('id'); - $value = $this->helperData->getIsApproved($customerId); + $value = $this->helperData->getIsApproved($customerId); return $this->helperData->getApprovalLabel($value); } @@ -76,7 +76,7 @@ public function getApprovedLabel() public function isEnabled() { $customerId = $this->getRequest()->getParam('id'); - $customer = $this->helperData->getCustomerById($customerId); + $customer = $this->helperData->getCustomerById($customerId); return $this->helperData->isEnabledForWebsite($customer->getWebsiteId()); } diff --git a/Console/Command/Approve.php b/Console/Command/Approve.php index 35555a1..1e08fd9 100755 --- a/Console/Command/Approve.php +++ b/Console/Command/Approve.php @@ -78,10 +78,10 @@ public function __construct( HelperData $helperData, $name = null ) { - $this->customer = $customer; - $this->appState = $appState; + $this->customer = $customer; + $this->appState = $appState; $this->customerRepositoryInterface = $customerRepositoryInterface; - $this->helperData = $helperData; + $this->helperData = $helperData; parent::__construct($name); } @@ -111,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $emailCustomer = $input->getArgument(self::KEY_EMAIL); - $customer = $this->customerRepositoryInterface->get($emailCustomer); + $customer = $this->customerRepositoryInterface->get($emailCustomer); if (!$this->helperData->isEnabledForWebsite($customer->getWebsiteId())) { $output->writeln(''); $output->writeln('Module is not enabled for the website of this customer.'); diff --git a/Console/Command/NotApprove.php b/Console/Command/NotApprove.php index 6da9094..3a69f0c 100755 --- a/Console/Command/NotApprove.php +++ b/Console/Command/NotApprove.php @@ -77,10 +77,10 @@ public function __construct( Data $helperData, $name = null ) { - $this->customer = $customer; - $this->appState = $appState; + $this->customer = $customer; + $this->appState = $appState; $this->customerRepositoryInterface = $customerRepositoryInterface; - $this->helperData = $helperData; + $this->helperData = $helperData; parent::__construct($name); } @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $emailCustomer = $input->getArgument(self::KEY_EMAIL); - $customer = $this->customerRepositoryInterface->get($emailCustomer); + $customer = $this->customerRepositoryInterface->get($emailCustomer); if (!$this->helperData->isEnabledForWebsite($customer->getWebsiteId())) { $output->writeln(''); $output->writeln('Module is not enabled for the website of this customer.'); diff --git a/Helper/Data.php b/Helper/Data.php index e490c60..b316572 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -112,11 +112,11 @@ public function __construct( CustomerViewHelper $customerViewHelper, CustomerRegistry $customerRegistry ) { - $this->_httpContext = $httpContext; - $this->transportBuilder = $transportBuilder; - $this->attributeOptions = $attributeOptions; + $this->_httpContext = $httpContext; + $this->transportBuilder = $transportBuilder; + $this->attributeOptions = $attributeOptions; $this->customerViewHelper = $customerViewHelper; - $this->customerRegistry = $customerRegistry; + $this->customerRegistry = $customerRegistry; parent::__construct($context, $objectManager, $storeManager); } @@ -216,7 +216,7 @@ public function approvalAction($customer, $typeApproval) } $customerData = $customer->getDataModel(); - $attribute = $customerData->getCustomAttribute('is_approved'); + $attribute = $customerData->getCustomAttribute('is_approved'); if ($attribute && $attribute->getValue() != $typeApproval) { $customerData->setId($customer->getId()); $customerData->setCustomAttribute('is_approved', $typeApproval); @@ -234,7 +234,7 @@ public function approvalAction($customer, $typeApproval) public function setApprovePendingById($customerId, $actionRegister) { if ($this->getIsApproved($customerId) != AttributeOptions::PENDING) { - $customer = $this->customerRegistry->retrieve($customerId); + $customer = $this->customerRegistry->retrieve($customerId); $customerData = $customer->getDataModel(); $customerData->setId($customerId); @@ -360,8 +360,8 @@ public function getEmailTemplate($type, $storeId = null) public function emailApprovalAction($customer, $emailType) { $storeId = $customer->getStoreId(); - $sendTo = $customer->getEmail(); - $sender = $this->getSenderCustomer(); + $sendTo = $customer->getEmail(); + $sender = $this->getSenderCustomer(); if ($this->getAutoApproveConfig()) { $sender = $this->getConfigValue('customer/create_account/email_identity'); } @@ -380,11 +380,11 @@ public function emailApprovalAction($customer, $emailType) public function emailNotifyAdmin($customer) { $storeId = $this->getStoreId(); - $sender = $this->getSenderAdmin(); + $sender = $this->getSenderAdmin(); if ($this->getAutoApproveConfig()) { $sender = $this->getConfigValue('customer/create_account/email_identity'); } - $sendTo = $this->getRecipientsAdmin(); + $sendTo = $this->getRecipientsAdmin(); $sendToArray = explode(',', $sendTo); if ($this->getEnabledNoticeAdmin()) { @@ -568,8 +568,8 @@ public function shouldEnableButton($typeApprove) } $customerId = $this->getRequestParam('id'); - $customer = $this->getCustomerById($customerId); - $websiteId = $customer->getWebsiteId(); + $customer = $this->getCustomerById($customerId); + $websiteId = $customer->getWebsiteId(); if (!$this->isEnabledForWebsite($websiteId) || $this->getIsApproved($customerId) == $typeApprove) { return false; diff --git a/Model/ListApprove.php b/Model/ListApprove.php index 15ddece..cf8fc51 100755 --- a/Model/ListApprove.php +++ b/Model/ListApprove.php @@ -56,7 +56,7 @@ public function __construct( Data $helperData, CustomerRepositoryInterface $customerRepository ) { - $this->helperData = $helperData; + $this->helperData = $helperData; $this->customerRepository = $customerRepository; } diff --git a/Observer/CustomerSaveAfter.php b/Observer/CustomerSaveAfter.php index 4d2ae4b..edb1366 100755 --- a/Observer/CustomerSaveAfter.php +++ b/Observer/CustomerSaveAfter.php @@ -56,13 +56,13 @@ public function __construct(HelperData $helperData) */ public function execute(Observer $observer) { - $customer = $observer->getEvent()->getCustomer(); + $customer = $observer->getEvent()->getCustomer(); $autoApproval = $this->helperData->getAutoApproveConfig(); if (!$this->helperData->isEnabledForWebsite($customer->getWebsiteId())) { return; } - $customerId = $customer->getId(); + $customerId = $customer->getId(); $hasCustomerEdit = $this->helperData->hasCustomerEdit(); // case create customer in adminhtml if (!$hasCustomerEdit && $customerId) { diff --git a/Plugin/CustomerAuthenticated.php b/Plugin/CustomerAuthenticated.php index 28ca2bd..e114940 100644 --- a/Plugin/CustomerAuthenticated.php +++ b/Plugin/CustomerAuthenticated.php @@ -94,12 +94,12 @@ public function __construct( Session $customerSession, RedirectInterface $redirect ) { - $this->helperData = $helperData; - $this->messageManager = $messageManager; - $this->_response = $response; + $this->helperData = $helperData; + $this->messageManager = $messageManager; + $this->_response = $response; $this->_cusCollectFactory = $cusCollectFactory; - $this->_customerSession = $customerSession; - $this->_redirect = $redirect; + $this->_customerSession = $customerSession; + $this->_redirect = $redirect; } /** diff --git a/Plugin/CustomerConfirm.php b/Plugin/CustomerConfirm.php index 220320c..fd69303 100644 --- a/Plugin/CustomerConfirm.php +++ b/Plugin/CustomerConfirm.php @@ -74,9 +74,9 @@ public function __construct( RedirectInterface $redirect, Session $customerSession ) { - $this->helperData = $helperData; - $this->messageManager = $messageManager; - $this->_redirect = $redirect; + $this->helperData = $helperData; + $this->messageManager = $messageManager; + $this->_redirect = $redirect; $this->_customerSession = $customerSession; } diff --git a/Plugin/CustomerCreatePost.php b/Plugin/CustomerCreatePost.php index 93641a5..f90b595 100644 --- a/Plugin/CustomerCreatePost.php +++ b/Plugin/CustomerCreatePost.php @@ -98,13 +98,13 @@ public function __construct( ResponseFactory $responseFactory, CusCollectFactory $cusCollectFactory ) { - $this->helperData = $helperData; - $this->messageManager = $messageManager; + $this->helperData = $helperData; + $this->messageManager = $messageManager; $this->resultRedirectFactory = $resultRedirectFactory; - $this->_redirect = $redirect; - $this->_customerSession = $customerSession; - $this->_response = $responseFactory; - $this->_cusCollectFactory = $cusCollectFactory; + $this->_redirect = $redirect; + $this->_customerSession = $customerSession; + $this->_response = $responseFactory; + $this->_cusCollectFactory = $cusCollectFactory; } /** @@ -124,12 +124,12 @@ public function afterExecute(CreatePost $createPost, $result) } $customerId = null; - $request = $createPost->getRequest(); - $emailPost = $request->getParam('email'); + $request = $createPost->getRequest(); + $emailPost = $request->getParam('email'); if ($emailPost) { $cusCollectFactory = $this->_cusCollectFactory->create(); - $customerFilter = $cusCollectFactory->addFieldToFilter('email', $emailPost)->getFirstItem(); - $customerId = $customerFilter->getId(); + $customerFilter = $cusCollectFactory->addFieldToFilter('email', $emailPost)->getFirstItem(); + $customerId = $customerFilter->getId(); } if ($customerId) { diff --git a/Plugin/ResourceModel/AroundSaveData.php b/Plugin/ResourceModel/AroundSaveData.php index 37578fe..690f9a7 100755 --- a/Plugin/ResourceModel/AroundSaveData.php +++ b/Plugin/ResourceModel/AroundSaveData.php @@ -58,6 +58,7 @@ public function __construct(HelperData $helperData) * @param null $passwordHash * * @return mixed + * @SuppressWarnings("Unused") * @throws LocalizedException * @throws NoSuchEntityException */ @@ -72,17 +73,19 @@ public function aroundSave( } $valuePrevious = $this->helperData->getIsApproved($customer->getId()); - $result = $proceed($customer, $passwordHash); - $value = $this->helperData->getIsApproved($customer->getId()); + $result = $proceed($customer, $passwordHash); + $value = $this->helperData->getIsApproved($customer->getId()); - if ($value == AttributeOptions::APPROVED && ($valuePrevious == AttributeOptions::NOTAPPROVE || $valuePrevious == AttributeOptions::PENDING)) { + if ($value === AttributeOptions::APPROVED && + ($valuePrevious === AttributeOptions::NOTAPPROVE || $valuePrevious === AttributeOptions::PENDING)) { $this->helperData->emailApprovalAction($result, 'approve'); - } elseif ($value == AttributeOptions::NOTAPPROVE && (in_array( - $valuePrevious, - [AttributeOptions::APPROVED, AttributeOptions::PENDING, null] - ))) { + } elseif ($value === AttributeOptions::NOTAPPROVE + && (in_array($valuePrevious, [AttributeOptions::APPROVED, AttributeOptions::PENDING, null], true))) { $this->helperData->emailApprovalAction($result, 'not_approve'); - } elseif ($value == AttributeOptions::PENDING && $valuePrevious == null) { + } elseif ($value === AttributeOptions::PENDING + && ($valuePrevious === null + || $valuePrevious === AttributeOptions::NOTAPPROVE + || $valuePrevious === AttributeOptions::APPROVED)) { $this->helperData->emailApprovalAction($result, 'success'); } diff --git a/Setup/InstallData.php b/Setup/InstallData.php index f3fe5c0..d580c4b 100755 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -89,10 +89,10 @@ public function __construct( Config $eavConfig ) { $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - $this->indexerRegistry = $indexerRegistry; - $this->_pageFactory = $pageFactory; - $this->eavConfig = $eavConfig; + $this->attributeSetFactory = $attributeSetFactory; + $this->indexerRegistry = $indexerRegistry; + $this->_pageFactory = $pageFactory; + $this->eavConfig = $eavConfig; } /** @@ -110,7 +110,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - $attributeSet = $this->attributeSetFactory->create(); + $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->removeAttribute(Customer::ENTITY, self::IS_APPROVED); @@ -176,11 +176,11 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface */ private function initApprovedForAllCustomer($setup, $attributeId) { - $customerEntityTable = $setup->getTable('customer_entity'); + $customerEntityTable = $setup->getTable('customer_entity'); $customerEntityVarcharTable = $setup->getTable('customer_entity_varchar'); - $data = []; + $data = []; - $select = $setup->getConnection()->select()->from($customerEntityTable, ['entity_id']); + $select = $setup->getConnection()->select()->from($customerEntityTable, ['entity_id']); $customerIds = $setup->getConnection()->fetchCol($select); foreach ($customerIds as $id) { $data[] = [ diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index c7ae5c7..97e22e5 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -63,9 +63,9 @@ public function __construct( AttributeSetFactory $attributeSetFactory ) { $this->customerSetupFactory = $customerSetupFactory; - $this->indexerRegistry = $indexerRegistry; - $this->eavConfig = $eavConfig; - $this->attributeSetFactory = $attributeSetFactory; + $this->indexerRegistry = $indexerRegistry; + $this->eavConfig = $eavConfig; + $this->attributeSetFactory = $attributeSetFactory; } /** @@ -82,7 +82,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - $attributeSet = $this->attributeSetFactory->create(); + $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->removeAttribute(Customer::ENTITY, self::IS_APPROVED); @@ -128,16 +128,16 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface */ private function initApprovedForAllCustomer($setup, $attributeId) { - $customerEntityTable = $setup->getTable('customer_entity'); + $customerEntityTable = $setup->getTable('customer_entity'); $customerEntityTextTable = $setup->getTable('customer_entity_text'); - $data = []; - $connection = $setup->getConnection(); + $data = []; + $connection = $setup->getConnection(); $check = $connection->select()->from($customerEntityTextTable, ['entity_id']); $count = count($connection->fetchCol($check)); if ($count === 0) { - $select = $connection->select()->from($customerEntityTable, ['entity_id']); + $select = $connection->select()->from($customerEntityTable, ['entity_id']); $customerIds = $connection->fetchCol($select); foreach ($customerIds as $id) { $data[] = [ diff --git a/Test/Unit/Plugin/CustomerCreatePostTest.php b/Test/Unit/Plugin/CustomerCreatePostTest.php index e174389..89ab1c1 100755 --- a/Test/Unit/Plugin/CustomerCreatePostTest.php +++ b/Test/Unit/Plugin/CustomerCreatePostTest.php @@ -90,17 +90,17 @@ class CustomerCreatePostTest extends TestCase */ protected function setUp() { - $this->helperData = $this->getMockBuilder(HelperData::class) + $this->helperData = $this->getMockBuilder(HelperData::class) ->disableOriginalConstructor()->getMock(); - $this->messageManager = $this->getMockBuilder(ManagerInterface::class)->getMock(); + $this->messageManager = $this->getMockBuilder(ManagerInterface::class)->getMock(); $this->resultRedirectFactory = $this->getMockBuilder(RedirectFactory::class) ->disableOriginalConstructor()->getMock(); - $this->_redirect = $this->getMockBuilder(RedirectInterface::class)->getMock(); - $this->_customerSession = $this->getMockBuilder(CustomerSession::class) + $this->_redirect = $this->getMockBuilder(RedirectInterface::class)->getMock(); + $this->_customerSession = $this->getMockBuilder(CustomerSession::class) ->disableOriginalConstructor()->getMock(); - $this->_response = $this->getMockBuilder(ResponseFactory::class) + $this->_response = $this->getMockBuilder(ResponseFactory::class) ->disableOriginalConstructor()->getMock(); - $this->_cusCollectFactory = $this->getMockBuilder(CusCollectFactory::class) + $this->_cusCollectFactory = $this->getMockBuilder(CusCollectFactory::class) ->setMethods(['create']) ->disableOriginalConstructor()->getMock(); @@ -133,7 +133,7 @@ public function testAfterExecute() * @var CreatePost|PHPUnit_Framework_MockObject_MockObject $redirectOj */ $redirectOj = $this->getMockBuilder(CreatePost::class)->setMethods(['getRequest'])->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder(RequestInterface::class)->getMock(); + $request = $this->getMockBuilder(RequestInterface::class)->getMock(); $redirectOj->method('getRequest')->willReturn($request); $request->expects($this->once())->method('getParam')->with('email')->willReturn($emailPost); diff --git a/composer.json b/composer.json index 0115594..cb19b6c 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "mageplaza/module-core": "^1.4.5" }, "type": "magento2-module", - "version": "1.0.1", + "version": "1.0.2", "license": "proprietary", "authors": [ { diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 345d3ce..a4e828b 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -47,7 +47,7 @@ Enable,Enable "Error Message","Error Message" "Redirect CMS Page","Redirect CMS Page" "Admin Notification Email","Admin Notification Email" -"To avoid sending to spam box, you should install SMTP","To avoid sending to spam box, you should install SMTP" +"To avoid sending to spam box, you should install Mageplaza SMTP Extension.","To avoid sending to spam box, you should install Mageplaza SMTP Extension." Sender,Sender "Email Template","Email Template" Recipient(s),Recipient(s) diff --git a/view/adminhtml/ui_component/customer_form.xml b/view/adminhtml/ui_component/customer_form.xml index 9a3488e..398ce14 100755 --- a/view/adminhtml/ui_component/customer_form.xml +++ b/view/adminhtml/ui_component/customer_form.xml @@ -27,4 +27,18 @@ Mageplaza\CustomerApproval\Block\Adminhtml\Edit\Approve +
+ + + + customer + true + + + + text + true + + +
diff --git a/view/adminhtml/web/js/grid/columns/approval.js b/view/adminhtml/web/js/grid/columns/approval.js index c8947fe..69801a7 100755 --- a/view/adminhtml/web/js/grid/columns/approval.js +++ b/view/adminhtml/web/js/grid/columns/approval.js @@ -29,14 +29,18 @@ define([ bodyTmpl: 'ui/grid/cells/html' }, getLabel: function (record) { + if (!record.is_approved) { //not sure why it doesn't exist + return ''; + } + var columnVal = record.is_approved[0]; if (columnVal === 'pending') { return '' + $t('Pending') + ''; } else if (columnVal === 'notapproved') { - return '' + $t('Not Approved') + ''; - } else if (columnVal === 'approved'){ - return '' + $t('Approved') + ''; + return '' + $t('Not Approved') + ''; + } else if (columnVal === 'approved') { + return '' + $t('Approved') + ''; } return '';