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

Commit

Permalink
Merge pull request #19 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
2.3 develop
  • Loading branch information
Shinichi69 authored Dec 28, 2021
2 parents 7b28036 + 27e597d commit 7f6e5f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
27 changes: 5 additions & 22 deletions Ui/Component/Listing/Columns/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@

use Exception;
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;
use Mageplaza\LoginAsCustomer\Model\LogFactory;

/**
* Class Customer
Expand All @@ -41,31 +38,23 @@ class Customer extends Column
*/
protected $customerRepository;

/**
* @var LogFactory
*/
protected $_logFactory;

/**
* Customer constructor.
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param CustomerRepository $customerRepository
* @param LogFactory $logFactory
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
CustomerRepository $customerRepository,
LogFactory $logFactory,
array $components = [],
array $data = []
) {
$this->customerRepository = $customerRepository;
$this->_logFactory = $logFactory;

parent::__construct($context, $uiComponentFactory, $components, $data);
}
Expand All @@ -74,25 +63,19 @@ public function __construct(
* @param array $dataSource
*
* @return array
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$customerId = $item['customer_id'];

try {
$customer = $this->customerRepository->getById($customerId);
if ($customer && $customer->getId()) {
$item['customer_id'] = $customer->getFirstname() . ' ' . $customer->getLastname() . ' <' . $customer->getEmail() . '>';
} else {
$item['customer_id'] = $item['customer_name'] . ' <' . $item['customer_email'] . '>';
}
$customer = $this->customerRepository->getById($customerId);
$item['customer_id'] = $customer->getFirstname() . ' ' .
$customer->getLastname() . ' <' . $customer->getEmail() . '>';
} catch (Exception $e) {
$log = $this->_logFactory->create()->load($item['customer_id'], 'customer_id');
$log->delete();
$item['customer_id'] = $item['customer_name'] . ' <' . $item['customer_email']
. '> Note: Customer\'s account has been deleted.';
}
}
}
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.5",
"version": "1.0.6",
"license": "proprietary",
"authors": [
{
Expand Down

0 comments on commit 7f6e5f5

Please sign in to comment.