From 98ea60f1f0bd2e46a1080d03c185ab9e107705fa Mon Sep 17 00:00:00 2001 From: prime Date: Thu, 18 Jun 2020 14:32:42 +0700 Subject: [PATCH 1/4] compatible 235 - fix 1, 2, 3 - status old customer, recipient filed required --- Setup/InstallData.php | 2 +- Setup/UpgradeData.php | 4 +- etc/adminhtml/system.xml | 257 ++++++++++++++++++++------------------- 3 files changed, 133 insertions(+), 130 deletions(-) diff --git a/Setup/InstallData.php b/Setup/InstallData.php index d580c4b..727e9ae 100755 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -119,7 +119,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface 'type' => 'varchar', 'label' => 'Approval Status', 'input' => 'select', - "source" => AttributeOptions::class, + 'source' => AttributeOptions::class, 'required' => false, 'default' => 'approved', 'visible' => true, diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 97e22e5..a3b66eb 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -133,7 +133,9 @@ private function initApprovedForAllCustomer($setup, $attributeId) $data = []; $connection = $setup->getConnection(); - $check = $connection->select()->from($customerEntityTextTable, ['entity_id']); + $check = $connection->select() + ->from($customerEntityTextTable, ['entity_id']) + ->where('attribute_id = ?', $attributeId); $count = count($connection->fetchCol($check)); if ($count === 0) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 59cae61..a16c468 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,128 +1,129 @@ - - - - -
- - mageplaza - Mageplaza_CustomerApproval::configuration - - - - - Magento\Config\Model\Config\Source\Yesno - Yes to enable this module.]]> - - - - Magento\Config\Model\Config\Source\Yesno - If yes, customers will be approved when registering from the frontend - - - - required-entry - This notification is displayed when account is successfully registered - - - - Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove - This action is activated when customers use the disapproved accounts and try to log in. - - - - required-entry - - show_error - - - - - Magento\Cms\Model\Config\Source\Page - - redirect_page - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - Magento\Config\Model\Config\Source\Email\Identity - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - - - - - - - Magento\Config\Model\Config\Source\Email\Identity - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - -
-
-
\ No newline at end of file + + + + +
+ + mageplaza + Mageplaza_CustomerApproval::configuration + + + + + Magento\Config\Model\Config\Source\Yesno + Yes to enable this module.]]> + + + + Magento\Config\Model\Config\Source\Yesno + If yes, customers will be approved when registering from the frontend + + + + required-entry + This notification is displayed when account is successfully registered + + + + Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove + This action is activated when customers use the disapproved accounts and try to log in. + + + + required-entry + + show_error + + + + + Magento\Cms\Model\Config\Source\Page + + redirect_page + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + Magento\Config\Model\Config\Source\Email\Identity + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + required-entry + + + + + + + Magento\Config\Model\Config\Source\Email\Identity + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + +
+
+
From c6ee42e19b18e1ab6003435c9893900c494feab4 Mon Sep 17 00:00:00 2001 From: prime Date: Thu, 18 Jun 2020 15:17:16 +0700 Subject: [PATCH 2/4] compatible 235 - fix 3 - log message --- Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Data.php b/Helper/Data.php index b316572..e5d59e4 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -433,7 +433,7 @@ public function sendMail($sendTo, $customer, $emailTemplate, $storeId, $sender) return true; } catch (Exception $e) { - $this->_logger->critical($e->getLogMessage()); + $this->_logger->critical($e->getMessage()); } return false; From 7487dca107c743ebc1d6ec6bdea0de39bb9e0552 Mon Sep 17 00:00:00 2001 From: prime Date: Tue, 7 Jul 2020 15:39:44 +0700 Subject: [PATCH 3/4] ticket 99876 - fix can't log in when have 2 customer in different website --- Plugin/CustomerAuthenticated.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Plugin/CustomerAuthenticated.php b/Plugin/CustomerAuthenticated.php index e114940..7a1671c 100644 --- a/Plugin/CustomerAuthenticated.php +++ b/Plugin/CustomerAuthenticated.php @@ -25,7 +25,6 @@ use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CusCollectFactory; use Magento\Customer\Model\Session; -use Magento\Framework\App\ActionFlag; use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\App\ResponseFactory; use Magento\Framework\App\ResponseInterface; @@ -37,6 +36,7 @@ use Mageplaza\CustomerApproval\Helper\Data as HelperData; use Mageplaza\CustomerApproval\Model\Config\Source\AttributeOptions; use Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove; +use Magento\Store\Model\StoreManagerInterface; /** * Class CustomerAuthenticated @@ -75,16 +75,21 @@ class CustomerAuthenticated */ protected $_redirect; + /** + * @var StoreManagerInterface + */ + protected $storeManager; + /** * CustomerAuthenticated constructor. * * @param HelperData $helperData * @param ManagerInterface $messageManager - * @param ActionFlag $actionFlag * @param ResponseFactory $response * @param CusCollectFactory $cusCollectFactory * @param Session $customerSession * @param RedirectInterface $redirect + * @param StoreManagerInterface $storeManager */ public function __construct( HelperData $helperData, @@ -92,7 +97,8 @@ public function __construct( ResponseFactory $response, CusCollectFactory $cusCollectFactory, Session $customerSession, - RedirectInterface $redirect + RedirectInterface $redirect, + StoreManagerInterface $storeManager ) { $this->helperData = $helperData; $this->messageManager = $messageManager; @@ -100,6 +106,7 @@ public function __construct( $this->_cusCollectFactory = $cusCollectFactory; $this->_customerSession = $customerSession; $this->_redirect = $redirect; + $this->storeManager = $storeManager; } /** @@ -122,26 +129,31 @@ public function aroundAuthenticate( $password ) { $result = $proceed($username, $password); + if (!$this->helperData->isEnabled()) { return $result; } + $websiteId = $this->storeManager->getStore()->getWebsiteId(); $customerFilter = $this->_cusCollectFactory->create() ->addFieldToFilter('email', $username) + ->addFieldToFilter('website_id', $websiteId) ->getFirstItem(); // check old customer and set approved $getIsApproved = null; + if ($customerId = $customerFilter->getId()) { $this->isOldCustomerHasCheck($customerId); // check new customer logedin $getIsApproved = $this->helperData->getIsApproved($customerId); } - if ($customerId && $getIsApproved != AttributeOptions::APPROVED && $getIsApproved != null) { + if ($customerId && $getIsApproved !== AttributeOptions::APPROVED && !empty($getIsApproved)) { // case redirect $urlRedirect = $this->helperData->getUrl($this->helperData->getCmsRedirectPage(), ['_secure' => true]); - if ($this->helperData->getTypeNotApprove() == TypeNotApprove::SHOW_ERROR || $this->helperData->getTypeNotApprove() == null) { + if ($this->helperData->getTypeNotApprove() === TypeNotApprove::SHOW_ERROR + || empty($this->helperData->getTypeNotApprove())) { // case show error $urlRedirect = $this->helperData->getUrl('customer/account/login', ['_secure' => true]); $this->messageManager->addErrorMessage(__($this->helperData->getErrorMessage())); @@ -171,7 +183,8 @@ public function aroundAuthenticate( private function isOldCustomerHasCheck($customerId) { $getApproved = $this->helperData->getIsApproved($customerId); - if ($getApproved == null) { + + if (empty($getApproved)) { $this->helperData->autoApprovedOldCustomerById($customerId); } } From e08cb442ba92fcca580a645b398a78d94989a183 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 15 Jul 2020 09:15:44 +0700 Subject: [PATCH 4/4] Clean code --- Plugin/CustomerAuthenticated.php | 4 +- composer.json | 2 +- etc/adminhtml/system.xml | 258 +++++++++++++++---------------- 3 files changed, 132 insertions(+), 132 deletions(-) diff --git a/Plugin/CustomerAuthenticated.php b/Plugin/CustomerAuthenticated.php index 7a1671c..d422eb8 100644 --- a/Plugin/CustomerAuthenticated.php +++ b/Plugin/CustomerAuthenticated.php @@ -33,10 +33,10 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Stdlib\Cookie\FailureToSendException; +use Magento\Store\Model\StoreManagerInterface; use Mageplaza\CustomerApproval\Helper\Data as HelperData; use Mageplaza\CustomerApproval\Model\Config\Source\AttributeOptions; use Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove; -use Magento\Store\Model\StoreManagerInterface; /** * Class CustomerAuthenticated @@ -134,7 +134,7 @@ public function aroundAuthenticate( return $result; } - $websiteId = $this->storeManager->getStore()->getWebsiteId(); + $websiteId = $this->storeManager->getStore()->getWebsiteId(); $customerFilter = $this->_cusCollectFactory->create() ->addFieldToFilter('email', $username) ->addFieldToFilter('website_id', $websiteId) diff --git a/composer.json b/composer.json index cb19b6c..05514a5 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "mageplaza/module-core": "^1.4.5" }, "type": "magento2-module", - "version": "1.0.2", + "version": "1.0.3", "license": "proprietary", "authors": [ { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a16c468..7d1aac7 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,129 +1,129 @@ - - - - -
- - mageplaza - Mageplaza_CustomerApproval::configuration - - - - - Magento\Config\Model\Config\Source\Yesno - Yes to enable this module.]]> - - - - Magento\Config\Model\Config\Source\Yesno - If yes, customers will be approved when registering from the frontend - - - - required-entry - This notification is displayed when account is successfully registered - - - - Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove - This action is activated when customers use the disapproved accounts and try to log in. - - - - required-entry - - show_error - - - - - Magento\Cms\Model\Config\Source\Page - - redirect_page - - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - Magento\Config\Model\Config\Source\Email\Identity - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - required-entry - - - - - - - Magento\Config\Model\Config\Source\Email\Identity - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Email\Template - - - -
-
-
+ + + + +
+ + mageplaza + Mageplaza_CustomerApproval::configuration + + + + + Magento\Config\Model\Config\Source\Yesno + Yes to enable this module.]]> + + + + Magento\Config\Model\Config\Source\Yesno + If yes, customers will be approved when registering from the frontend + + + + required-entry + This notification is displayed when account is successfully registered + + + + Mageplaza\CustomerApproval\Model\Config\Source\TypeNotApprove + This action is activated when customers use the disapproved accounts and try to log in. + + + + required-entry + + show_error + + + + + Magento\Cms\Model\Config\Source\Page + + redirect_page + + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + Magento\Config\Model\Config\Source\Email\Identity + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + required-entry + + + + + + + Magento\Config\Model\Config\Source\Email\Identity + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Email\Template + + + +
+
+