vendor/store.shopware.com/flowsitedepositsystembasic/src/FlowsiteDepositSystemBasic.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * FLOWSITE Deposit System for Shopware 6 Main Class
  4.  *
  5.  * @copyright  2020 FLOWSITE GmbH
  6.  */
  7. namespace FLOWSITE\FlowsiteDepositSystemBasic;
  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\System\CustomField\CustomFieldTypes;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  15. class FlowsiteDepositSystemBasic extends Plugin
  16. {
  17.     public function install(InstallContext $context): void
  18.     {
  19.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  20.         $customFieldSetRepository->create(
  21.             [
  22.                 [
  23.                     'name' => 'deposit',
  24.                     'config' => [
  25.                         'label' => [
  26.                             'de-DE' => 'Pfand',
  27.                             'en-GB' => 'Deposit',
  28.                         ],
  29.                     ],
  30.                     'customFields' => [
  31.                         [
  32.                             'name' => 'deposit',
  33.                             'type' => CustomFieldTypes::FLOAT,
  34.                             'config' => [
  35.                                 'min' => 0,
  36.                                 'label' => [
  37.                                     'de-DE' => 'Pfandbetrag',
  38.                                     'en-GB' => 'Deposit value',
  39.                                 ],
  40.                             ],
  41.                         ],
  42.                         [
  43.                             'name' => 'deposittype',
  44.                             'type' => CustomFieldTypes::TEXT,
  45.                             'config' => [
  46.                                 'label' => [
  47.                                     'de-DE' => 'Pfandtyp',
  48.                                     'en-GB' => 'Deposit type',
  49.                                 ],
  50.                             ],
  51.                         ],
  52.                     ],
  53.                     'relations' => [
  54.                         [
  55.                             'entityName' => 'product',
  56.                         ],
  57.                     ],
  58.                 ],
  59.             ],
  60.             $context->getContext()
  61.         );
  62.     }
  63.     public function uninstall(UninstallContext $context): void
  64.     {
  65.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  66.         $entitites $customFieldSetRepository->search(
  67.             (new Criteria())->addFilter(
  68.                 new MultiFilter(
  69.                     MultiFilter::CONNECTION_OR,
  70.                     [
  71.                         new EqualsFilter('name''deposit'),
  72.                         new EqualsFilter('name''deposittype'),
  73.                     ]
  74.                 )
  75.             ),
  76.             \Shopware\Core\Framework\Context::createDefaultContext()
  77.         );
  78.         foreach ($entitites->getEntities() as $_entityId => $_entityData) {
  79.             $customFieldSetRepository->delete(
  80.                 [
  81.                     ['id' => $_entityId],
  82.                 ],
  83.                 \Shopware\Core\Framework\Context::createDefaultContext()
  84.             );
  85.         }
  86.     }
  87. }