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 #15 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jun 16, 2020
2 parents 9cb1769 + 0e33f8e commit fb7b485
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Edit/Approve.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
Data $helperData
) {
$this->customerAccountManagement = $customerAccountManagement;
$this->helperData = $helperData;
$this->helperData = $helperData;

parent::__construct($context, $registry);
}
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Edit/NotApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
Data $helperData
) {
$this->customerAccountManagement = $customerAccountManagement;
$this->helperData = $helperData;
$this->helperData = $helperData;

parent::__construct($context, $registry);
}
Expand Down
4 changes: 2 additions & 2 deletions Block/Adminhtml/Edit/Tab/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions Console/Command/Approve.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.');
Expand Down
8 changes: 4 additions & 4 deletions Console/Command/NotApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.');
Expand Down
24 changes: 12 additions & 12 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Model/ListApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
Data $helperData,
CustomerRepositoryInterface $customerRepository
) {
$this->helperData = $helperData;
$this->helperData = $helperData;
$this->customerRepository = $customerRepository;
}

Expand Down
4 changes: 2 additions & 2 deletions Observer/CustomerSaveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions Plugin/CustomerAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Plugin/CustomerConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 10 additions & 10 deletions Plugin/CustomerCreatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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) {
Expand Down
19 changes: 11 additions & 8 deletions Plugin/ResourceModel/AroundSaveData.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(HelperData $helperData)
* @param null $passwordHash
*
* @return mixed
* @SuppressWarnings("Unused")
* @throws LocalizedException
* @throws NoSuchEntityException
*/
Expand All @@ -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');
}

Expand Down
16 changes: 8 additions & 8 deletions Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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[] = [
Expand Down
16 changes: 8 additions & 8 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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[] = [
Expand Down
14 changes: 7 additions & 7 deletions Test/Unit/Plugin/CustomerCreatePostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit fb7b485

Please sign in to comment.