<?php declare(strict_types=1);
namespace LoyxxSW6ConversionCheckout;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
/**
* Class LoyxxSW6ConversionCheckout
* @package LoyxxSW6ConversionCheckout
*/
class LoyxxSW6ConversionCheckout extends Plugin
{
/** Bundle Name */
public const BUNDLE_NAME = 'LoyxxSW6ConversionCheckout';
/** Author Name */
public const AUTHOR = 'Loy GmbH';
public function install(InstallContext $installContext): void
{
parent::install($installContext);
// set default value for config
$systemConfigService = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
$countryId = $systemConfigService->get(LoyxxSW6ConversionCheckout::BUNDLE_NAME. '.config.noDefaultCountry') ? NULL : $systemConfigService->get(LoyxxSW6ConversionCheckout::BUNDLE_NAME. '.config.defaultCountry');
if (is_null($countryId)){
$countryRepository = $this->container->get('country.repository');
$criteria = new Criteria();
$criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
new EqualsFilter('name', 'Germany'),
new EqualsFilter('name', 'Deutschland')
]));
$countryId = $countryRepository->searchIds($criteria, $installContext->getContext())->firstId();
$systemConfigService->set(LoyxxSW6ConversionCheckout::BUNDLE_NAME. '.config.defaultCountry', $countryId);
}
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
}
}