31 lines
838 B
PHP
31 lines
838 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Cart\Plugin\TestMode;
|
|
|
|
use Esun\Cart\Model\TestModeConfig;
|
|
use Magento\Checkout\Controller\Index\Index as CheckoutIndex;
|
|
use Magento\Framework\Controller\Result\RedirectFactory;
|
|
use Magento\Framework\Controller\ResultInterface;
|
|
|
|
class RestrictCheckoutPlugin
|
|
{
|
|
public function __construct(
|
|
private readonly TestModeConfig $testModeConfig,
|
|
private readonly RedirectFactory $resultRedirectFactory
|
|
) {
|
|
}
|
|
|
|
public function aroundExecute(CheckoutIndex $subject, callable $proceed): ResultInterface
|
|
{
|
|
if (!$this->testModeConfig->isRestricted()) {
|
|
return $proceed();
|
|
}
|
|
|
|
return $this->resultRedirectFactory->create()->setPath(
|
|
'checkout/cart',
|
|
['_query' => ['purchase_test_mode' => 1]]
|
|
);
|
|
}
|
|
}
|