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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed May 22, 2019
2 parents 4be59de + 4fe8c0c commit 3311aa8
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 44 deletions.
12 changes: 7 additions & 5 deletions Controller/Adminhtml/Log/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

namespace Mageplaza\LoginAsCustomer\Controller\Adminhtml\Log;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;

/**
* Class Index
* @package Mageplaza\LoginAsCustomer\Controller\Adminhtml\Log
*/
class Index extends \Magento\Backend\App\Action
class Index extends Action
{
/**
* Authorization level of a basic admin session
Expand All @@ -40,15 +42,15 @@ class Index extends \Magento\Backend\App\Action
/**
* Page result factory
*
* @var \Magento\Framework\View\Result\PageFactory
* @var PageFactory
*/
public $resultPageFactory;

/**
* Index constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
Expand All @@ -62,7 +64,7 @@ public function __construct(
/**
* execute the action
*
* @return \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page
* @return \Magento\Backend\Model\View\Result\Page|Page
*/
public function execute()
{
Expand Down
14 changes: 10 additions & 4 deletions Controller/Adminhtml/Login/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@

namespace Mageplaza\LoginAsCustomer\Controller\Adminhtml\Login;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Customer\Model\CustomerFactory;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Url;
use Mageplaza\LoginAsCustomer\Helper\Data;
use Mageplaza\LoginAsCustomer\Model\LogFactory;
Expand All @@ -31,7 +36,7 @@
* Class Index
* @package Mageplaza\LoginAsCustomer\Controller\Adminhtml\Login
*/
class Index extends \Magento\Backend\App\Action
class Index extends Action
{
/**
* Authorization level of a basic admin session
Expand Down Expand Up @@ -77,8 +82,9 @@ public function __construct(
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return ResponseInterface|ResultInterface
* @throws NoSuchEntityException
* @throws LocalizedException
*/
public function execute()
{
Expand Down Expand Up @@ -115,6 +121,6 @@ public function execute()
->setScope($store)
->getUrl('mploginascustomer/login/index', ['key' => $token, '_nosid' => true]);

$this->getResponse()->setRedirect($loginUrl);
return $this->getResponse()->setRedirect($loginUrl);
}
}
14 changes: 10 additions & 4 deletions Controller/Login/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@

namespace Mageplaza\LoginAsCustomer\Controller\Login;

use Exception;
use Magento\Checkout\Model\Cart;
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Mageplaza\LoginAsCustomer\Helper\Data;
use Mageplaza\LoginAsCustomer\Model\LogFactory;

/**
* Class Index
* @package Mageplaza\LoginAsCustomer\Controller\Login
*/
class Index extends \Magento\Framework\App\Action\Action
class Index extends Action
{
/**
* @var AccountRedirect
Expand Down Expand Up @@ -87,7 +93,7 @@ public function __construct(
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
* @return ResponseInterface|Forward|Redirect|ResultInterface
*/
public function execute()
{
Expand All @@ -104,7 +110,7 @@ public function execute()
} else {
$this->checkoutCart->truncate()->save();
}
} catch (\Exception $e) {
} catch (Exception $e) {
$this->messageManager->addNoticeMessage(__('Cannot truncate cart items.'));
}

Expand All @@ -123,7 +129,7 @@ public function execute()

return $resultRedirect;
}
} catch (\Exception $e) {
} catch (Exception $e) {
$this->messageManager->addError(
__('An unspecified error occurred. Please contact us for assistance.')
);
Expand Down
23 changes: 14 additions & 9 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@

use Magento\Customer\Model\Customer;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Math\Random;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Core\Helper\AbstractData;

Expand All @@ -36,12 +41,12 @@ class Data extends AbstractData
const CONFIG_MODULE_PATH = 'mploginascustomer';

/**
* @var \Magento\Framework\AuthorizationInterface
* @var AuthorizationInterface
*/
protected $_authorization;

/**
* @var \Magento\Framework\Math\Random
* @var Random
*/
protected $mathRandom;

Expand All @@ -51,15 +56,15 @@ class Data extends AbstractData
* @param Context $context
* @param ObjectManagerInterface $objectManager
* @param StoreManagerInterface $storeManager
* @param \Magento\Framework\AuthorizationInterface $authorization
* @param \Magento\Framework\Math\Random $random
* @param AuthorizationInterface $authorization
* @param Random $random
*/
public function __construct(
Context $context,
ObjectManagerInterface $objectManager,
StoreManagerInterface $storeManager,
\Magento\Framework\AuthorizationInterface $authorization,
\Magento\Framework\Math\Random $random
AuthorizationInterface $authorization,
Random $random
) {
$this->_authorization = $authorization;
$this->mathRandom = $random;
Expand All @@ -77,7 +82,7 @@ public function isAllowLogin()

/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function getLoginToken()
{
Expand All @@ -87,8 +92,8 @@ public function getLoginToken()
/**
* @param Customer $customer
*
* @return \Magento\Store\Api\Data\StoreInterface|null
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return StoreInterface|null
* @throws NoSuchEntityException
*/
public function getStore($customer)
{
Expand Down
2 changes: 1 addition & 1 deletion Model/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Log extends AbstractModel implements IdentityInterface
*/
protected function _construct()
{
$this->_init(\Mageplaza\LoginAsCustomer\Model\ResourceModel\Log::class);
$this->_init(ResourceModel\Log::class);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions Model/ResourceModel/Log/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@

namespace Mageplaza\LoginAsCustomer\Model\ResourceModel\Log;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Mageplaza\LoginAsCustomer\Model\ResourceModel\Log;

/**
* Class Collection
* @package Mageplaza\LoginAsCustomer\Model\ResourceModel\Log
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
class Collection extends AbstractCollection
{
/**
* @var string
Expand Down Expand Up @@ -53,6 +56,6 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
*/
protected function _construct()
{
$this->_init(\Mageplaza\LoginAsCustomer\Model\Log::class, \Mageplaza\LoginAsCustomer\Model\ResourceModel\Log::class);
$this->_init(\Mageplaza\LoginAsCustomer\Model\Log::class, Log::class);
}
}
5 changes: 3 additions & 2 deletions Plugin/AddButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Mageplaza\LoginAsCustomer\Plugin;

use Magento\Sales\Block\Adminhtml\Order\View;
use Mageplaza\LoginAsCustomer\Helper\Data;

/**
Expand All @@ -45,9 +46,9 @@ public function __construct(Data $helper)
}

/**
* @param \Magento\Sales\Block\Adminhtml\Order\View $subject
* @param View $subject
*/
public function beforeGetBackUrl(\Magento\Sales\Block\Adminhtml\Order\View $subject)
public function beforeGetBackUrl(View $subject)
{
$customerId = $subject->getOrder()->getCustomerId();
if ($customerId && $this->helper->isAllowLogin()) {
Expand Down
24 changes: 13 additions & 11 deletions Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

namespace Mageplaza\LoginAsCustomer\Setup;

use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Zend_Db_Exception;

/**
* @codeCoverageIgnore
Expand All @@ -33,7 +35,7 @@ class InstallSchema implements InstallSchemaInterface
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @throws \Zend_Db_Exception
* @throws Zend_Db_Exception
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
Expand All @@ -46,21 +48,21 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
*/
$table = $installer->getConnection()
->newTable($installer->getTable('mp_login_as_customer'))
->addColumn('log_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, [
->addColumn('log_id', Table::TYPE_INTEGER, null, [
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true
], 'Entity ID')
->addColumn('admin_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Admin ID')
->addColumn('admin_email', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, [], 'Admin Email')
->addColumn('admin_name', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, [], 'Admin Name')
->addColumn('customer_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Customer ID')
->addColumn('customer_email', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, [], 'Customer Email')
->addColumn('customer_name', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, [], 'Customer Name')
->addColumn('token', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 64, [], 'Token')
->addColumn('is_logged_in', \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '0'], 'Is Logged In')
->addColumn('created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Creation Time')
->addColumn('admin_id', Table::TYPE_INTEGER, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Admin ID')
->addColumn('admin_email', Table::TYPE_TEXT, 255, [], 'Admin Email')
->addColumn('admin_name', Table::TYPE_TEXT, 255, [], 'Admin Name')
->addColumn('customer_id', Table::TYPE_INTEGER, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Customer ID')
->addColumn('customer_email', Table::TYPE_TEXT, 255, [], 'Customer Email')
->addColumn('customer_name', Table::TYPE_TEXT, 255, [], 'Customer Name')
->addColumn('token', Table::TYPE_TEXT, 64, [], 'Token')
->addColumn('is_logged_in', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '0'], 'Is Logged In')
->addColumn('created_at', Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Creation Time')
->setComment('Login As Customer Logs table');
$installer->getConnection()->createTable($table);

Expand Down
6 changes: 4 additions & 2 deletions Ui/Component/Listing/Columns/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
namespace Mageplaza\LoginAsCustomer\Ui\Component\Listing\Columns;

use Magento\Customer\Model\ResourceModel\CustomerRepository;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
Expand Down Expand Up @@ -62,8 +64,8 @@ public function __construct(
* @param array $dataSource
*
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function prepareDataSource(array $dataSource)
{
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "mageplaza/module-login-as-customer",
"description": "Magento 2 Login As Customer Extension",
"require": {
"mageplaza/module-core": "^1.4.0"
"mageplaza/module-core": "^1.4.3"
},
"type": "magento2-module",
"version": "1.0.1",
"version": "1.0.2",
"license": "proprietary",
"authors": [
{
Expand Down
6 changes: 4 additions & 2 deletions registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
* @license https://www.mageplaza.com/LICENSE.txt
*/

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Mageplaza_LoginAsCustomer',
__DIR__
);

0 comments on commit 3311aa8

Please sign in to comment.