custom/plugins/ExpertDepositExtension-master/src/ExpertDepositExtension.php line 13

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