<?php declare(strict_types=1);
namespace Compra\InvoiceDispatchSW6;
use Compra\FoundationSW6\Core\System\CustomFieldService;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CompraInvoiceDispatchSW6 extends Plugin
{
public function build(ContainerBuilder $container): void
{
$container->setParameter('compra_invoice_dispatch_s_w6.plugin_dir', $this->getPath());
parent::build($container);
}
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->addCustomFields($installContext->getContext());
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
$this->addCustomFields($updateContext->getContext());
}
/**
* Function to create the custom fields for the plugin.
*
* @param $context
*/
public function addCustomFields($context): void
{
$customFieldService = $this->container->get(CustomFieldService::class);
if (!$customFieldService) {
return;
}
try {
$customFieldService->createOrUpdateCustomFieldSets([
[
'name' => 'compra_invoice_dispatch',
'config' => [
'label' => [
'de-DE' => 'COMPRA Rechnungsversand',
'en-GB' => 'COMPRA Invoice Dispatch'
]
],
'relations' => [
[
'entityName' => 'customer'
]
],
'customFields' => [
[
'name' => 'compra_invoice_mail_enabled',
'type' => 'bool',
'config' => [
'type' => 'checkbox',
'label' => [
'de-DE' => 'Rechnungsversand per E-Mail',
'en-GB' => 'Invoice dispatch by e-mail'
],
'helpText' => [
'de-DE' => 'Sollen Rechnungen per E-Mail versandt werden?',
'en-GB' => 'Should invoices be sent by e-mail?'
],
'componentName' => 'sw-field',
'customFieldType' => 'checkbox',
'customFieldPosition' => 0
]
],
[
'name' => 'compra_invoice_mail_address',
'type' => 'text',
'config' => [
'label' => [
'de-DE' => 'Rechnungs-E-Mail-Adresse',
'en-GB' => 'Invoice e-mail address'
],
'helpText' => [
'de-DE' => 'E-Mail-Adresse für den Rechnungsversannd',
'en-GB' => 'E-mail address for the invoice dispatch'
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 1
]
]
]
]], $context);
} catch (\Exception $e) {}
}
}