custom/plugins/s360-product-recommendations/src/S360ProductRecommendations.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace S360ProductRecommendations;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Storefront\Framework\ThemeInterface;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  10. class S360ProductRecommendations extends Plugin
  11. {
  12.     public function install(InstallContext $installContext): void
  13.     {
  14.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  15.         $customFieldSetRepository->create([
  16.             [
  17.                 'name' => 's360_product_recommendations',
  18.                 'config' => [
  19.                     'label' => [
  20.                         'en-GB' => 'S360 Product Recommendation',
  21.                         'de-De' => 'S360 Produkt Empfehlungen'
  22.                     ]
  23.                 ],
  24.                 'customFields' => [
  25.                     [
  26.                         'name' => 's360_product_recommendations_dynamic_product_group',
  27.                         'type' => CustomFieldTypes::ENTITY,
  28.                         'config' => [
  29.                             'label' => [
  30.                                 'en-GB' => 'Dymanic product group',
  31.                                 'de-De' => 'Dynamische Produktgruppe'
  32.                             ],
  33.                             'entity' => 'product_stream',
  34.                             'componentName' => 'sw-entity-single-select',
  35.                             'customFieldType' => 'select',
  36.                             'customFieldPosition' => 
  37.                         ]
  38.                     ],
  39.                     
  40.                 ],
  41.                 'relations' => [
  42.                     [
  43.                         'entityName' => 'category'
  44.                     ]
  45.                 ]
  46.             ]
  47.         ], $installContext->getContext());
  48.     }
  49.     public function uninstall(UninstallContext $uninstallContext): void
  50.     {
  51.         // this has to get uninstalled - cannot give user a choice (keep data) otherwise error on reinstall
  52.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  53.         $criteria = new Criteria();
  54.         $criteria->addFilter(new EqualsAnyFilter('name', ['s360_product_recommendations']));
  55.         // EntitySearchResult
  56.         $result $customFieldSetRepository->search($criteria$uninstallContext->getContext());
  57.         foreach ($result->getEntities() as $entity) {
  58.             $customFieldSetRepository->delete([[
  59.                 'id' => $entity->getId()
  60.             ]], $uninstallContext->getContext());
  61.         }
  62.     }
  63. }