49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Lts\Checkout\Controller\Index;
|
|
|
|
use Magento\Checkout\Model\Session;
|
|
use Magento\Framework\App\Action\Context;
|
|
use Magento\Framework\App\Action\HttpPostActionInterface;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\Exception\NoSuchEntityException;
|
|
use Magento\Quote\Api\CartRepositoryInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Magento\Framework\App\Action\Action;
|
|
|
|
class SavePoNumber extends Action implements HttpPostActionInterface
|
|
{
|
|
private \Magento\Framework\App\RequestInterface $request;
|
|
private CartRepositoryInterface $cartRepository;
|
|
private LoggerInterface $logger;
|
|
private Session $session;
|
|
|
|
public function __construct(
|
|
\Magento\Framework\App\RequestInterface $request,
|
|
CartRepositoryInterface $cartRepository,
|
|
LoggerInterface $logger,
|
|
Session $session,
|
|
Context $context
|
|
) {
|
|
parent::__construct($context);
|
|
$this->request = $request;
|
|
$this->cartRepository = $cartRepository;
|
|
$this->logger = $logger;
|
|
$this->session = $session;
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$poNumber = $this->request->getParam('poNumber');
|
|
$this->logger->debug("Saving po number: $poNumber");
|
|
|
|
try {
|
|
$quote = $this->session->getQuote();
|
|
$quote->setData('other_ref_num', $poNumber);
|
|
$this->cartRepository->save($quote);
|
|
} catch (NoSuchEntityException | LocalizedException $e) {
|
|
$this->logger->critical($e->getMessage());
|
|
}
|
|
|
|
}
|
|
} |