custom/plugins/PixupSitemapGeneratorSW6/src/PixupSitemapGeneratorSW6.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Pixup\GoogleSitemapGenerator;
  3. use Shopware\Core\Content\Category\CategoryDefinition;
  4. use Shopware\Core\Content\LandingPage\LandingPageDefinition;
  5. use Shopware\Core\Content\Product\ProductDefinition;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\OrFilter;
  11. use Shopware\Core\Framework\Plugin;
  12. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  15. use Shopware\Core\System\CustomField\CustomFieldTypes;
  16. use Shopware\Storefront\Page\LandingPage\LandingPage;
  17. class PixupSitemapGeneratorSW6 extends Plugin
  18. {
  19.     public function install(InstallContext $installContext): void
  20.     {
  21.         parent::install($installContext); // TODO: Change the autogenerated stub
  22.         $this->createCustomFields($installContext->getContext());
  23.     }
  24.     public function update(UpdateContext $updateContext): void
  25.     {
  26.         parent::update($updateContext); // TODO: Change the autogenerated stub
  27.         $this->createCustomFields($updateContext->getContext());
  28.     }
  29.     public function uninstall(UninstallContext $uninstallContext): void
  30.     {
  31.         parent::uninstall($uninstallContext);
  32.         // remove custom Field
  33.         $customFieldRepository $this->container->get('custom_field_set.repository');
  34.         $criteria = new Criteria();
  35.         $criteria->addFilter(new OrFilter([
  36.             new EqualsAnyFilter('name', ['pixup_google_sitemap']),
  37.         ]));
  38.         $ids $customFieldRepository->searchIds($criteria$uninstallContext->getContext());
  39.         $ids $ids->getTotal() > $ids null;
  40.         if ($ids) {
  41.             $customFieldRepository->delete(array_values($ids->getData()), $uninstallContext->getContext());
  42.         }
  43.     }
  44.     public function createCustomFields($context) {
  45.         /**
  46.          * @var EntityRepository $customFieldRepository
  47.          */
  48.         $customFieldRepository $this->container->get("custom_field_set.repository");
  49.         $r $customFieldRepository->search( (new Criteria())->addFilter(new EqualsFilter("name","pixup_google_sitemap")),$context);
  50.         if(empty($r->first())) {
  51.             $customFieldRepository->create([
  52.                 [
  53.                     'name' => 'pixup_google_sitemap',
  54.                     'global' => false,
  55.                     'config' => [
  56.                         'label' => [
  57.                             'de-DE' => 'Sitemap Einstellungen',
  58.                             'en-GB' => 'Sitemap Settings'
  59.                         ]
  60.                     ],
  61.                     'relations' => [
  62.                         ['entityName' => CategoryDefinition::ENTITY_NAME],
  63.                         ['entityName' => ProductDefinition::ENTITY_NAME],
  64.                         ['entityName' => LandingPageDefinition::ENTITY_NAME]
  65.                     ],
  66.                     'customFields' => [
  67.                         [
  68.                             'name' => 'pixup_google_sitemap_exclude',
  69.                             'type' => CustomFieldTypes::BOOL,
  70.                             'config' => [
  71.                                 'customFieldPosition' => 1,
  72.                                 'label' => [
  73.                                     'de-DE' => 'Nicht in Sitemap ausgeben',
  74.                                     'en-GB' => 'Exclude from Sitemap'
  75.                                 ],
  76.                             ]
  77.                         ],
  78.                         [
  79.                             'name' => 'pixup_google_sitemap_priority',
  80.                             'type' => CustomFieldTypes::FLOAT,
  81.                             'config' => [
  82.                                 'customFieldPosition' => 2,
  83.                                 'label' => [
  84.                                     'de-DE' => 'Priorität (0.0 - 1.0) (Default: 0.5)',
  85.                                     'en-GB' => 'Priority (0.0 - 1.0) (Default: 0.5)'
  86.                                 ],
  87.                             ]
  88.                         ],
  89.                         [
  90.                         'name' => 'pixup_google_sitemap_changefreq',
  91.                         'type' => CustomFieldTypes::SELECT,
  92.                             'config' => [
  93.                                 'customFieldPosition' => 3,
  94.                                 'componentName' => 'sw-single-select',
  95.                                 'customFieldType' => CustomFieldTypes::SELECT,
  96.                                 'label' => [
  97.                                     'de-DE' => 'Change Frequency (default: daily)',
  98.                                     'en-GB' => 'Change Frequency (default: daily)'
  99.                                 ],
  100.                                 'options' => [
  101.                                     [
  102.                                         'value' => 'always',
  103.                                         'label' => [
  104.                                             'de-DE' => 'always',
  105.                                             'en-GB' => 'always'
  106.                                         ],
  107.                                     ],
  108.                                     [
  109.                                         "value" => "hourly",
  110.                                         'label' => [
  111.                                             'de-DE' => 'hourly',
  112.                                             'en-GB' => 'hourly'
  113.                                         ],
  114.                                     ],
  115.                                     [
  116.                                         "value" => "daily",
  117.                                         'label' => [
  118.                                             'de-DE' => 'daily',
  119.                                             'en-GB' => 'daily'
  120.                                         ],
  121.                                     ],
  122.                                     [
  123.                                         "value" => "weekly",
  124.                                         'label' => [
  125.                                             'de-DE' => 'weekly',
  126.                                             'en-GB' => 'weekly'
  127.                                         ],
  128.                                     ],
  129.                                     [
  130.                                         "value" => "monthly",
  131.                                         'label' => [
  132.                                             'de-DE' => 'monthly',
  133.                                             'en-GB' => 'monthly'
  134.                                         ],
  135.                                     ],
  136.                                     [
  137.                                         "value" => "yearly",
  138.                                         'label' => [
  139.                                             'de-DE' => 'yearly',
  140.                                             'en-GB' => 'yearly'
  141.                                         ],
  142.                                     ],
  143.                                     [
  144.                                         "value" => "never",
  145.                                         'label' => [
  146.                                             'de-DE' => 'never',
  147.                                             'en-GB' => 'never'
  148.                                         ],
  149.                                     ],
  150.                                 ]
  151.                             ],
  152.                         ]
  153.                     ]
  154.                 ]
  155.             ], $context);
  156.         }
  157.     }
  158. }