From d157869b74754e79f57338c8a2f31b628b02e63a Mon Sep 17 00:00:00 2001 From: linhnv Date: Tue, 28 Jun 2022 14:39:55 +0700 Subject: [PATCH] --fix bug when disable module --- Controller/Index/Download.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Controller/Index/Download.php b/Controller/Index/Download.php index 3a4988c..f9b77c0 100644 --- a/Controller/Index/Download.php +++ b/Controller/Index/Download.php @@ -26,11 +26,13 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Mageplaza\ShareCart\Api\ShareCartRepositoryInterface; +use Mageplaza\ShareCart\Helper\Data; use Mpdf\MpdfException; /** @@ -49,20 +51,28 @@ class Download extends Action */ protected $checkoutSession; + /** + * @var Data + */ + protected $helper; + /** * Download constructor. * * @param Context $context * @param ShareCartRepositoryInterface $printProcess * @param Session $checkoutSession + * @param Data $helper */ public function __construct( Context $context, ShareCartRepositoryInterface $printProcess, - Session $checkoutSession + Session $checkoutSession, + Data $helper ) { $this->printProcess = $printProcess; $this->checkoutSession = $checkoutSession; + $this->helper = $helper; parent::__construct($context); } @@ -76,6 +86,12 @@ public function __construct( */ public function execute() { + /** @var Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + if (!$this->helper->isEnabled()) { + $this->messageManager->addErrorMessage(__('The Share Cart extension is disable')); + return $resultRedirect->setPath('checkout/cart'); + } $mpShareCartToken = $this->checkoutSession->getQuote()->getMpShareCartToken(); $this->printProcess->downloadPdf($mpShareCartToken);