<?php declare(strict_types=1);
namespace DonCarneTheme;
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;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class DonCarneTheme extends Plugin implements ThemeInterface
{
public function install(InstallContext $context): void {
$customFieldSetRepository = $this->container->get("custom_field_set.repository");
$customFieldSetRepository->create([
[
'name' => 'doncarne_product_custom_fields',
'config' => [
'label' => [
'de-DE' => 'Doncarne Produkt Zusatzfelder',
'en-GB' => 'Doncarne Product Custom Fields'
]
],
'customFields' => [
[
'name' => 'doncarne_product_surprise_box',
'type' => CustomFieldTypes::SWITCH,
'config' => [
'label' => [
'en-GB' => 'Surprise Box',
'de-De' => 'Surprise Box'
],
'componentName' => 'sw-switch-field',
'customFieldType' => 'switch',
'translated' => false
]
],
[
'name' => 'doncarne_product_usps',
'type' => CustomFieldTypes::HTML,
'config' => [
'label' => 'USPs',
'componentName' => 'sw-text-editor',
'customFieldType' => 'textEditor',
'translated' => true
]
],
[
'name' => 'doncarne_product_delivery_product_state',
'type' => CustomFieldTypes::JSON,
'config' => [
'label' => [
'en-GB' => 'Delivery Type',
'de-De' => 'Lieferart'
],
'componentName' => 'sw-multi-select',
'customFieldType' => 'select',
'customFieldPosition' => 1,
'options' => [
[
'value' => 'frozen',
'label' => [
'de-DE' => 'Gefroren',
'en-GB' => 'Frozen'
]
],
[
'value' => 'fresh',
'label' => [
'de-DE' => 'Frischware',
'en-GB' => 'Fresh'
]
]
]
]
]
],
'relations' => [
[
'entityName' => 'product'
]
]
],
[
'name' => 'doncarne_category_custom_fields',
'config' => [
'label' => [
'de-DE' => 'Doncarne Kategorie Zusatzfelder',
'en-GB' => 'Doncarne Category Custom Fields'
]
],
'customFields' => [
[
'name' => 'doncarne_category_buy_widget_theme',
'type' => CustomFieldTypes::JSON,
'config' => [
'label' => [
'en-GB' => 'Productdetail buy widget theme',
'de-De' => 'Produktseite Kaufbox Theme'
],
'componentName' => 'sw-single-select',
'customFieldType' => 'select',
'customFieldPosition' => 1,
'options' => [
[
'value' => 'light',
'label' => [
'de-DE' => 'Hell',
'en-GB' => 'Light'
]
],
[
'value' => 'dark',
'label' => [
'de-DE' => 'Dunkel',
'en-GB' => 'Dark'
]
]
]
]
],
[
'name' => 'doncarne_category_hide_mobile',
'type' => CustomFieldTypes::SWITCH,
'config' => [
'label' => [
'en-GB' => 'Hide in mobile',
'de-De' => 'Mobil ausblenden'
],
'componentName' => 'sw-switch-field',
'customFieldType' => 'switch',
'translated' => false
]
],
[
'name' => 'doncarne_category_special_menu_display',
'type' => CustomFieldTypes::SWITCH,
'config' => [
'label' => 'Beliebte Themen Menu Look',
'componentName' => 'sw-switch-field',
'customFieldType' => 'switch',
'translated' => false
]
]
],
'relations' => [
[
'entityName' => 'category'
]
]
]
], $context->getContext());
// unclear how CustomFieldTypes::ENTITY can be created, doncarne_category_custom_fields_special_menu_extra_categories added via admin
}
public function uninstall(UninstallContext $context): void {
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsAnyFilter('name', ['doncarne_product_custom_fields', 'doncarne_category_custom_fields']));
// EntitySearchResult
$result = $customFieldSetRepository->search($criteria, $context->getContext());
foreach ($result->getEntities() as $entity) {
$customFieldSetRepository->delete([[
'id' => $entity->getId()
]], $context->getContext());
}
}
}