<?php declare(strict_types=1);
namespace MoorlForms\Core\Content\Element\Selection;
use MoorlForms\Core\Content\Element\ElementCollection;
use MoorlForms\Core\Content\Element\ElementEntity;
use Shopware\Core\Defaults;
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\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\System\Salutation\SalutationEntity;
class ElementSelectionSalutation extends ElementSelectionExtension
{
protected EntityRepositoryInterface $repository;
public function __construct(
EntityRepositoryInterface $repository
)
{
$this->repository = $repository;
}
public function getName(): string
{
return "salutation";
}
public function init(ElementEntity $element, ElementCollection $elements): void
{
$criteria = new Criteria();
$criteria->addFilter(new NotFilter('or', [
new EqualsFilter('id', Defaults::SALUTATION),
]));
$items = $this->repository->search($criteria, $this->salesChannelContext->getContext())->getEntities();
$newItems = [];
/** @var SalutationEntity $item */
foreach ($items as $item) {
$new = $this->createOption($item, $element->getId(), $afterId);
$new->addTranslated('name', $item->getTranslation('displayName'));
//$new->setTechnicalName($item->getSalutationKey());
$newItems[] = $new;
}
$elements->merge(new ElementCollection($newItems));
}
}