custom/plugins/LoyxxSW6ConversionCheckout/src/LoyxxSW6ConversionCheckout.php line 16

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace LoyxxSW6ConversionCheckout;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. /**
  10.  * Class LoyxxSW6ConversionCheckout
  11.  * @package LoyxxSW6ConversionCheckout
  12.  */
  13. class LoyxxSW6ConversionCheckout extends Plugin
  14. {
  15.     /** Bundle Name */
  16.     public const BUNDLE_NAME 'LoyxxSW6ConversionCheckout';
  17.     /** Author Name */
  18.     public const AUTHOR 'Loy GmbH';
  19.     public function install(InstallContext $installContext): void
  20.     {
  21.         parent::install($installContext);
  22.         // set default value for config
  23.         $systemConfigService $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  24.         $countryId $systemConfigService->get(LoyxxSW6ConversionCheckout::BUNDLE_NAME'.config.noDefaultCountry') ? NULL $systemConfigService->get(LoyxxSW6ConversionCheckout::BUNDLE_NAME'.config.defaultCountry');
  25.         if (is_null($countryId)){
  26.             $countryRepository $this->container->get('country.repository');
  27.             $criteria = new Criteria();
  28.             $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
  29.                 new EqualsFilter('name''Germany'),
  30.                 new EqualsFilter('name''Deutschland')
  31.             ]));
  32.             $countryId $countryRepository->searchIds($criteria$installContext->getContext())->firstId();
  33.             $systemConfigService->set(LoyxxSW6ConversionCheckout::BUNDLE_NAME'.config.defaultCountry'$countryId);
  34.         }
  35.     }
  36.     public function uninstall(UninstallContext $uninstallContext): void
  37.     {
  38.         parent::uninstall($uninstallContext);
  39.         if ($uninstallContext->keepUserData()) {
  40.             return;
  41.         }
  42.     }
  43. }