86 lines
2.3 KiB
PHP
Executable File
86 lines
2.3 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\DenyManagementInterface;
|
|
use \Magento\Customer\Api\CustomerRepositoryInterface;
|
|
use \JR\ReportIntegration\Model\ChangeQuoteControl;
|
|
|
|
class DenyManagement implements DenyManagementInterface
|
|
{
|
|
/**
|
|
* @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 postDeny($email, $secret, $id, $customer_group)
|
|
{
|
|
return $this->requestService->post(
|
|
$email,
|
|
$secret,
|
|
[$this, 'deny'],
|
|
['id' => $id, 'customer_group' => $customer_group]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function deny($id, $customer_group)
|
|
{
|
|
$result = [];
|
|
$groups = [
|
|
'Enduser' => 5,
|
|
'Competitor' => 6,
|
|
'Other' => 7,
|
|
];
|
|
try {
|
|
$customer = $this->customerRepository->getById($id);
|
|
$customer->setCustomAttribute('sales_rep', '');
|
|
$customer->setGroupId(array_key_exists($customer_group, $groups) ? $groups[$customer_group] : 7);
|
|
$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;
|
|
}
|
|
}
|
|
|