<?php declare(strict_types=1);
namespace ProxaEmployee;
use Shopware\Core\Checkout\Customer\CustomerDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class ProxaEmployee extends Plugin
{
const EMPLOYEE_SET_NAME = 'employee';
const CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID = 'ProxaEmployee_mitarbeiterID';
const CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER = 'ProxaEmployee_personalNumber';
/**
* @param ActivateContext $activateContext
* @return void
*/
public function activate(ActivateContext $activateContext): void
{
$this->makeCustomFieldSet();
}
/**
* @param UpdateContext $updateContext
* @return void
*/
public function update(UpdateContext $updateContext): void
{
$this->makeCustomFieldSet();
}
/**
* @param DeactivateContext $deactivateContext
* @return void
*/
public function deactivate(DeactivateContext $deactivateContext): void
{
$this->deleteCustomFieldSet();
}
/**
* @return void
*/
private function makeCustomFieldSet()
{
$this->deleteCustomFieldSet();
$this->container->get('custom_field_set.repository')->upsert([$this->getStockCustomFieldSet()], Context::createDefaultContext());
}
/**
* @return void
*/
private function deleteCustomFieldSet()
{
$this->container->get('custom_field_set.repository')->delete([['id' => md5(self::EMPLOYEE_SET_NAME)]], Context::createDefaultContext());
}
/**
* @return array
*/
private function getStockCustomFieldSet(): array
{
return [
'id' => md5(self::EMPLOYEE_SET_NAME),
'name' => self::EMPLOYEE_SET_NAME,
'active' => true,
'config' => [
'label' => [
'de-DE' => 'Employee',
'en-GB' => 'Employee'
]
],
'relations' => [
['entityName' => CustomerDefinition::ENTITY_NAME]
],
'customFields' => [
[
'id' => md5(self::CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID),
'name' => self::CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID,
'type' => CustomFieldTypes::TEXT,
'active' => true,
'config' => [
'customFieldPosition' => 0,
'customFieldType' => 'text',
'label' => [
'de-DE' => 'Mitarbeiter ID',
'en-GB' => 'Mitarbeiter ID',
],
]
], [
'id' => md5(self::CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER),
'name' => self::CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER,
'type' => CustomFieldTypes::TEXT,
'active' => true,
'config' => [
'customFieldPosition' => 0,
'customFieldType' => 'text',
'label' => [
'de-DE' => 'Personal Number',
'en-GB' => 'Personal Number',
],
]
],
]
];
}
}