<?php declare(strict_types=1);
namespace Mag\NewsletterOverlayBox;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
class MagNewsletterOverlayBox extends Plugin
{
/**
* @var EntityRepositoryInterface $customFieldSetRepository
*/
private $customFieldSetRepository;
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->addCustomFields($installContext);
}
/**
* {@inheritdoc}
*/
private function addCustomFields(InstallContext $installContext)
{
/** @var EntityRepositoryInterface $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(
new EqualsFilter('name', 'mag_newsletter_overlay_box')
);
$sets = $customFieldSetRepository->search($criteria, $installContext->getContext());
if (!$sets->count()) {
$customFieldSetRepository->create([[
'name' => 'mag_newsletter_overlay_box',
'customFields' => [
[
'name' => 'mag_newsletter_overlay_box_vouchercode',
'type' => CustomFieldTypes::TEXT
]
],
'relations' => [
[
'entityName' => 'newsletter_recipient'
]
],
]], $installContext->getContext());
}
}
}