custom/plugins/BilobaManufacturerPro/src/BilobaManufacturerPro.php line 15

Open in your IDE?
  1. <?php
  2. namespace Biloba\ManufacturerPro;
  3. use Biloba\ManufacturerPro\Core\BilobaManufacturerProPluginHelper;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Context;
  11. use Shopware\Core\System\CustomField\CustomFieldEntity;
  12. class BilobaManufacturerPro extends Plugin
  13. {
  14.     public function install(InstallContext $context): void
  15.     {
  16.         $this->setupCustomAttributes($context->getContext());
  17.     }
  18.     public function update(UpdateContext $context): void
  19.     {
  20.         $this->setupCustomAttributes($context->getContext());
  21.     }
  22.     public function activate(ActivateContext $context): void
  23.     {
  24.         $this->setupCustomAttributes($context->getContext());
  25.         parent::activate($context);
  26.     }
  27.     public function deactivate(DeactivateContext $context): void
  28.     {
  29.        parent::deactivate($context);
  30.     }
  31.     public function setupCustomAttributes(Context $context): void {
  32.         // generate UUID (https://www.guidgenerator.com/online-guid-generator.aspx)
  33.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  34.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  35.         $idCustomFieldSetManufacturerInfo 'c2a8e865733049e6adfe3e0e8d31d43c';
  36.         $idCustomFieldSetManufacturerInfo = [
  37.             'id' => $idCustomFieldSetManufacturerInfo,
  38.             'name' => 'biloba_manufacturer_pro',
  39.             'config' => ["label" => ["en-GB" => "Biloba Manufacturer Pro""de-DE" => "Biloba Manufacturer Pro"], "translated" => "true"],
  40.             'active' => boolval(1)
  41.         ];
  42.         $customFieldSetRepository->upsert([$idCustomFieldSetManufacturerInfo], $context);
  43.         /** @var EntityRepositoryInterface $customFieldSetRelationRepository */
  44.         $customFieldSetRelationRepository $this->container->get('custom_field_set_relation.repository');
  45.         $data = [
  46.            'id' => '45aeecb576324ee6945d159d581d884c',
  47.            'customFieldSet' => $idCustomFieldSetManufacturerInfo,
  48.            'entityName' => 'product_manufacturer'
  49.         ];
  50.         
  51.         $customFieldSetRelationRepository->upsert([$data] , $context);
  52.         /** @var EntityRepositoryInterface $customFieldRepository */
  53.         $customFieldRepository $this->container->get('custom_field.repository'); 
  54.         $data = [
  55.             // Inside manufacturer info
  56.             [
  57.                 'id' => '850d48abfaca4cd8989c5dafbfdb45e4',
  58.                 'name' => 'biloba_manufacturer_pro_hide_manufacturer_in_manufacturerlist',
  59.                 'type' => 'bool',
  60.                 'config' => ["label" => ["en-GB" => "Hide Manufacturer in Manufacturerlist""de-DE" => "Hersteller in Herstellerliste verbergen"], "helpText" => ["en-GB" => null"de-DE" => null], "componentName" => "sw-field""customFieldType" => "switch""customFieldPosition" => 1],
  61.                 'active' => boolval(1),
  62.                 'customFieldSet' => $idCustomFieldSetManufacturerInfo
  63.             ],
  64.             [
  65.                 'id' => '5a176807c86347c08a52ed13d1583ef2',
  66.                 'name' => 'biloba_manufacturer_pro_highlight_manufacturer',
  67.                 'type' => 'bool',
  68.                 'config' => ["label" => ["en-GB" => "Highlight Manufacturer""de-DE" => "Hersteller hervorheben"], "helpText" => ["en-GB" => null"de-DE" => null], "componentName" => "sw-field""customFieldType" => "switch""customFieldPosition" => 2],
  69.                 'active' => boolval(1),
  70.                 'customFieldSet' => $idCustomFieldSetManufacturerInfo
  71.             ],
  72.             [
  73.                 'id' => 'd734fb9322ed4664b25405251b36d5c7',
  74.                 'name' => 'biloba_manufacturer_pro_select_color_for_highlighting_manufacturer',
  75.                 'type' => 'colorpicker',
  76.                 'config' => ["label" => ["en-GB" => "Select color for highlighting Manufacturer""de-DE" => "Farbauswahl für das Hervorheben des Herstellers"], "helpText" => ["en-GB" => null"de-DE" => null], "componentName" => "sw-field""customFieldType" => "colorpicker""customFieldPosition" => 3],
  77.                 'active' => boolval(1),
  78.                 'customFieldSet' => $idCustomFieldSetManufacturerInfo
  79.             ],
  80.             
  81.         ];
  82.     
  83.         $customFieldRepository->upsert($data$context);
  84.     }
  85.     public function removeCustomAttributes(Context $context): void {
  86.         //Removing custom_field_set
  87.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  88.         $customFieldSetRepository ->delete(
  89.             [
  90.                 ['id' => 'c2a8e865733049e6adfe3e0e8d31d43c'],
  91.             ],
  92.             $context
  93.         );
  94.     }
  95.     public function uninstall(UninstallContext $context): void
  96.     {
  97.         parent::uninstall($context);
  98.         if ($context->keepUserData()) {
  99.             return;
  100.         }
  101.         $this->removeCustomAttributes($context->getContext());
  102.         BilobaManufacturerProPluginHelper::removeCmsBlocks($this->container$context->getContext(), [
  103.             'biloba-block-manufacturer-list'
  104.         ]);
  105.         BilobaManufacturerProPluginHelper::removeCmsBlocks($this->container$context->getContext(), [
  106.             'biloba-block-manufacturer-image-grid'
  107.         ]);
  108.         // Delete by type and not by slot
  109.         BilobaManufacturerProPluginHelper::removeCmsSlots($this->container$context->getContext(), [
  110.             'biloba-element-manufacturer-list'
  111.         ]);
  112.         BilobaManufacturerProPluginHelper::removeCmsSlots($this->container$context->getContext(), [
  113.             'biloba-block-manufacturer-image-grid'
  114.         ]);
  115.     }
  116. }