<?php declare(strict_types=1);
namespace BjerregaardTheme;
use Doctrine\DBAL\Driver\PDO\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Storefront\Framework\ThemeInterface;
class BjerregaardTheme extends Plugin implements ThemeInterface
{
public function boot(): void
{
parent::boot();
if (!$this->isActive()) {
return;
}
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
}
}
public function activate(ActivateContext $activateContext): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
//$this->installCustomFields($activateContext, $customFieldSetRepository);
parent::activate($activateContext); // TODO: Change the autogenerated stub
}
/** @phpstan-ignore-next-line */
private function installCustomFields(Plugin\Context\ActivateContext $context, ?object $customFieldSetRepository): void
{
/** @var Connection $connection */
$connection = $this->container->get('Doctrine\DBAL\Connection');
$customFieldSetRepository->upsert([[
'name' => 'bjerregaardcustomercustomfields',
'active' => true,
'global' => true,
'config' => [
'label' => [
'en-GB' => 'Bjerregaard Customer Custom fields'
],
],
'customFields' => $this->getCustomFields(),
'relations' => [
[
'entityName' => 'customer'
]
]
]], $context->getContext());
}
/**
* @return array<array<string, mixed>>
*/
private function getCustomFields(): array
{
return [
[
'name' => 'DiscountGroup',
'type' => CustomFieldTypes::TEXT,
'config' => [
'bordered' => false,
'label' => [
'en-GB' => 'Customer discount group'
],
'customFieldPosition' => 0
],
],
[
'name' => 'FreightCode',
'type' => CustomFieldTypes::TEXT,
'config' => [
'bordered' => false,
'label' => [
'en-GB' => 'Freight Code'
],
'customFieldPosition' => 1,
],
]
];
}
}