<?php declare(strict_types=1);
namespace Acris\PersistentCart;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\System\SystemConfig\SystemConfigEntity;
class AcrisPersistentCartCS extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext);
$this->setDefaultClearSessionConfigurationValue($activateContext->getContext());
}
private function setDefaultClearSessionConfigurationValue(Context $context): void
{
/** @var EntityRepositoryInterface $systemConfigRepository */
$systemConfigRepository = $this->container->get('system_config.repository');
/** @var EntitySearchResult $systemConfigResults */
$systemConfigResults = $systemConfigRepository->search((new Criteria())->addFilter(new EqualsFilter('configurationKey', 'core.loginRegistration.invalidateSessionOnLogOut')), $context);
if ($systemConfigResults->first() && $systemConfigResults->getTotal() > 0) {
/** @var SystemConfigEntity $systemConfig */
foreach ($systemConfigResults as $systemConfig) {
$systemConfigRepository->update([
[
'id' => $systemConfig->getId(),
'configurationValue' => false
]
], $context);
}
}
}
}