Files
ltsecurityinc/app/code/JR/ReportIntegration/Model/DisableAccountsManagement.php
T

92 lines
2.4 KiB
PHP
Executable File

<?php
/**
* Copyright © JR All rights reserved.
* See COPYING.txt for license details.
*/
namespace JR\ReportIntegration\Model;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Customer\Api\CustomerRepositoryInterface;
use JR\ReportIntegration\Api\Model\DisableAccountsManagementInterface;
use JR\ReportIntegration\Service\RequestService;
use JR\ReportIntegration\Model\ChangeQuoteControl;
class DisableAccountsManagement implements DisableAccountsManagementInterface
{
/**
* @var Json
*/
protected $json;
/**
* @var RequestService
*/
protected $requestService;
/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
/**
* @var ChangeQuoteControl
*/
protected $changeQuoteControl;
/**
* @param Json
* @param CustomerRepositoryInterface
*
*/
public function __construct(
Json $json,
RequestService $requestService,
CustomerRepositoryInterface $customerRepository,
ChangeQuoteControl $changeQuoteControl
) {
$this->json = $json;
$this->requestService = $requestService;
$this->customerRepository = $customerRepository;
$this->changeQuoteControl = $changeQuoteControl;
}
/**
* POST for disableAccounts api
* @param string $email
* @param string $secret
* @param string $ids
*/
public function postDisableAccounts($email, $secret, $ids)
{
return $this->requestService->post(
$email,
$secret,
[$this, 'disableAccounts'],
['ids' => $this->json->unserialize($ids)]
);
}
/**
* {@inheritdoc}
*/
public function disableAccounts($ids)
{
$result = [];
foreach ($ids as $id) {
try {
$customer = $this->customerRepository->getById($id);
$customer->setGroupId(5);
$customer->setConfirmation('non-empty string');
$this->changeQuoteControl->forceIsAllowed(true);
$this->customerRepository->save($customer);
$result[] = array('account' => $customer->getEmail(), 'error' => NULL);
} catch (\Exception $e) {
$result[] = array('account' => isset($customer) ? $customer->getEmail() : $id, 'error' => $e->getMessage());
}
}
return $result;
}
}