82 lines
2.2 KiB
PHP
Executable File
82 lines
2.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © JR All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
|
|
namespace JR\ReportIntegration\Model;
|
|
|
|
use \JR\ReportIntegration\Api\Service\RequestServiceInterface;
|
|
use \JR\ReportIntegration\Api\Model\ConfirmManagementInterface;
|
|
use \Magento\Customer\Api\CustomerRepositoryInterface;
|
|
use \JR\ReportIntegration\Model\ChangeQuoteControl;
|
|
|
|
class ConfirmManagement implements ConfirmManagementInterface
|
|
{
|
|
/**
|
|
* @var RequestServiceInterface
|
|
*/
|
|
private $requestService;
|
|
|
|
/**
|
|
* @var CustomerRepositoryInterface
|
|
*/
|
|
private $customerRepository;
|
|
|
|
/**
|
|
* @var ChangeQuoteControl
|
|
*/
|
|
protected $changeQuoteControl;
|
|
|
|
/**
|
|
* @param RequestServiceInterface
|
|
* @param CustomerRepositoryInterface
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(
|
|
RequestServiceInterface $requestService,
|
|
CustomerRepositoryInterface $customerRepository,
|
|
ChangeQuoteControl $changeQuoteControl
|
|
) {
|
|
$this->requestService = $requestService;
|
|
$this->customerRepository = $customerRepository;
|
|
$this->changeQuoteControl = $changeQuoteControl;
|
|
}
|
|
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function postConfirm($email, $secret, $id, $sales_rep)
|
|
{
|
|
return $this->requestService->post(
|
|
$email,
|
|
$secret,
|
|
[$this, 'confirm'],
|
|
['id' => $id, 'sales_rep' => $sales_rep]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function confirm($id, $sales_rep)
|
|
{
|
|
$result = [];
|
|
try {
|
|
$customer = $this->customerRepository->getById($id);
|
|
$customer->setCustomAttribute('sales_rep', $sales_rep);
|
|
$customer->setGroupId(2);
|
|
$customer->setConfirmation(null);
|
|
$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;
|
|
}
|
|
}
|
|
|