custom/plugins/WbfkImportExport/src/WbfkImportExport.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Wbfk\ImportExport;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. class WbfkImportExport extends Plugin
  9. {
  10.     /**
  11.      * @param ActivateContext $activateContext
  12.      */
  13.     public function activate(ActivateContext $activateContext): void
  14.     {
  15.         /** @var EntityRepository $customFieldSetRepository */
  16.         $customFieldSetRepository $this->container->get(
  17.             'custom_field_set.repository'
  18.         );
  19.         $fieldSets $this->getCustomFieldSets();
  20.         foreach ($fieldSets as $fieldSet) {
  21.             $customFieldSetRepository->upsert(
  22.                 [$fieldSet],
  23.                 $activateContext->getContext()
  24.             );
  25.         }
  26.     }
  27.     /**
  28.      * @return array
  29.      */
  30.     private function getCustomFieldSets(): array
  31.     {
  32.         $fieldsets = [];
  33.         $position 10000;
  34.         $fieldsets[] = [
  35.             'id' => 'a624bf80beef4696abeb8b09e223e6c5',
  36.             'name' => 'wbfk_category_data',
  37.             'active' => true,
  38.             'global' => true,
  39.             'config' => [
  40.                 'translated' => true,
  41.                 'label' => [
  42.                     'en-GB' => 'WBFK Import - Custom fields for categories',
  43.                     'de-DE' => 'WBFK Import - Freitextfelder für Kategorien',
  44.                 ],
  45.             ],
  46.             'customFields' => [
  47.                 [
  48.                     'id' => '9bf2e5f60fd046bf8977998a635ff861',
  49.                     'name' => 'wbfk_category_oxid_id',
  50.                     'type' => CustomFieldTypes::TEXT,
  51.                     'config' => [
  52.                         'customFieldPosition' => $position++,
  53.                         'label' => [
  54.                             'en-GB' => 'Oxid category ID',
  55.                             'de-DE' => 'Oxid Kategorie ID',
  56.                         ],
  57.                     ],
  58.                 ],
  59.                 [
  60.                     'id' => 'be6f3a96eea64bcd924868acc18bb16e',
  61.                     'name' => 'wbfk_topsellerTreshold',
  62.                     'type' => CustomFieldTypes::FLOAT,
  63.                     'config' => [
  64.                         'customFieldPosition' => $position++,
  65.                         'label' => [
  66.                             'en-GB' => 'Number of sold units from which a product is marked as top seller',
  67.                             'de-DE' => 'Anzahl notwendiger verkaufter Stück, ab denen ein Produkt als Topseller markiert wird',
  68.                         ],
  69.                     ],
  70.                 ],
  71.             ],
  72.             'relations' => [
  73.                 [
  74.                     'id' => '438863628a7f499ca6d6c602c4b68d70',
  75.                     'entityName' => 'category',
  76.                 ],
  77.             ],
  78.         ];
  79.         $position 10000;
  80.         $fieldsets[] = [
  81.             'id' => 'd3939f14c5f545d98ecb02fe06aa0590',
  82.             'name' => 'wbfk_customer_data',
  83.             'active' => true,
  84.             'global' => true,
  85.             'config' => [
  86.                 'translated' => true,
  87.                 'label' => [
  88.                     'en-GB' => 'WBFK Import - Custom fields for customers',
  89.                     'de-DE' => 'WBFK Import - Freitextfelder für Kunden',
  90.                 ],
  91.             ],
  92.             'customFields' => [
  93.                 [
  94.                     'id' => '87515dac1402485db3043c30cfc3c9aa',
  95.                     'name' => 'wbfk_customer_oxid_id',
  96.                     'type' => CustomFieldTypes::TEXT,
  97.                     'config' => [
  98.                         'customFieldPosition' => $position++,
  99.                         'label' => [
  100.                             'en-GB' => 'Oxid customer ID',
  101.                             'de-DE' => 'Oxid Kunden ID',
  102.                         ],
  103.                     ],
  104.                 ],
  105.             ],
  106.             'relations' => [
  107.                 [
  108.                     'id' => 'a6f630c1af9f4690887af3ee134de8a1',
  109.                     'entityName' => 'customer',
  110.                 ],
  111.             ],
  112.         ];
  113.         return $fieldsets;
  114.     }
  115. }