custom/plugins/WbfkOffer/src/WbfkOffer.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * PremSoft
  5.  * Copyright © 2020 Premsoft - Sven Mittreiter
  6.  *
  7.  * @copyright  Copyright (c) 2020, premsoft - Sven Mittreiter (http://www.premsoft.de)
  8.  * @author     Sven Mittreiter <info@premsoft.de>
  9.  */
  10. namespace Wbfk\Offer;
  11. use Doctrine\DBAL\Connection;
  12. use Doctrine\DBAL\Exception;
  13. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  14. use Shopware\Core\Framework\Plugin;
  15. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  17. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  18. use Wbfk\Offer\Lifecycle\DocumentsLifecycle;
  19. use Wbfk\Offer\Lifecycle\MailLifecycle;
  20. class WbfkOffer extends Plugin
  21. {
  22.     public const EVENT_OFFER_REQUESTED 'wbfk.offer.requested';
  23.     public function install(InstallContext $installContext): void
  24.     {
  25.         /** @var EntityRepository $flowRepository */
  26.         /*
  27.         $flowRepository = $this->container->get('flow.repository');
  28.         $flowRepository->create([
  29.             [
  30.                 'id' => $this->ids->create('flow_id'),
  31.                 'name' => 'Create Offer',
  32.                 'eventName' => self::EVENT_OFFER_REQUESTED,
  33.                 'priority' => 1,
  34.                 'active' => true,
  35.                 'payload' => null,
  36.                 'invalid' => true,
  37.                 'sequences' => [
  38.                     [
  39.                         'id' => $this->ids->create('flow_sequence_id'),
  40.                         'parentId' => null,
  41.                         'ruleId' => $this->ids->create('rule_id'),
  42.                         'actionName' => null,
  43.                         'config' => [],
  44.                         'position' => 1,
  45.                         'rule' => [
  46.                             'id' => $this->ids->get('rule_id'),
  47.                             'name' => 'Test rule',
  48.                             'priority' => 1,
  49.                             'conditions' => [
  50.                                 ['type' => (new AlwaysValidRule())->getName()],
  51.                             ],
  52.                         ],
  53.                     ],
  54.                     [
  55.                         'id' => $this->ids->create('flow_sequence_id1'),
  56.                         'parentId' => $this->ids->get('flow_sequence_id'),
  57.                         'ruleId' => null,
  58.                         'actionName' => AddOrderTagAction::getName(),
  59.                         'config' => [
  60.                             'tagId' => $this->ids->get('tag_id'),
  61.                             'entity' => OrderDefinition::ENTITY_NAME,
  62.                         ],
  63.                         'position' => 1,
  64.                         'trueCase' => true,
  65.                     ],
  66.                     [
  67.                         'id' => $this->ids->create('flow_sequence_id2'),
  68.                         'parentId' => $this->ids->get('flow_sequence_id'),
  69.                         'ruleId' => null,
  70.                         'actionName' => AddOrderTagAction::getName(),
  71.                         'config' => [
  72.                             'tagId' => $this->ids->get('tag_id2'),
  73.                             'entity' => OrderDefinition::ENTITY_NAME,
  74.                         ],
  75.                         'position' => 2,
  76.                         'trueCase' => true,
  77.                     ],
  78.                 ],
  79.             ]
  80.         ], Context::createDefaultContext());
  81.         /**/
  82.         parent::install($installContext);
  83.     }
  84.     public function update(UpdateContext $updateContext): void
  85.     {
  86.         parent::update($updateContext);
  87.     }
  88.     /**
  89.      * @throws Exception
  90.      */
  91.     public function uninstall(UninstallContext $uninstallContext): void
  92.     {
  93.         if ($uninstallContext->keepUserData()) {
  94.             parent::uninstall($uninstallContext);
  95.             return;
  96.         }
  97.         /** @var Connection $connection */
  98.         $connection $this->container->get(Connection::class);
  99.         $docLifecycle = new DocumentsLifecycle($connection);
  100.         $docLifecycle->delete();
  101.         $mailLifecycle = new MailLifecycle($connection);
  102.         $mailLifecycle->delete();
  103.         $connection->executeStatement(
  104.             <<<SQL
  105.             DROP TABLE IF EXISTS `wbfk_offer_document`;
  106.             DROP TABLE IF EXISTS `wbfk_offer_item`;
  107.             DROP TABLE IF EXISTS `wbfk_offer_tag`;
  108.             DROP TABLE IF EXISTS `wbfk_offer`;
  109.             SQL
  110.         );
  111.         parent::uninstall($uninstallContext);
  112.     }
  113. }