33 lines
824 B
PHP
33 lines
824 B
PHP
<?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;
|
|
}
|
|
}
|