<?php declare(strict_types=1);
namespace Cogi\Theme\Capskeeper;
use Shopware\Core\Framework\Context;
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\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\Aggregate\CustomFieldSet\CustomFieldSetEntity;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Storefront\Framework\ThemeInterface;
class CogiThemeCapskeeper extends Plugin implements ThemeInterface
{
public function getThemeConfigPath(): string
{
return 'theme.json';
}
/**
* @param InstallContext $installContext
*/
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->createCustomFieldSets();
}
/**
* @param UpdateContext $updateContext
*/
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
$this->createCustomFieldSets();
}
/**
* @param UninstallContext $uninstallContext
*/
public function uninstall(UninstallContext $uninstallContext): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'custom_cogi'));
/** @var CustomFieldSetEntity $customFieldSetEntity */
$customFieldSetEntity = $customFieldSetRepository->search($criteria, $uninstallContext->getContext())->first();
if (isset($customFieldSetEntity)) {
$customFieldSetRepository->delete([['id' => $customFieldSetEntity->getId()]], $uninstallContext->getContext());
}
parent::uninstall($uninstallContext);
}
private function createCustomFieldSets(): void {
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
try {
$customFieldSetRepository->create([
[
'name' => 'custom_cogi',
'config' => [
'label' => [
'de-DE' => 'Zusätzliche Felder Theme',
'en-GB' => 'Additional field Theme'
]
],
'relations' => array_map(function ($entity) {
return ['entityName' => $entity];
}, ['product']),
'customFields' => [
[
'name' => 'custom_cogi_description_top',
'type' => CustomFieldTypes::HTML,
'config' => [
'componentName' => 'sw-text-editor',
'customFieldType' => CustomFieldTypes::HTML,
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Zusätzliche Produktbeschreibung oben',
'de-DE' => 'Additional Productdescription top'
],
'translated' => true
]
],
[
'name' => 'custom_cogi_description_bottom',
'type' => CustomFieldTypes::HTML,
'config' => [
'componentName' => 'sw-text-editor',
'customFieldType' => CustomFieldTypes::HTML,
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Zusätzliche Produktbeschreibung unten',
'de-DE' => 'Additional Productdescription bottom'
],
'translated' => true
]
],
[
'name' => 'custom_cogi_delivery',
'type' => CustomFieldTypes::HTML,
'config' => [
'componentName' => 'sw-text-editor',
'customFieldType' => CustomFieldTypes::HTML,
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Zusätzliche Versandinformationen',
'de-DE' => 'Additional shipping information'
],
'translated' => true
]
],
[
'name' => 'custom_cogi_product_listing_description',
'type' => CustomFieldTypes::HTML,
'config' => [
'componentName' => 'sw-text-editor',
'customFieldType' => CustomFieldTypes::HTML,
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Description for listing',
'de-DE' => 'Beschreibung, welche im listing angezeigt wird'
],
'translated' => true
]
],
]
]
], Context::createDefaultContext());
} catch (\Exception $e) {
}
}
}