custom/plugins/s360-cms-manufacturer-overview/src/S360CMSManufacturer.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace S360CMSManufacturer;
  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\EqualsAnyFilter;
  9. class S360CMSManufacturer extends Plugin
  10. {
  11.     public function install(InstallContext $context): void
  12.     {
  13.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  14.         $customFieldSetRepository->upsert([
  15.             [
  16.                 'name' => 'custom_s360_manufacturers',
  17.                 'config' => [
  18.                     'label' => [
  19.                         'en-GB' => 'S360 Manufacturers custom fields',
  20.                         'de-De' => 'S360 Hersteller Zusatzfelder'
  21.                     ]
  22.                 ],
  23.                 'customFields' => [
  24.                     [
  25.                         'name' => 's360_manufacturers_hide_in_overview',
  26.                         'type' => CustomFieldTypes::BOOL,
  27.                         'config' => [
  28.                             'label' => [
  29.                                 'en-GB' => 'Hide on manufacturer page',
  30.                                 'de-De' => 'Auf Herstellerseite nicht anzeigen'
  31.                             ],
  32.                             'componentName' => 'sw-checkbox-field',
  33.                             'customFieldType' => 'checkbox',
  34.                             'translated' => false,
  35.                             'customFieldPosition' => 1
  36.                         ]
  37.                     ]
  38.                 ],
  39.                 'relations' => [
  40.                     [
  41.                         'entityName' => 'product_manufacturer'
  42.                     ]
  43.                 ]
  44.             ]
  45.         ], $context->getContext());
  46.     }
  47.     public function uninstall(UninstallContext $context): void {
  48.         if ($context->keepUserData()) {
  49.             return;
  50.         }
  51.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  52.         $criteria = new Criteria();
  53.         $criteria->addFilter(new EqualsAnyFilter('name', ['custom_s360_manufacturers']));
  54.         // EntitySearchResult
  55.         $result $customFieldSetRepository->search($criteria$context->getContext());
  56.         foreach ($result->getEntities() as $entity) {
  57.             $customFieldSetRepository->delete([[
  58.                 'id' => $entity->getId()
  59.             ]], $context->getContext());
  60.         }
  61.     }
  62. }