41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\CustomerVat\Controller\Vat;
|
|
|
|
use Esun\CustomerVat\Model\VatApplicationService;
|
|
use Magento\Customer\Model\Session;
|
|
use Magento\Framework\App\Action\Context;
|
|
use Magento\Framework\App\Action\HttpPostActionInterface;
|
|
use Magento\Framework\Data\Form\FormKey\Validator;
|
|
|
|
class Delete extends AbstractVat implements HttpPostActionInterface
|
|
{
|
|
public function __construct(
|
|
Context $context,
|
|
Session $customerSession,
|
|
private readonly Validator $formKeyValidator,
|
|
private readonly VatApplicationService $applications
|
|
) {
|
|
parent::__construct($context, $customerSession);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
if (!$this->formKeyValidator->validate($this->getRequest())) {
|
|
$this->messageManager->addErrorMessage(__('Your session has expired. Please try again.'));
|
|
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
|
}
|
|
try {
|
|
$this->applications->deleteForCustomer(
|
|
(int)$this->getRequest()->getParam('id'),
|
|
(int)$this->customerSession->getCustomerId()
|
|
);
|
|
$this->messageManager->addSuccessMessage(__('The VAT number has been deleted.'));
|
|
} catch (\Throwable $exception) {
|
|
$this->messageManager->addErrorMessage($exception->getMessage());
|
|
}
|
|
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
|
}
|
|
}
|