<?php declare(strict_types=1);
namespace S360CMSManufacturer;
use Shopware\Core\Framework\Plugin;
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 S360CMSManufacturer extends Plugin
{
public function install(InstallContext $context): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->upsert([
[
'name' => 'custom_s360_manufacturers',
'config' => [
'label' => [
'en-GB' => 'S360 Manufacturers custom fields',
'de-De' => 'S360 Hersteller Zusatzfelder'
]
],
'customFields' => [
[
'name' => 's360_manufacturers_hide_in_overview',
'type' => CustomFieldTypes::BOOL,
'config' => [
'label' => [
'en-GB' => 'Hide on manufacturer page',
'de-De' => 'Auf Herstellerseite nicht anzeigen'
],
'componentName' => 'sw-checkbox-field',
'customFieldType' => 'checkbox',
'translated' => false,
'customFieldPosition' => 1
]
]
],
'relations' => [
[
'entityName' => 'product_manufacturer'
]
]
]
], $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', ['custom_s360_manufacturers']));
// EntitySearchResult
$result = $customFieldSetRepository->search($criteria, $context->getContext());
foreach ($result->getEntities() as $entity) {
$customFieldSetRepository->delete([[
'id' => $entity->getId()
]], $context->getContext());
}
}
}