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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TemplaidChatGPT;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  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 TemplaidChatGPT extends Plugin
  11. {
  12.     public function activate(ActivateContext $activateContext): void
  13.     {
  14.         $this->addCustomFields($activateContext);
  15.         parent::activate($activateContext);
  16.     }
  17.     private function addCustomFields(ActivateContext $context): void
  18.     {
  19.         /** @var EntityRepository $customFieldSetRepository */
  20.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  21.         $criteria = new Criteria();
  22.         $criteria->addFilter(new EqualsFilter('name''templaid_chatgpt'));
  23.         $result $customFieldSetRepository->search($criteria$context->getContext());
  24.         if ($result->count() == 0) {
  25.             $customFieldSetId Uuid::randomHex();
  26.             $customFieldSetRepository->create([
  27.                 [
  28.                     'id' => $customFieldSetId,
  29.                     'name' => 'templaid_chatgpt',
  30.                     'config' => [
  31.                         'label' => [
  32.                             'en-GB' => 'Chat GPT'
  33.                         ]
  34.                     ],
  35.                     'customFields' => [
  36.                         [
  37.                             'id' => Uuid::randomHex(),
  38.                             'name' => 'templaid_chatgpt_details',
  39.                             'type' => CustomFieldTypes::HTML,
  40.                             'config' => [
  41.                                 'label' => [
  42.                                     'en-GB' => 'ChatGPT details',
  43.                                     'da-DK' => 'ChatGPT detaljer'
  44.                                 ],
  45.                                 'customFieldPosition' => 4,
  46.                                 'componentName' => 'sw-text-editor',
  47.                                 'customFieldType' => 'textEditor',
  48.                                 'helpText' => [
  49.                                     'en-GB' => 'Details to generate from',
  50.                                     'da-DK' => 'Detaljer til generering'
  51.                                 ],
  52.                                 'placeholder' => [
  53.                                     'en-GB' => 'Eg. For kids',
  54.                                     'da-DK' => 'Fx: T-shirt i god kvalitet. Til børn. Sjovt motiv.'
  55.                                 ],
  56.                             ],
  57.                             'active' => true,
  58.                             'customFieldSetId' => $customFieldSetId,
  59.                         ],
  60.                         [
  61.                             'id' => Uuid::randomHex(),
  62.                             'name' => 'templaid_chatgpt_description',
  63.                             'type' => CustomFieldTypes::HTML,
  64.                             'config' => [
  65.                                 'label' => [
  66.                                     'en-GB' => 'Generated Description',
  67.                                     'da-DK' => 'Genereret beskrivelse'
  68.                                 ],
  69.                                 'customFieldPosition' => 5,
  70.                                 'componentName' => 'sw-text-editor',
  71.                                 'customFieldType' => 'textEditor',
  72.                                 'helpText' => [
  73.                                     'en-GB' => 'Generated description based on product title',
  74.                                     'da-DK' => 'Genereret beskrivelse baseret på input og produktnavn'
  75.                                 ],
  76.                                 'placeholder' => [
  77.                                     'en-GB' => 'Some awesome AI generated text',
  78.                                     'da-DK' => 'En fantastisk AI tekst'
  79.                                 ],
  80.                             ],
  81.                             'active' => true,
  82.                             'customFieldSetId' => $customFieldSetId,
  83.                         ],
  84.                         [
  85.                             'id' => Uuid::randomHex(),
  86.                             'name' => 'templaid_chatgpt_meta_title',
  87.                             'type' => CustomFieldTypes::HTML,
  88.                             'config' => [
  89.                                 'label' => [
  90.                                     'en-GB' => 'Generated Meta Title',
  91.                                     'da-DK' => 'Genererede meta-titel'
  92.                                 ],
  93.                                 'customFieldPosition' => 7,
  94.                                 'componentName' => 'sw-text-editor',
  95.                                 'customFieldType' => 'textEditor',
  96.                                 'helpText' => [
  97.                                     'en-GB' => 'Generated meta title, should be max 56 chars',
  98.                                     'da-DK' => 'Genereret meta-titel baseret på input og produktnavn'
  99.                                 ],
  100.                                 'placeholder' => [
  101.                                     'en-GB' => 'Some awesome AI generated text',
  102.                                     'da-DK' => 'En fantastisk AI tekst'
  103.                                 ],
  104.                             ],
  105.                             'active' => true,
  106.                             'customFieldSetId' => $customFieldSetId,
  107.                         ],
  108.                         [
  109.                             'id' => Uuid::randomHex(),
  110.                             'name' => 'templaid_chatgpt_meta_description',
  111.                             'type' => CustomFieldTypes::HTML,
  112.                             'config' => [
  113.                                 'label' => [
  114.                                     'en-GB' => 'Generated Meta Description',
  115.                                     'da-DK' => 'Genererede meta-beskrivelse'
  116.                                 ],
  117.                                 'customFieldPosition' => 9,
  118.                                 'componentName' => 'sw-text-editor',
  119.                                 'customFieldType' => 'textEditor',
  120.                                 'helpText' => [
  121.                                     'en-GB' => 'Generated meta description based on generated description',
  122.                                     'da-DK' => 'Genereret meta-beskrivelse baseret på input og produktnavn'
  123.                                 ],
  124.                                 'placeholder' => [
  125.                                     'en-GB' => 'Some awesome AI generated text',
  126.                                     'da-DK' => 'En fantastisk AI tekst'
  127.                                 ],
  128.                             ],
  129.                             'active' => true,
  130.                             'customFieldSetId' => $customFieldSetId,
  131.                         ],
  132.                         [
  133.                             'id' => Uuid::randomHex(),
  134.                             'name' => 'templaid_chatgpt_seo_keywords',
  135.                             'type' => CustomFieldTypes::HTML,
  136.                             'config' => [
  137.                                 'label' => [
  138.                                     'en-GB' => 'Generated SEO Keywords',
  139.                                     'da-DK' => 'Genererede SEO nøgleord'
  140.                                 ],
  141.                                 'customFieldPosition' => 11,
  142.                                 'componentName' => 'sw-text-editor',
  143.                                 'customFieldType' => 'textEditor',
  144.                                 'helpText' => [
  145.                                     'en-GB' => 'Generated SEO keywords based on product generated description',
  146.                                     'da-DK' => 'Genererede SEO nøgleord baseret på input og produktnavn'
  147.                                 ],
  148.                                 'placeholder' => [
  149.                                     'en-GB' => 'Some awesome AI generated text',
  150.                                     'da-DK' => 'En fantastisk AI tekst'
  151.                                 ],
  152.                             ],
  153.                             'active' => true,
  154.                             'customFieldSetId' => $customFieldSetId,
  155.                         ]
  156.                     ],
  157.                     'relations' => [
  158.                         [
  159.                             'id' => Uuid::randomHex(),
  160.                             'customFieldSetId' => $customFieldSetId,
  161.                             'entityName' => 'product',
  162.                         ]
  163.                     ]
  164.                 ]
  165.             ], $context->getContext());
  166.         }
  167.     }
  168. }