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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nxs\NxsDeliveryTimesDisplay;
  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 NxsDeliveryTimesDisplay 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.         }
  34.     }
  35.     /**
  36.      * @return array
  37.      */
  38.     private function getFields(): array
  39.     {
  40.         return [[
  41.             'id' => Uuid::randomHex(),
  42.             'entityName' => 'product',
  43.             'customFieldSet' => [
  44.                 'name' => 'nxs_attributes',
  45.                 'config' => [
  46.                     'label' => [
  47.                         'de-DE' => 'NXS Attribute',
  48.                         'en-GB' => 'NXS Attributes'
  49.                     ],
  50.                     'translated' => true
  51.                 ],
  52.                 'customFields' => [
  53.                     [
  54.                         'name' => 'nxs_additional_delivery_time',
  55.                         'type' => CustomFieldTypes::TEXT,
  56.                         'config' => [
  57.                             'type' => 'text',
  58.                             'label' => [
  59.                                 'de-DE' => 'Lieferzeit',
  60.                                 'en-GB' => 'Delivery time'
  61.                             ],
  62.                             'placeholder' => [
  63.                                 'de-DE' => '0',
  64.                                 'en-GB' => '0'
  65.                             ],
  66.                             'componentName' => 'sw-field',
  67.                             'customFieldType' => 'text',
  68.                             'customFieldPosition' => 1
  69.                         ]
  70.                     ]
  71.                 ]
  72.             ]]
  73.         ];
  74.     }
  75. }