<?php declare(strict_types=1);
namespace Compra\EnvironmentalDiscountSW6;
use Compra\FoundationSW6\Core\System\CustomFieldService;
use Shopware\Core\Framework\Context;
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 CompraEnvironmentalDiscountSW6 extends Plugin
{
public function build(ContainerBuilder $container): void
{
$container->setParameter('compra_environmental_discount_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 $context
*/
public function addCustomFields(Context $context): void
{
$customFieldService = $this->container->get(CustomFieldService::class);
if (!$customFieldService) {
return;
}
try {
$customFieldService->createOrUpdateCustomFields([
[
'name' => 'compra_environmental_discount_has_changed_to_mail',
'type' => CustomFieldTypes::BOOL
]
], $context);
} catch (\Exception $e) {}
}
}