custom/static-plugins/K3nApplicationCard/src/K3nApplicationCard.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace K3n\K3nApplicationCard;
  3. use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
  4. use Shopware\Core\Content\MailTemplate\Aggregate\MailTemplateType\MailTemplateTypeEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\Plugin;
  9. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Shopware\Core\Framework\Uuid\Uuid;
  12. class K3nApplicationCard extends Plugin
  13. {
  14.     public const TEMPLATE_TYPE_NAME 'Application card';
  15.     public const TEMPLATE_TYPE_TECHNICAL_NAME 'application_card';
  16.     public const MAIL_TEMPLATE_NAME 'ApplicationCardMailTemplate';
  17.     public function install(InstallContext $installContext): void
  18.     {
  19.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  20.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  21.         /** @var EntityRepositoryInterface $mailTemplateRepository */
  22.         $mailTemplateRepository $this->container->get('mail_template.repository');
  23.         $mailTemplateTypeId Uuid::randomHex();
  24.         $mailTemplateType = [
  25.             [
  26.                 'id' => $mailTemplateTypeId,
  27.                 'name' => self::TEMPLATE_TYPE_NAME,
  28.                 'technicalName' => self::TEMPLATE_TYPE_TECHNICAL_NAME,
  29.                 'availableEntities' => [
  30.                     'product' => 'product',
  31.                     'salesChannel' => 'sales_channel'
  32.                 ]
  33.             ]
  34.         ];
  35.         $mailTemplate = [
  36.             [
  37.                 'id' => Uuid::randomHex(),
  38.                 'mailTemplateTypeId' => $mailTemplateTypeId,
  39.                 'subject' => [
  40.                     'en-GB' => 'Agrility Reservation',
  41.                     'de-DE' => 'LG Seeds - Bestätigung Agrility Reservierung'
  42.                 ],
  43.                 'senderName' => '{{ salesChannel.name }}',
  44.                 'contentPlain' => "
  45.                     Hallo {{ userName }},\n\n
  46.                     Durch Ihre Reservierung in unserem Online-Portal haben Sie die Möglichkeit, kostenfrei Applikationskarten zur teilflächenspezifischen Maisaussaat 2021 zur erhalten. Entsprechend Ihrer reservierten Maismenge, erhalten Sie ein Flächenkontingent (ha), für das Sie Applikationskarten Anfragen können.\n
  47.                     Anfang 2021 erhalten Sie von uns den Code sowie alle weiteren Informationen, um die Applikationskarten für Ihre Maisflächen kostenfrei zu bestellen.\n
  48.                     Für weitere Informationen zu unserem Service der teilflächenspezifischen Maisaussaat erhalten Sie hier:\n
  49.                     www.lgseeds.de/agrility
  50.                     ",
  51.                 'contentHtml' => '
  52.                     <div style="font-family:arial; font-size:12px;">
  53.                         <p>Hallo {{ userName }},<br/><br/>
  54.                         <p>Durch Ihre Reservierung in unserem Online-Portal haben Sie die M&ouml;glichkeit, kostenfrei Applikationskarten zur teilfl&auml;chenspezifischen Maisaussaat 2021 zur erhalten. Entsprechend Ihrer reservierten Maismenge, erhalten Sie ein Fl&auml;chenkontingent (ha), f&uuml;r das Sie Applikationskarten Anfragen k&ouml;nnen.</p>
  55.                         <p>Anfang 2021 erhalten Sie von uns den Code sowie alle weiteren Informationen, um die Applikationskarten f&uuml;r Ihre Maisfl&auml;chen kostenfrei zu bestellen.</p>
  56.                         <p>F&uuml;r weitere Informationen zu unserem Service der teilfl&auml;chenspezifischen Maisaussaat erhalten Sie hier:&nbsp;<a href="http://www.lgseeds.de/agrility">www.lgseeds.de/agrility</a></p>
  57.                         </p>
  58.                     </div>
  59.                 ',
  60.             ]
  61.         ];
  62.         try {
  63.             $mailTemplateTypeRepository->create($mailTemplateType$installContext->getContext());
  64.             $mailTemplateRepository->create($mailTemplate$installContext->getContext());
  65.         } catch (UniqueConstraintViolationException $exception) {
  66.         }
  67.     }
  68.     public function uninstall(UninstallContext $uninstallContext): void
  69.     {
  70.         if ($uninstallContext->keepUserData()) {
  71.             return;
  72.         }
  73.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  74.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  75.         /** @var EntityRepositoryInterface $mailTemplateRepository */
  76.         $mailTemplateRepository $this->container->get('mail_template.repository');
  77.         /** @var MailTemplateTypeEntity $myCustomMailTemplateType */
  78.         $myCustomMailTemplateType $mailTemplateTypeRepository->search(
  79.             (new Criteria())
  80.                 ->addFilter(new EqualsFilter('technicalName'self::TEMPLATE_TYPE_TECHNICAL_NAME)),
  81.             $uninstallContext
  82.                 ->getContext()
  83.         )->first();
  84.         $mailTemplateIds $mailTemplateRepository->searchIds(
  85.             (new Criteria())
  86.                 ->addFilter(new EqualsFilter('mailTemplateTypeId'$myCustomMailTemplateType->getId())),
  87.             $uninstallContext
  88.                 ->getContext()
  89.         )->getIds();
  90.         $ids array_map(static function ($id) {
  91.             return ['id' => $id];
  92.         }, $mailTemplateIds);
  93.         $mailTemplateRepository->delete($ids$uninstallContext->getContext());
  94.         //Delete the TemplateType which were added by this Plugin
  95.         $mailTemplateTypeRepository->delete([
  96.             ['id' => $myCustomMailTemplateType->getId()]
  97.         ], $uninstallContext->getContext());
  98.     }
  99. }