88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Lts\Inventory\Controller\Index;
|
|
|
|
use Lts\Inventory\Api\Data\SourceCustomerInterface;
|
|
use Lts\Inventory\Api\Data\SourceCustomerInterfaceFactory;
|
|
use Lts\Inventory\Api\SourceCustomerRepositoryInterface;
|
|
use Magento\Customer\Model\Session;
|
|
use Magento\Framework\App\Action\HttpGetActionInterface;
|
|
use Magento\Framework\Controller\ResultInterface;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\View\Result\PageFactory;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class Index implements HttpGetActionInterface
|
|
{
|
|
|
|
/**
|
|
* @var PageFactory
|
|
*/
|
|
protected $resultPageFactory;
|
|
private Session $customerSession;
|
|
private \Magento\Framework\App\RequestInterface $request;
|
|
private SourceCustomerRepositoryInterface $sourceCustomerRepository;
|
|
private SourceCustomerInterfaceFactory $sourceCustomerFactory;
|
|
private \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory;
|
|
private \Magento\Framework\UrlInterface $url;
|
|
private \Magento\Framework\Message\ManagerInterface $messageManager;
|
|
private LoggerInterface $logger;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param PageFactory $resultPageFactory
|
|
*/
|
|
public function __construct(
|
|
PageFactory $resultPageFactory,
|
|
SourceCustomerInterfaceFactory $sourceCustomerFactory,
|
|
Session $customerSession,
|
|
SourceCustomerRepositoryInterface $sourceCustomerRepository,
|
|
\Magento\Framework\App\RequestInterface $request,
|
|
\Magento\Framework\Message\ManagerInterface $messageManager,
|
|
LoggerInterface $logger,
|
|
)
|
|
{
|
|
$this->resultPageFactory = $resultPageFactory;
|
|
$this->sourceCustomerFactory = $sourceCustomerFactory;
|
|
$this->sourceCustomerRepository = $sourceCustomerRepository;
|
|
$this->customerSession = $customerSession;
|
|
$this->request = $request;
|
|
$this->messageManager = $messageManager;
|
|
$this->logger = $logger;
|
|
}
|
|
|
|
protected function savePrefer()
|
|
{
|
|
$code = $this->request->getParam('code');
|
|
$customer = $this->customerSession->getCustomer();
|
|
if ($code && $customer->getId()) {
|
|
try {
|
|
$this->sourceCustomerRepository->save(
|
|
$this->sourceCustomerFactory->create()->setCustomerId($customer->getId())->setSourceCode($code)
|
|
);
|
|
} catch (LocalizedException $e) {
|
|
$this->logger->critical($e->getMessage(), $e->getTrace());
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Execute view action
|
|
*
|
|
* @return ResultInterface
|
|
*/
|
|
public function execute(): ResultInterface
|
|
{
|
|
$this->savePrefer();
|
|
$resultPage = $this->resultPageFactory->create();
|
|
$resultPage->getConfig()->getTitle()->set(__('My Warehouse'));
|
|
return $resultPage;
|
|
}
|
|
}
|
|
|