custom/plugins/AcrisPersistentCartCS/src/AcrisPersistentCartCS.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\PersistentCart;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\Plugin;
  9. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  10. use Shopware\Core\System\SystemConfig\SystemConfigEntity;
  11. class AcrisPersistentCartCS extends Plugin
  12. {
  13.     public function activate(ActivateContext $activateContext): void
  14.     {
  15.         parent::activate($activateContext);
  16.         $this->setDefaultClearSessionConfigurationValue($activateContext->getContext());
  17.     }
  18.     private function setDefaultClearSessionConfigurationValue(Context $context): void
  19.     {
  20.         /** @var EntityRepositoryInterface $systemConfigRepository */
  21.         $systemConfigRepository $this->container->get('system_config.repository');
  22.         /** @var EntitySearchResult $systemConfigResults */
  23.         $systemConfigResults $systemConfigRepository->search((new Criteria())->addFilter(new EqualsFilter('configurationKey''core.loginRegistration.invalidateSessionOnLogOut')), $context);
  24.         if ($systemConfigResults->first() && $systemConfigResults->getTotal() > 0) {
  25.             /** @var SystemConfigEntity $systemConfig */
  26.             foreach ($systemConfigResults as $systemConfig) {
  27.                 $systemConfigRepository->update([
  28.                     [
  29.                         'id' => $systemConfig->getId(),
  30.                         'configurationValue' => false
  31.                     ]
  32.                 ], $context);
  33.             }
  34.         }
  35.     }
  36. }