<?php declare(strict_types=1);
namespace TigerMedia\General\TigerRequestDeliveryDate;
use Doctrine\DBAL\Driver\PDO\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class TigerRequestDeliveryDate extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$this->installCustomFieldsForProduct($activateContext, $customFieldSetRepository);
parent::activate($activateContext);
}
private function installCustomFieldsForProduct(Plugin\Context\ActivateContext $context, ?object $customFieldSetRepository): void
{
/** @var Connection $connection */
$connection = $this->container->get('Doctrine\DBAL\Connection');
$customFieldSetRepository->upsert([[
'id' => Uuid::fromStringToHex('tigermediarequestdeliverydate'),
'name' => 'tigermediarequestdeliverydate',
'active' => true,
'config' => [
'label' => [
'en-GB' => 'Tiger Request Delivery Date'
],
],
'customFields' => $this->getOrderCustomFields(),
'relations' => [
[
'entityName' => 'order'
]
]
]], $context->getContext());
}
/**
* @return array<mixed>
*/
private function getOrderCustomFields(): array
{
return [
[
'id' => Uuid::fromStringToHex('tigermediarequestdelivery'),
'name' => 'tigermediarequestdelivery',
'type' => CustomFieldTypes::TEXT,
'config' => [
'bordered' => false,
'label' => [
'en-GB' => 'Requested delivery date'
],
'customFieldPosition' => 0,
'helpText' => [
'en-GB' => 'Requested delivery date'
],
],
]
];
}
}