<?php declare(strict_types=1);
namespace EnetSubshop;
use Shopware\Core\Framework\Context;
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;
class EnetSubshop extends Plugin
{
public function install(InstallContext $context): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->create(
[
[
'name' => 'enet_subshop',
'config' => [
'label' => [
'en-GB' => 'Subshop Einstellungen',
'de-DE' => 'Subshop Settings'
]
],
'customFields' => [
[
'name' => 'enet_frontendname',
'type' => CustomFieldTypes::TEXT,
'config' => [
'compoenentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Name Frontend',
'de-DE' => 'Name im Frontend'
]
],
'active' => true
],
[
'name' => 'enet_postalcode',
'type' => CustomFieldTypes::TEXT,
'config' => [
'compoenentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Postal Code',
'de-DE' => 'Postleitzahl'
]
],
'active' => true
],
[
'name' => 'enet_adress_street',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Adress Street + Number',
'de-DE' => 'Adresse Straße + Nummer'
],
],
'active' => true
],
[
'name' => 'enet_adress_opentimes',
'type' => CustomFieldTypes::HTML,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'textarea',
'label' => [
'en-GB' => 'Opening Times',
'de-DE' => 'Öffnungszeiten'
],
],
'active' => true
],
[
'name' => 'enet_adress_showasselection',
'type' => CustomFieldTypes::BOOL,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'switch',
'label' => [
'en-GB' => 'Show in Frontend as Select',
'de-DE' => 'Im Frontend als Auswahl als Subshop'
],
],
'active' => true
],
[
'name' => 'enet_subshop_gmaps_latlng',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Gooogle Maps Lat Lng (copy from adressline)',
'de-DE' => 'Google Maps Lat Lng (aus der Adresszeile kopieren)'
],
],
'active' => true
],
[
'name' => 'enet_subshop_logo',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Logo Url',
'de-DE' => 'Logo Url'
],
],
'active' => true
],
[
'name' => 'enet_subshop_hero',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'label' => [
'en-GB' => 'Hero Image',
'de-DE' => 'Hero Image'
],
],
'active' => true
]
],
'relations' => [
['entityName' => 'sales_channel'],
],
]
],
$context->getContext()
);
}
// todo: deinstallieren, hier muss eine id mit angegeben werden?
// zum löschen muss die id ermittelt werden und dann kann gelöscht werden
// besser wäre aber etwas wie update anstatt immer nur create
// quelle: https://bitbucket.basecom.de/projects/SHOP (fancyhover)
// democode:
// protected function removeCustomFieldSet(): void
// {
// /** @var EntityRepositoryInterface $customFieldSetRepository */
// $customFieldSetRepository = $this->container->get('custom_field_set.repository');
//
// $criteria = new Criteria();
// $criteria->addFilter(new EqualsFilter('name', 'kuborgh_fancy_hover'));
// $ids = $customFieldSetRepository->searchIds($criteria, Context::createDefaultContext());
//
// if ($ids) {
// $customFieldSetRepository->delete([['id' => $ids->getIds()[0]]], Context::createDefaultContext());
// }
// }
// public function uninstall(UninstallContext $context): void
// {
// $customFieldSetRepository = $this->container->get('custom_field_set.repository');
// $customFieldSetRepository->delete(
// [
// [
// 'name' => 'enet_subshop',
// 'customFields' => [
// ['name' => 'enet_postalcode'],
// ['name' => 'enet_adress_street'],
// ]
// ]
// ],
// $context->getContext()
// );
// }
}