custom/plugins/NxsAdditionalProductPicture/src/NxsAdditionalProductPicture.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nxs\NxsAdditionalProductPicture;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  8. use Shopware\Core\Framework\Uuid\Uuid;
  9. use Shopware\Core\System\CustomField\CustomFieldTypes;
  10. class NxsAdditionalProductPicture extends Plugin
  11. {
  12.     /**
  13.      * @param ActivateContext $activateContext
  14.      * @throws \Exception
  15.      */
  16.     public function activate(ActivateContext $activateContext): void
  17.     {
  18.         $indexerMessageSender $this->container->get(EntityIndexerRegistry::class);
  19.         $indexerMessageSender->sendIndexingMessage(['product.indexer']);
  20.     }
  21.     /**
  22.      * @param Plugin\Context\InstallContext $installContext
  23.      * @throws InconsistentCriteriaIdsException
  24.      */
  25.     public function install(Plugin\Context\InstallContext $installContext): void
  26.     {
  27.         parent::install($installContext);
  28.         $criteria = new Criteria();
  29.         $criteria->setTerm('nxs_attributes');
  30.         $customSet $this->container->get('custom_field_set.repository')->search($criteria$installContext->getContext());
  31.         if ($customSet->getTotal() === 0) {
  32.             $this->container->get('custom_field_set_relation.repository')->create($this->getFields(), $installContext->getContext());
  33.         } else {
  34.             $this->container->get('custom_field_set_relation.repository')->create($this->getFields(), $installContext->getContext());
  35.         }
  36.     }
  37.     /**
  38.      * @return array
  39.      */
  40.     private function getFields(): array
  41.     {
  42.         return [[
  43.             'id' => Uuid::randomHex(),
  44.             'entityName' => 'product',
  45.             'customFieldSet' => [
  46.                 'name' => 'nxs_attributes',
  47.                 'config' => [
  48.                     'label' => [
  49.                         'de-DE' => 'NXS Attribute',
  50.                         'en-GB' => 'NXS Attributes'
  51.                     ],
  52.                     'translated' => true
  53.                 ],
  54.                 'customFields' => [
  55.                     [
  56.                         'name' => 'nxs_additional_product_picture',
  57.                         'type' => CustomFieldTypes::SELECT,
  58.                         'config' => [
  59.                             'type' => 'media',
  60.                             'label' => [
  61.                                 'de-DE' => 'Zusätzliches Bild',
  62.                                 'en-GB' => 'Additional picture'
  63.                             ],
  64.                             'placeholder' => [
  65.                                 'de-DE' => '0',
  66.                                 'en-GB' => '0'
  67.                             ],
  68.                             'componentName' => 'sw-field',
  69.                             'customFieldType' => 'media',
  70.                             'customFieldPosition' => 1
  71.                         ]
  72.                     ]
  73.                 ]
  74.             ]]
  75.         ];
  76.     }
  77. }