custom/plugins/ProxaEmployee/src/ProxaEmployee.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ProxaEmployee;
  3. use Shopware\Core\Checkout\Customer\CustomerDefinition;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. use Shopware\Core\System\CustomField\CustomFieldTypes;
  10. class ProxaEmployee extends Plugin
  11. {
  12.     const EMPLOYEE_SET_NAME 'employee';
  13.     const CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID 'ProxaEmployee_mitarbeiterID';
  14.     const CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER 'ProxaEmployee_personalNumber';
  15.     /**
  16.      * @param ActivateContext $activateContext
  17.      * @return void
  18.      */
  19.     public function activate(ActivateContext $activateContext): void
  20.     {
  21.         $this->makeCustomFieldSet();
  22.     }
  23.     /**
  24.      * @param UpdateContext $updateContext
  25.      * @return void
  26.      */
  27.     public function update(UpdateContext $updateContext): void
  28.     {
  29.         $this->makeCustomFieldSet();
  30.     }
  31.     /**
  32.      * @param DeactivateContext $deactivateContext
  33.      * @return void
  34.      */
  35.     public function deactivate(DeactivateContext $deactivateContext): void
  36.     {
  37.         $this->deleteCustomFieldSet();
  38.     }
  39.     /**
  40.      * @return void
  41.      */
  42.     private function makeCustomFieldSet()
  43.     {
  44.         $this->deleteCustomFieldSet();
  45.         $this->container->get('custom_field_set.repository')->upsert([$this->getStockCustomFieldSet()], Context::createDefaultContext());
  46.     }
  47.     /**
  48.      * @return void
  49.      */
  50.     private function deleteCustomFieldSet()
  51.     {
  52.         $this->container->get('custom_field_set.repository')->delete([['id' => md5(self::EMPLOYEE_SET_NAME)]], Context::createDefaultContext());
  53.     }
  54.     /**
  55.      * @return array
  56.      */
  57.     private function getStockCustomFieldSet(): array
  58.     {
  59.         return [
  60.             'id' => md5(self::EMPLOYEE_SET_NAME),
  61.             'name' => self::EMPLOYEE_SET_NAME,
  62.             'active' => true,
  63.             'config' => [
  64.                 'label' => [
  65.                     'de-DE' => 'Employee',
  66.                     'en-GB' => 'Employee'
  67.                 ]
  68.             ],
  69.             'relations' => [
  70.                 ['entityName' => CustomerDefinition::ENTITY_NAME]
  71.             ],
  72.             'customFields' => [
  73.                 [
  74.                     'id' => md5(self::CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID),
  75.                     'name' => self::CUSTOMER_CUSTOM_FIELD_MITARBEITER_ID,
  76.                     'type' => CustomFieldTypes::TEXT,
  77.                     'active' => true,
  78.                     'config' => [
  79.                         'customFieldPosition' => 0,
  80.                         'customFieldType' => 'text',
  81.                         'label' => [
  82.                             'de-DE' => 'Mitarbeiter ID',
  83.                             'en-GB' => 'Mitarbeiter ID',
  84.                         ],
  85.                     ]
  86.                 ], [
  87.                     'id' => md5(self::CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER),
  88.                     'name' => self::CUSTOMER_CUSTOM_FIELD_PERSONAL_NUMBER,
  89.                     'type' => CustomFieldTypes::TEXT,
  90.                     'active' => true,
  91.                     'config' => [
  92.                         'customFieldPosition' => 0,
  93.                         'customFieldType' => 'text',
  94.                         'label' => [
  95.                             'de-DE' => 'Personal Number',
  96.                             'en-GB' => 'Personal Number',
  97.                         ],
  98.                     ]
  99.                 ],
  100.             ]
  101.         ];
  102.     }
  103. }