This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Esun\Cart\Plugin\TestMode;
use Esun\Cart\Model\TestModeConfig;
use Magento\Checkout\Model\Cart;
use Magento\Framework\Exception\LocalizedException;
class RestrictAddToCartPlugin
{
public function __construct(private readonly TestModeConfig $testModeConfig)
{
}
/**
* @param mixed $productInfo
* @param mixed $requestInfo
* @return array<mixed>|null
* @throws LocalizedException
*/
public function beforeAddProduct(Cart $subject, $productInfo, $requestInfo = null): ?array
{
if ($this->testModeConfig->isRestricted()) {
throw new LocalizedException(
__('Our website is currently in beta testing. Purchases are not available at this time.')
);
}
return null;
}
}
@@ -0,0 +1,30 @@
<?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]]
);
}
}