Files
2026-09-15 10:26:34 +08:00

85 lines
3.1 KiB
PHP
Executable File

<?php
/**
* Magezon
*
* This source file is subject to the Magezon Software License, which is available at https://www.magezon.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to https://www.magezon.com for more information.
*
* @category Magezon
* @package Magezon_QuickOrder
* @copyright Copyright (C) 2018 Magezon (https://www.magezon.com)
*/
namespace Magezon\QuickOrder\Controller\Index;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Psr\Log\LoggerInterface;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @var \Magento\Framework\Controller\Result\ForwardFactory
*/
protected $resultForwardFactory;
/**
* @var \Magezon\QuickOrder\Helper\Data
*/
protected $dataHelper;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
* @param \Magezon\QuickOrder\Helper\Data $dataHelper
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
\Magezon\QuickOrder\Helper\Data $dataHelper,
protected \Stemcell\Catalog\Helper\Product\View $productViewHelper,
protected CheckoutSession $checkoutSession,
protected LoggerInterface $logger,
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->resultForwardFactory = $resultForwardFactory;
$this->dataHelper = $dataHelper;
}
/**
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
try {
if (!$this->checkoutSession->getQuote()->getId()) {
$newQuote = $this->checkoutSession->getQuote();
$newQuote->setIsActive(true);
$newQuote->save();
}
} catch (\Exception $e) {
$this->logger->critical('货号直购页面发现没有新的购物车, 尝试初始化新购物车时失败,原因:'. $e->getMessage());
}
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set($this->dataHelper->getTitle());
if (!$this->dataHelper->isEnabled() || !$this->dataHelper->isGroupValid() || !$this->productViewHelper->notStockCheckGroup()) {
$resultForward = $this->resultForwardFactory->create();
return $resultForward->forward('noroute');
}
return $resultPage;
}
}