<?php
declare(strict_types=1);
namespace GrimmTheme;
use Shopware\Core\Framework\Plugin;
use Shopware\Storefront\Framework\ThemeInterface;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
class GrimmTheme extends Plugin implements ThemeInterface
{
public const FIELDSETNAME = 'grimm_customFields';
public const FIELDSETLABEL = 'GRIMM Custom Fields';
public const ACCOUNT_TYPE_INSTITUTION = "institution";
public function getThemeConfigPath(): string
{
return 'theme.json';
}
public function install(InstallContext $context): void
{
// Grimm fields
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->create([[
'name' => self::FIELDSETNAME,
'config' => [
'label' => self::FIELDSETLABEL
],
'customFields' => [
[
'name' => 'grimm_customFields_short_desc',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => 'Produkt Kurzbeschreibung',
'componentName' => 'sw-text-field',
'customFieldType' => 'text',
'translated' => false
]
],
[
'name' => 'grimm_customFields_uvp',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'label' => 'UVP',
'componentName' => 'sw-number-field',
'customFieldType' => 'number',
'translated' => false,
'numberType' => 'float'
]
],
[
'name' => 'grimm_customFields_guarantee',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => 'Garantie',
'componentName' => 'sw-text-field',
'customFieldType' => 'text',
'translated' => false
]
],
[
'name' => 'grimm_customFields_replacement',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => 'Ersatzteile',
'componentName' => 'sw-checkbox-field',
'customFieldType' => 'checkbox',
'translated' => false
]
],
[
'name' => 'grimm_customfields_productRequest_only',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => 'Auf Anfrage',
'componentName' => 'sw-checkbox-field',
'customFieldType' => 'checkbox',
'translated' => false
]
],
[
'name' => 'grimm_customfields_productRequest_showUVP',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => 'UVP anzeigen wenn auf Anfrage',
'componentName' => 'sw-checkbox-field',
'customFieldType' => 'checkbox',
'translated' => false
]
],
[
'name' => 'grimm_customFields_additionalDeliveryInfo',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => 'Zusatzinfo Lieferung',
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'translated' => false
]
]
],
'relations' => [
[
'entityName' => 'product'
]
]
]], $context->getContext());
// downloads
$customFieldSetRepository->create([
[
'name' => 'custom_product_downloads',
'config' => [
'label' => [
'en-GB' => 'Downloads',
'de-DE' => 'Downloads'
]
],
'customFields' => [
[
'name' => 'custom_product_downloads_name1',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => '1. Download Name',
'translated' => false,
'customFieldPosition' => 1
],
],
[
'name' => 'custom_product_downloads_media1',
'type' => CustomFieldTypes::MEDIA,
'config' => [
'label' => '1. Download Media',
'componentName' => 'sw-media-field',
'customFieldType' => 'media',
'translated' => false,
'customFieldPosition' => 2
]
],
[
'name' => 'custom_product_downloads_name2',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => '2. Download Name',
'translated' => false,
'customFieldPosition' => 3
],
],
[
'name' => 'custom_product_downloads_media2',
'type' => CustomFieldTypes::MEDIA,
'config' => [
'label' => '2. Download Media',
'componentName' => 'sw-media-field',
'customFieldType' => 'media',
'translated' => false,
'customFieldPosition' => 4
]
],
[
'name' => 'custom_product_downloads_name3',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => '3. Download Name',
'translated' => false,
'customFieldPosition' => 5
],
],
[
'name' => 'custom_product_downloads_media3',
'type' => CustomFieldTypes::MEDIA,
'config' => [
'label' => '3. Download Media',
'componentName' => 'sw-media-field',
'customFieldType' => 'media',
'translated' => false,
'customFieldPosition' => 6
]
],
[
'name' => 'custom_product_downloads_name4',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => '4. Download Name',
'translated' => false,
'customFieldPosition' => 7
],
],
[
'name' => 'custom_product_downloads_media4',
'type' => CustomFieldTypes::MEDIA,
'config' => [
'label' => '4. Download Media',
'componentName' => 'sw-media-field',
'customFieldType' => 'media',
'translated' => false,
'customFieldPosition' => 8
]
],
[
'name' => 'custom_product_downloads_name5',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => '5. Download Name',
'translated' => false,
'customFieldPosition' => 9
],
]
],
'relations' => [
[
'entityName' => 'product'
]
]
]
], $context->getContext());
// newsletter
$customFieldSetRepository->create([
[
'name' => 'custom_category_newsletter',
'config' => [
'label' => [
'en-GB' => 'Newsletter Column',
'de-DE' => 'Newsletter Spalte'
]
],
'customFields' => [
[
'name' => 'custom_category_newsletter_column',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => 'Newsletter Editor (ONLY EDIT AS HTML)',
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'translated' => false
]
]
],
'relations' => [
[
'entityName' => 'category'
]
]
]
], $context->getContext());
// clerk
$customFieldSetRepository->create([
[
'name' => 'custom_clerk',
'config' => [
'label' => [
'en-GB' => 'Clerk',
'de-DE' => 'Clerk'
]
],
'customFields' => [
[
'name' => 'custom_clerk_net_price',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'label' => 'Nettopreis',
'componentName' => 'sw-number-field',
'customFieldType' => 'number',
'translated' => false,
'numberType' => 'float'
]
],
[
'name' => 'custom_clerk_vat',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'label' => 'Steuersatz',
'componentName' => 'sw-number-field',
'customFieldType' => 'number',
'translated' => false,
'numberType' => 'float'
]
],
[
'name' => 'custom_clerk_shipping_time',
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => 'Lieferzeit',
'translated' => false
]
]
],
'relations' => [
[
'entityName' => 'product'
]
]
]
], $context->getContext());
// one field here was manually created by clients themselves within shop - wont be available on newinstalled theme
$customFieldSetRepository->create([
[
'name' => 'custom_payment',
'config' => [
'label' => [
'en-GB' => 'Extended Data for Payment methods',
'de-DE' => 'Erweiterte Daten für Zahlungsarten'
]
],
'customFields' => [
[
'name' => 'custom_payment_active_payment_method',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => 'Aktive Methode Beschreibung',
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'translated' => false
]
],
[
'name' => 'custom_payment_description',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => 'Beschreibung',
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'translated' => false
]
]
],
'relations' => [
[
'entityName' => 'payment_method'
]
]
]
], $context->getContext());
}
public function uninstall(UninstallContext $context): void
{
if ($context->keepUserData()) {
return;
}
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsAnyFilter('name', [self::FIELDSETNAME, 'custom_product_downloads', 'custom_category_newsletter', 'custom_clerk', 'custom_payment']));
// EntitySearchResult
$result = $customFieldSetRepository->search($criteria, $context->getContext());
foreach ($result->getEntities() as $entity) {
$customFieldSetRepository->delete([[
'id' => $entity->getId()
]], $context->getContext());
}
}
}