When I’m trying to load the plugin configuration and other services, I’m facing some troubles and encountering errors. I need the plugin config here, and the connection is established through an API.
Error: Cannot assign null to property YourPlugin\Core\Rule\CustomResponseCodeRule::$connection of type Doctrine\DBAL\Connection
class CustomResponseCodeRule extends Rule
{
private Connection $connection;
private SystemConfigService $systemConfigService;
private ContainerInterface $container;
private CartService $cartService;
protected $isResponseValue;
protected string $operator;
public function __construct(
Connection $connection,
SystemConfigService $systemConfigService,
ContainerInterface $container,
CartService $cartService,
) {
parent::__construct();
$this->connection = $connection;
$this->systemConfigService = $systemConfigService;
$this->container = $container;
$this->cartService = $cartService;
$this->isResponseValue = 1;
}
/**
* @return string
*/
public function getName(): string
{
return 'plugin_response_check';
}
/**
* Override the match method to avoid session dependency
*
* @param RuleScope $scope
* @return bool
*/
public function match(RuleScope $scope): bool
{
$pluginStatus = $this->systemConfigService->get('IntrumCreditHelper.config.status');
if ($pluginStatus != 1) {
return false;
}
$customer = $scope->getSalesChannelContext()->getCustomer();
// Check for our rule and customer data
if (!$scope instanceof CheckoutRuleScope || !$customer) {
return true;
}
$cart = $this->cartService->getCart(
$scope->getSalesChannelContext()->getToken(),
$scope->getSalesChannelContext()
);
$totalAmount = $cart->getPrice()->getTotalPrice();
}
}