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 #21 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Sep 9, 2020
2 parents 341ac39 + 2ea86c8 commit 86fd4cf
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 77 deletions.
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Bug report
about: Technical issue with the extension
labels: 'Issue'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Preconditions (*)
<!---
Provide the exact Magento version (example: 2.4.0) and any important information on the environment where bug is reproducible.
-->
1.
2.

### Steps to reproduce (*)
<!---
Important: Provide a set of clear steps to reproduce this bug. We can not provide support without clear instructions on how to reproduce.
-->
1.
2.

### Expected result (*)
<!--- Tell us what do you expect to happen. -->
1. [Screenshots, logs or description]
2.

### Actual result (*)
<!--- Tell us what happened instead. Include error messages and issues. -->
1. [Screenshots, logs or description]
2.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/developer-experience-issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Developer experience issue
about: Issues related to customization, extensibility, modularity
labels: 'Experience'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Summary (*)
<!--- Describe the issue you are experiencing. Include general information, error messages, environments, and so on. -->

### Examples (*)
<!--- Provide code examples or a patch with a test (recommended) to clearly indicate the problem. -->

### Proposed solution
<!--- Suggest your potential solutions for this issue. -->
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature request
about: Request feature for development
labels: 'Feature Request'

---

<!---
Fields marked with (*) are required. Please don't remove the template.
-->

### Description (*)
<!--- Describe the feature you would like to add. -->

### Expected behavior (*)
<!--- What is the expected behavior of this feature? How is it going to work? -->

### Benefits
<!--- How do you think this feature would improve the extension? -->

### Additional information
<!--- What other information can you provide about the desired feature? -->
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--- Provide a general summary of the Pull Request in the Title above -->

### Description
<!--- Provide a description of the changes proposed in the pull request -->

### Fixed Issues (if relevant)
<!--- Provide a list of fixed issues in the format magento/magento2#<issue_number>, if relevant -->
1. https://github.com/mageplaza/magento-2-reports/<issue_number>: Issue title
2. ...

### Manual testing scenarios
<!--- Provide a set of unambiguous steps to test the proposed code change -->
1.
2.

### Contribution checklist
- [ ] Pull request has a meaningful description of its purpose
- [ ] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
13 changes: 13 additions & 0 deletions .github/no-response.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Configuration for probot-no-response - https://github.com/probot/no-response

# Number of days of inactivity before an Issue is closed for lack of response
daysUntilClose: 7
# Label requiring a response
responseRequiredLabel: waiting-customer-response
# Comment to post when closing an Issue for lack of response. Set to `false` to disable
closeComment: >
This issue has been automatically closed because there has been no response
to our request for more information from the original author. With only the
information that is currently in the issue, we don't have enough information
to take action. Please reach out if you have or find the answers we need so
that we can investigate further.
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Index/Approve.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function execute()

$approveStatus = $this->getRequest()->getParam('status');
try {
if ($approveStatus == AttributeOptions::APPROVED) {
if ($approveStatus === AttributeOptions::APPROVED) {
$this->helperData->approvalCustomerById($customerId, TypeAction::EDITCUSTOMER);
$this->messageManager->addSuccessMessage(__('Customer account has been approved!'));
} else {
Expand Down
11 changes: 1 addition & 10 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,6 @@ public function setApprovePendingById($customerId, $actionRegister)
}
}

/**
* @return int
* @throws NoSuchEntityException
*/
public function getStoreId()
{
return $this->storeManager->getStore()->getId();
}

/**
* @return bool
*/
Expand Down Expand Up @@ -379,7 +370,7 @@ public function emailApprovalAction($customer, $emailType)
*/
public function emailNotifyAdmin($customer)
{
$storeId = $this->getStoreId();
$storeId = $customer->getStoreId();
$sender = $this->getSenderAdmin();
if ($this->getAutoApproveConfig()) {
$sender = $this->getConfigValue('customer/create_account/email_identity');
Expand Down
1 change: 1 addition & 0 deletions Model/Config/Source/AttributeOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AttributeOptions extends AbstractSource
const PENDING = 'pending';
const APPROVED = 'approved';
const NOTAPPROVE = 'notapproved';
const NEW_STATUS = 'new';

/**
* @return array
Expand Down
71 changes: 39 additions & 32 deletions Plugin/CustomerCreatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Stdlib\Cookie\FailureToSendException;
use Mageplaza\CustomerApproval\Helper\Data as HelperData;
use Mageplaza\CustomerApproval\Model\Config\Source\AttributeOptions;
use Mageplaza\CustomerApproval\Model\Config\Source\TypeAction;

/**
Expand Down Expand Up @@ -112,10 +113,10 @@ public function __construct(
* @param $result
*
* @return mixed
* @throws FailureToSendException
* @throws InputException
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws FailureToSendException
*/
public function afterExecute(CreatePost $createPost, $result)
{
Expand All @@ -126,43 +127,49 @@ public function afterExecute(CreatePost $createPost, $result)
$customerId = null;
$request = $createPost->getRequest();
$emailPost = $request->getParam('email');

if ($emailPost) {
$cusCollectFactory = $this->_cusCollectFactory->create();
$customerFilter = $cusCollectFactory->addFieldToFilter('email', $emailPost)->getFirstItem();
$customerId = $customerFilter->getId();
}

if ($customerId) {
$customer = $this->helperData->getCustomerById($customerId);
if ($this->helperData->getAutoApproveConfig()) {
// case allow auto approve
$this->helperData->approvalCustomerById($customerId, TypeAction::OTHER);
// send email approve to customer
$this->helperData->emailApprovalAction($customer, 'approve');
} else {
// case not allow auto approve
$actionRegister = false;
$this->helperData->setApprovePendingById($customerId, $actionRegister);
$this->messageManager->addNoticeMessage(__($this->helperData->getMessageAfterRegister()));
// send email notify to admin
$this->helperData->emailNotifyAdmin($customer);
// send email notify to customer
$this->helperData->emailApprovalAction($customer, 'success');
// force logout customer
$this->_customerSession->logout()
->setBeforeAuthUrl($this->_redirect->getRefererUrl())
->setLastCustomerId($customerId);

// processCookieLogout
$this->helperData->processCookieLogout();

// force redirect
$url = $this->helperData->getUrl('customer/account/login', ['_secure' => true]);
/**
* @var Response $response
*/
$response = $this->_response->create();
$response->setRedirect($url)->sendResponse();
$statusCustomer = $this->helperData->getIsApproved($customerId);

if ($statusCustomer === AttributeOptions::NEW_STATUS) {
if ($customerId) {
$customer = $this->helperData->getCustomerById($customerId);

if ($this->helperData->getAutoApproveConfig()) {
// case allow auto approve
$this->helperData->approvalCustomerById($customerId, TypeAction::OTHER);
// send email approve to customer
$this->helperData->emailApprovalAction($customer, 'approve');
} else {
// case not allow auto approve
$actionRegister = false;
$this->helperData->setApprovePendingById($customerId, $actionRegister);
$this->messageManager->addNoticeMessage(__($this->helperData->getMessageAfterRegister()));
// send email notify to admin
$this->helperData->emailNotifyAdmin($customer);
// send email notify to customer
$this->helperData->emailApprovalAction($customer, 'success');
// force logout customer
$this->_customerSession->logout()
->setBeforeAuthUrl($this->_redirect->getRefererUrl())
->setLastCustomerId($customerId);

// processCookieLogout
$this->helperData->processCookieLogout();

// force redirect
$url = $this->helperData->getUrl('customer/account/login', ['_secure' => true]);
/**
* @var Response $response
*/
$response = $this->_response->create();
$response->setRedirect($url)->sendResponse();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
'input' => 'select',
'source' => AttributeOptions::class,
'required' => false,
'default' => 'approved',
'default' => AttributeOptions::NEW_STATUS,
'visible' => true,
'user_defined' => true,
'is_used_in_grid' => true,
Expand Down
4 changes: 2 additions & 2 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
{
$setup->startSetup();
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '1.0.1', '<')) {
if (version_compare($context->getVersion(), '1.0.2', '<')) {
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();

Expand All @@ -94,7 +94,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
'input' => 'select',
'source' => AttributeOptions::class,
'required' => false,
'default' => 'approved',
'default' => AttributeOptions::NEW_STATUS,
'visible' => true,
'user_defined' => true,
'is_used_in_grid' => true,
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.3",
"version": "1.0.4",
"license": "proprietary",
"authors": [
{
Expand Down
60 changes: 30 additions & 30 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_CustomerApproval
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mageplaza_CustomerApproval" setup_version="1.0.1">
<sequence>
<module name="Mageplaza_Core"/>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_CustomerApproval
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mageplaza_CustomerApproval" setup_version="1.0.2">
<sequence>
<module name="Mageplaza_Core"/>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>

0 comments on commit 86fd4cf

Please sign in to comment.