custom/plugins/ZeobvAbandonedCart/src/ZeobvAbandonedCart.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Zeobv\AbandonedCart;
  3. use Shopware\Core\Content\MailTemplate\Aggregate\MailTemplateType\MailTemplateTypeEntity;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\Context;
  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. class ZeobvAbandonedCart extends Plugin
  11. {
  12.     const MAIL_TEMPLATE_REMINDER_NAME 'abandoned_cart.reminder';
  13.     public function install(InstallContext $installContext): void
  14.     {
  15.         $mailTemplateRepository $this->container->get('mail_template.repository');
  16.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  17.         $criteria = new Criteria();
  18.         $criteria->addFilter(new EqualsFilter('technicalName'self::MAIL_TEMPLATE_REMINDER_NAME));
  19.         $templateType $mailTemplateTypeRepository->search($criteria$installContext->getContext())->first();
  20.         if ( $templateType instanceof MailTemplateTypeEntity) {
  21.             return;
  22.         }
  23.         $mailTemplateRepository->create([
  24.             [
  25.                 'systemDefault' => false,
  26.                 'translations' => [
  27.                     [
  28.                         'languageId' => Defaults::LANGUAGE_SYSTEM,
  29.                         'subject' => 'Your cart is waiting for you',
  30.                         'description' => 'Mail template send to customer who abandoned a shopping cart for longer than the configured time.',
  31.                         'senderName' => '{{ salesChannel.name }}',
  32.                         'contentPlain' => 'Your cart is waiting for you. Use the following link to go to checkout {{ zeoAbandonedCart.salesChannelDomain.url }}{{ path(\'frontend.zeo.abandonedcart.recover\', {id: zeoAbandonedCart.id}) }}',
  33.                         'contentHtml' => '<h2>Your cart is waiting for you.</h2>
  34. <p>Click the following link to proceed to checkout.<br/>
  35.     <a href="{{ zeoAbandonedCart.salesChannelDomain.url }}{{ path(\'frontend.zeo.abandonedcart.recover\', {id: zeoAbandonedCart.id}) }}">
  36.         <button>Go to checkout</button>
  37.     </a>
  38. </p>'
  39.                     ]
  40.                 ],
  41.                 'mailTemplateType' => [
  42.                     'technicalName' => self::MAIL_TEMPLATE_REMINDER_NAME,
  43.                     'availableEntities' => [
  44.                         'zeoAbandonedCart' => 'zeo_abandoned_cart',
  45.                         'salesChannel' => 'sales_channel',
  46.                         'customer' => 'customer'
  47.                     ],
  48.                     'translations' => [
  49.                         [
  50.                             'languageId' => Defaults::LANGUAGE_SYSTEM,
  51.                             'name' => 'Enter abandoned cart state: Reminded'
  52.                         ],
  53.                     ]
  54.                 ]
  55.             ]
  56.         ], $installContext->getContext());
  57.     }
  58. }