Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jul 15, 2020
2 parents fb7b485 + e08cb44 commit 341ac39
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 19 additions & 6 deletions Plugin/CustomerAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +33,7 @@
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;
Expand Down Expand Up @@ -75,31 +75,38 @@ 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,
ManagerInterface $messageManager,
ResponseFactory $response,
CusCollectFactory $cusCollectFactory,
Session $customerSession,
RedirectInterface $redirect
RedirectInterface $redirect,
StoreManagerInterface $storeManager
) {
$this->helperData = $helperData;
$this->messageManager = $messageManager;
$this->_response = $response;
$this->_cusCollectFactory = $cusCollectFactory;
$this->_customerSession = $customerSession;
$this->_redirect = $redirect;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -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()));
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "1.0.2",
"version": "1.0.3",
"license": "proprietary",
"authors": [
{
Expand Down
3 changes: 2 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<field id="sendto" translate="label comment" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Recipient(s)</label>
<comment><![CDATA[Separated by commas (,)]]></comment>
<validate>required-entry</validate>
</field>
</group>
<group id="customer_notification_email" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -125,4 +126,4 @@
</group>
</section>
</system>
</config>
</config>

0 comments on commit 341ac39

Please sign in to comment.