init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_CustomerVat::applications';
|
||||
|
||||
public function __construct(Context $context, private readonly PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->setActiveMenu('Esun_CustomerVat::applications');
|
||||
$page->getConfig()->getTitle()->prepend(__('VAT Number Applications'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
|
||||
|
||||
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatResource;
|
||||
use Esun\CustomerVat\Model\VatApplication;
|
||||
use Esun\CustomerVat\Model\VatApplicationFactory;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\Auth\Session as AuthSession;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class Review extends Action implements HttpPostActionInterface
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_CustomerVat::review';
|
||||
|
||||
public function __construct(Context $context, private readonly VatApplicationFactory $factory,
|
||||
private readonly VatResource $resource, private readonly AuthSession $authSession,
|
||||
private readonly DateTime $dateTime)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$id = (int)$this->getRequest()->getParam('id');
|
||||
$status = (string)$this->getRequest()->getParam('status');
|
||||
$allowed = [VatApplication::STATUS_PENDING, VatApplication::STATUS_APPROVED, VatApplication::STATUS_REJECTED];
|
||||
$application = $this->factory->create();
|
||||
$this->resource->load($application, $id);
|
||||
if (!$application->getId() || !in_array($status, $allowed, true)) {
|
||||
$this->messageManager->addErrorMessage(__('Unable to review this VAT application.'));
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
||||
}
|
||||
try {
|
||||
$admin = $this->authSession->getUser();
|
||||
$application->addData([
|
||||
'status' => $status,
|
||||
'review_note' => trim((string)$this->getRequest()->getParam('review_note')) ?: null,
|
||||
'reviewed_by' => $admin ? (int)$admin->getId() : null,
|
||||
'reviewed_at' => $this->dateTime->gmtDate(),
|
||||
]);
|
||||
$this->resource->save($application);
|
||||
$this->messageManager->addSuccessMessage(__('The VAT application review has been saved.'));
|
||||
} catch (\Throwable $exception) {
|
||||
$this->messageManager->addExceptionMessage($exception, __('Unable to save the VAT application review.'));
|
||||
}
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/view', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
|
||||
|
||||
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatResource;
|
||||
use Esun\CustomerVat\Model\VatApplicationFactory;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class View extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_CustomerVat::applications';
|
||||
|
||||
public function __construct(Context $context, private readonly PageFactory $pageFactory,
|
||||
private readonly VatApplicationFactory $factory, private readonly VatResource $resource,
|
||||
private readonly Registry $registry)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$application = $this->factory->create();
|
||||
$this->resource->load($application, (int)$this->getRequest()->getParam('id'));
|
||||
if (!$application->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('The VAT application no longer exists.'));
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
||||
}
|
||||
$this->registry->register('current_customer_vat_admin', $application);
|
||||
$page = $this->pageFactory->create();
|
||||
$page->setActiveMenu('Esun_CustomerVat::applications');
|
||||
$page->getConfig()->getTitle()->prepend(__('VAT Application #%1', $application->getId()));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Vat;
|
||||
|
||||
use Magento\Customer\Controller\AccountInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
|
||||
abstract class AbstractVat extends Action implements AccountInterface
|
||||
{
|
||||
public function __construct(Context $context, protected readonly Session $customerSession)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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\HttpGetActionInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Edit extends AbstractVat implements HttpGetActionInterface
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Session $customerSession,
|
||||
private readonly PageFactory $pageFactory,
|
||||
private readonly VatApplicationService $applications,
|
||||
private readonly Registry $registry
|
||||
) {
|
||||
parent::__construct($context, $customerSession);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$application = $this->applications->getByIdForCustomer(
|
||||
(int)$this->getRequest()->getParam('id'),
|
||||
(int)$this->customerSession->getCustomerId()
|
||||
);
|
||||
$this->registry->register('current_customer_vat', $application);
|
||||
$page = $this->pageFactory->create();
|
||||
$page->getConfig()->getTitle()->set(__('Edit VAT Number'));
|
||||
return $page;
|
||||
} catch (\Throwable $exception) {
|
||||
$this->messageManager->addErrorMessage($exception->getMessage());
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Vat;
|
||||
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Customer\Model\Session;
|
||||
|
||||
class Index extends AbstractVat implements HttpGetActionInterface
|
||||
{
|
||||
public function __construct(Context $context, Session $customerSession, private readonly PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context, $customerSession);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->getConfig()->getTitle()->set(__('VAT Number Management'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerVat\Controller\Vat;
|
||||
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Customer\Model\Session;
|
||||
|
||||
class NewAction extends AbstractVat implements HttpGetActionInterface
|
||||
{
|
||||
public function __construct(Context $context, Session $customerSession, private readonly PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context, $customerSession);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->getConfig()->getTitle()->set(__('Add VAT Number'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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 Save 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');
|
||||
}
|
||||
$id = (int)$this->getRequest()->getParam('id');
|
||||
try {
|
||||
$this->applications->saveForCustomer(
|
||||
(int)$this->customerSession->getCustomerId(),
|
||||
(array)$this->getRequest()->getParams(),
|
||||
$id
|
||||
);
|
||||
$this->messageManager->addSuccessMessage(__('Your VAT number has been submitted for review.'));
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/index');
|
||||
} catch (\Throwable $exception) {
|
||||
$this->messageManager->addErrorMessage($exception->getMessage());
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/' . ($id ? 'edit' : 'new'), $id ? ['id' => $id] : []);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user