<?php declare(strict_types=1);
namespace TemplaidChatGPT;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class TemplaidChatGPT extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
$this->addCustomFields($activateContext);
parent::activate($activateContext);
}
private function addCustomFields(ActivateContext $context): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'templaid_chatgpt'));
$result = $customFieldSetRepository->search($criteria, $context->getContext());
if ($result->count() == 0) {
$customFieldSetId = Uuid::randomHex();
$customFieldSetRepository->create([
[
'id' => $customFieldSetId,
'name' => 'templaid_chatgpt',
'config' => [
'label' => [
'en-GB' => 'Chat GPT'
]
],
'customFields' => [
[
'id' => Uuid::randomHex(),
'name' => 'templaid_chatgpt_details',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'en-GB' => 'ChatGPT details',
'da-DK' => 'ChatGPT detaljer'
],
'customFieldPosition' => 4,
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'helpText' => [
'en-GB' => 'Details to generate from',
'da-DK' => 'Detaljer til generering'
],
'placeholder' => [
'en-GB' => 'Eg. For kids',
'da-DK' => 'Fx: T-shirt i god kvalitet. Til børn. Sjovt motiv.'
],
],
'active' => true,
'customFieldSetId' => $customFieldSetId,
],
[
'id' => Uuid::randomHex(),
'name' => 'templaid_chatgpt_description',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'en-GB' => 'Generated Description',
'da-DK' => 'Genereret beskrivelse'
],
'customFieldPosition' => 5,
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'helpText' => [
'en-GB' => 'Generated description based on product title',
'da-DK' => 'Genereret beskrivelse baseret på input og produktnavn'
],
'placeholder' => [
'en-GB' => 'Some awesome AI generated text',
'da-DK' => 'En fantastisk AI tekst'
],
],
'active' => true,
'customFieldSetId' => $customFieldSetId,
],
[
'id' => Uuid::randomHex(),
'name' => 'templaid_chatgpt_meta_title',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'en-GB' => 'Generated Meta Title',
'da-DK' => 'Genererede meta-titel'
],
'customFieldPosition' => 7,
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'helpText' => [
'en-GB' => 'Generated meta title, should be max 56 chars',
'da-DK' => 'Genereret meta-titel baseret på input og produktnavn'
],
'placeholder' => [
'en-GB' => 'Some awesome AI generated text',
'da-DK' => 'En fantastisk AI tekst'
],
],
'active' => true,
'customFieldSetId' => $customFieldSetId,
],
[
'id' => Uuid::randomHex(),
'name' => 'templaid_chatgpt_meta_description',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'en-GB' => 'Generated Meta Description',
'da-DK' => 'Genererede meta-beskrivelse'
],
'customFieldPosition' => 9,
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'helpText' => [
'en-GB' => 'Generated meta description based on generated description',
'da-DK' => 'Genereret meta-beskrivelse baseret på input og produktnavn'
],
'placeholder' => [
'en-GB' => 'Some awesome AI generated text',
'da-DK' => 'En fantastisk AI tekst'
],
],
'active' => true,
'customFieldSetId' => $customFieldSetId,
],
[
'id' => Uuid::randomHex(),
'name' => 'templaid_chatgpt_seo_keywords',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => [
'en-GB' => 'Generated SEO Keywords',
'da-DK' => 'Genererede SEO nøgleord'
],
'customFieldPosition' => 11,
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'helpText' => [
'en-GB' => 'Generated SEO keywords based on product generated description',
'da-DK' => 'Genererede SEO nøgleord baseret på input og produktnavn'
],
'placeholder' => [
'en-GB' => 'Some awesome AI generated text',
'da-DK' => 'En fantastisk AI tekst'
],
],
'active' => true,
'customFieldSetId' => $customFieldSetId,
]
],
'relations' => [
[
'id' => Uuid::randomHex(),
'customFieldSetId' => $customFieldSetId,
'entityName' => 'product',
]
]
]
], $context->getContext());
}
}
}