custom/plugins/AbasBecoCustomizations/src/AbasBecoCustomizations.php line 16

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace AbasBecoCustomizations;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. use Shopware\Core\System\CustomField\CustomFieldTypes;
  12. use Sms\SmsBecoCustomerGroupPopup\bootstrap\InstallUninstall;
  13. class AbasBecoCustomizations extends Plugin
  14. {
  15.     private const SW_FIELD_COMPONENT_NAME 'sw-field';
  16.     private const CUSTOM_FIELDS = [
  17.         [
  18.             'name' => 'sms_beco_technic_order_custom_fields',
  19.             'customFields' => [
  20.                 [
  21.                     'name' => 'sms_beco_technic_order_global_commission_number',
  22.                     'type' => CustomFieldTypes::TEXT,
  23.                     'config' => [
  24.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  25.                         'type' => CustomFieldTypes::TEXT,
  26.                         'customFieldType' => CustomFieldTypes::TEXT,
  27.                         'customFieldPosition' => 1,
  28.                         'label' => [
  29.                             'en-GB' => 'Global Commission Number for Cart',
  30.                             'de-DE' => 'Globale Warenkorbkommissionsnummer',
  31.                         ],
  32.                     ],
  33.                 ],
  34.                 [
  35.                     'name' => 'sms_beco_technic_order_comment',
  36.                     'type' => CustomFieldTypes::TEXT,
  37.                     'config' => [
  38.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  39.                         'type' => CustomFieldTypes::TEXT,
  40.                         'customFieldType' => CustomFieldTypes::TEXT,
  41.                         'customFieldPosition' => 1,
  42.                         'label' => [
  43.                             'en-GB' => 'Comment for current Cart',
  44.                             'de-DE' => 'Kommentar zur Bestellung',
  45.                         ],
  46.                     ],
  47.                 ],[
  48.                     'name' => 'sms_beco_technic_order_commission_number',
  49.                     'type' => CustomFieldTypes::TEXT,
  50.                     'config' => [
  51.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  52.                         'type' => CustomFieldTypes::TEXT,
  53.                         'customFieldType' => CustomFieldTypes::TEXT,
  54.                         'customFieldPosition' => 1,
  55.                         'label' => [
  56.                             'en-GB' => 'Global Commission Number',
  57.                             'de-DE' => 'Globale Kommissionsnummer',
  58.                         ],
  59.                     ],
  60.                 ]
  61.             ],
  62.             'config' => [
  63.                 'label' => [
  64.                     'en-GB' => 'Order Custom Fields',
  65.                     'de-DE' => 'Order Custom Fields',
  66.                 ],
  67.                 'translated' => true,
  68.             ],
  69.             'relations' => [[
  70.                 'entityName' => 'order'
  71.             ]]
  72.         ], [
  73.             'name' => 'sms_beco_technic_category_custom_fields',
  74.             'customFields' => [
  75.                 [
  76.                     'name' => 'sms_beco_technic_category_type',
  77.                     'type' => CustomFieldTypes::TEXT,
  78.                     'config' => [
  79.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  80.                         'type' => CustomFieldTypes::TEXT,
  81.                         'customFieldType' => CustomFieldTypes::TEXT,
  82.                         'customFieldPosition' => 1,
  83.                         'label' => [
  84.                             'en-GB' => 'SMS Beco Category Type',
  85.                             'de-DE' => 'SMS Beco Kategorietyp',
  86.                         ],
  87.                     ],
  88.                 ],
  89.                 [
  90.                     'name' => 'sms_beco_technic_product_listing_not_visible',
  91.                     'type' => CustomFieldTypes::SWITCH,
  92.                     'config' => [
  93.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  94.                         'type' => CustomFieldTypes::SWITCH,
  95.                         'customFieldType' => CustomFieldTypes::SWITCH,
  96.                         'customFieldPosition' => 1,
  97.                         'label' => [
  98.                             'en-GB' => 'Dont show Products in Listing',
  99.                             'de-DE' => 'Produkt im Listing ausblenden',
  100.                         ],
  101.                         'value' => false
  102.                     ],
  103.                 ],
  104.                 [
  105.                     'name' => 'sms_beco_technic_category_table_field_one',
  106.                     'type' => CustomFieldTypes::JSON,
  107.                     'config' => [
  108.                         'componentName' => 'sw-entity-single-select',
  109.                         'entity' => 'property_group',
  110.                         'customFieldType' => CustomFieldTypes::JSON,
  111.                         'customFieldPosition' => 2,
  112.                         'label' => [
  113.                             'en-GB' => 'Table Listing Column Header One',
  114.                             'de-DE' => 'Tabellenlisting: Erste Eigenschaft',
  115.                         ],
  116.                     ],
  117.                 ],
  118.                 [
  119.                     'name' => 'sms_beco_technic_category_table_field_two',
  120.                     'type' => CustomFieldTypes::JSON,
  121.                     'config' => [
  122.                         'componentName' => 'sw-entity-single-select',
  123.                         'entity' => 'property_group',
  124.                         'customFieldType' => CustomFieldTypes::JSON,
  125.                         'customFieldPosition' => 3,
  126.                         'label' => [
  127.                             'en-GB' => 'Table Listing Column Header Two',
  128.                             'de-DE' => 'Tabellenlisting: Zweite Eigenschaft',
  129.                         ],
  130.                     ],
  131.                 ],
  132.                 [
  133.                     'name' => 'sms_beco_technic_category_table_field_three',
  134.                     'type' => CustomFieldTypes::JSON,
  135.                     'config' => [
  136.                         'componentName' => 'sw-entity-single-select',
  137.                         'entity' => 'property_group',
  138.                         'customFieldType' => CustomFieldTypes::JSON,
  139.                         'customFieldPosition' => 4,
  140.                         'label' => [
  141.                             'en-GB' => 'Table Listing Column Header Three',
  142.                             'de-DE' => 'Tabellenlisting: Dritte Eigenschaft',
  143.                         ],
  144.                     ],
  145.                 ],
  146.                 [
  147.                     'name' => 'sms_beco_technic_category_table_field_four',
  148.                     'type' => CustomFieldTypes::JSON,
  149.                     'config' => [
  150.                         'componentName' => 'sw-entity-single-select',
  151.                         'entity' => 'property_group',
  152.                         'customFieldType' => CustomFieldTypes::JSON,
  153.                         'customFieldPosition' => 5,
  154.                         'label' => [
  155.                             'en-GB' => 'Table Listing Column Header Four',
  156.                             'de-DE' => 'Tabellenlisting: Vierte Eigenschaft',
  157.                         ],
  158.                     ],
  159.                 ],
  160.                 [
  161.                     'name' => 'sms_beco_technic_category_table_field_five',
  162.                     'type' => CustomFieldTypes::JSON,
  163.                     'config' => [
  164.                         'componentName' => 'sw-entity-single-select',
  165.                         'entity' => 'property_group',
  166.                         'customFieldType' => CustomFieldTypes::JSON,
  167.                         'customFieldPosition' => 6,
  168.                         'label' => [
  169.                             'en-GB' => 'Table Listing Column Header Five',
  170.                             'de-DE' => 'Tabellenlisting: Fünfte Eigenschaft',
  171.                         ],
  172.                     ],
  173.                 ],
  174.                 [
  175.                     'name' => 'sms_beco_technic_category_table_field_six',
  176.                     'type' => CustomFieldTypes::JSON,
  177.                     'config' => [
  178.                         'componentName' => 'sw-entity-single-select',
  179.                         'entity' => 'property_group',
  180.                         'customFieldType' => CustomFieldTypes::JSON,
  181.                         'customFieldPosition' => 7,
  182.                         'label' => [
  183.                             'en-GB' => 'Table Listing Column Header Six',
  184.                             'de-DE' => 'Tabellenlisting: Sechste Eigenschaft',
  185.                         ],
  186.                     ],
  187.                 ],
  188.                 [
  189.                     'name' => 'sms_beco_technic_category_table_primary_property_option',
  190.                     'type' => CustomFieldTypes::ENTITY,
  191.                     'config' => [
  192.                         'componentName' => 'sw-entity-single-select',
  193.                         'entity' => 'property_group_option',
  194.                         'customFieldType' => CustomFieldTypes::ENTITY,
  195.                         'customFieldPosition' => 8,
  196.                         'label' => [
  197.                             'en-GB' => 'Primary Property Option for Table (2) Listing',
  198.                             'de-DE' => 'Tabellenlisting: Eigenschaft, die definiert ob Artikel in erster Tabelle gelistet wird (Kat_Tabelle_2) / Priorisierte Sortierung bei Standartlisting',
  199.                         ],
  200.                     ],
  201.                 ],
  202.                 [
  203.                     'name' => 'sms_beco_technic_category_table_primary_property_option_name',
  204.                     'type' => CustomFieldTypes::TEXT,
  205.                     'config' => [
  206.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  207.                         'type' => CustomFieldTypes::TEXT,
  208.                         'customFieldType' => CustomFieldTypes::TEXT,
  209.                         'customFieldPosition' => 1,
  210.                         'label' => [
  211.                             'en-GB' => 'Tabellenlisting Kat_Tabelle_Zwei 1. Tabelle Name',
  212.                             'de-DE' => 'Tabellenlisting Kat_Tabelle_Zwei 1. Tabelle Name',
  213.                         ],
  214.                     ],
  215.                 ],
  216.             ],
  217.             'config' => [
  218.                 'label' => [
  219.                     'en-GB' => 'SMS Beco Category Custom Fields',
  220.                     'de-DE' => 'SMS Beco Category Custom Fields',
  221.                 ],
  222.                 'translated' => true,
  223.             ],
  224.             'relations' => [[
  225.                 'entityName' => 'category'
  226.             ]]
  227.         ],
  228.         [
  229.             'name' => 'sms_beco_technic_product_custom_fields',
  230.             'customFields' => [
  231.                 [
  232.                     'name' => 'sms_beco_technic_product_bbesch',
  233.                     'type' => CustomFieldTypes::TEXT,
  234.                     'config' => [
  235.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  236.                         'type' => CustomFieldTypes::TEXT,
  237.                         'customFieldType' => CustomFieldTypes::TEXT,
  238.                         'customFieldPosition' => 1,
  239.                         'label' => [
  240.                             'en-GB' => 'Abas Feld: BBesch',
  241.                             'de-DE' => 'Abas Feld: BBesch',
  242.                         ],
  243.                     ],
  244.                 ],
  245.                 [
  246.                     'name' => 'sms_beco_technic_product_bstnr',
  247.                     'type' => CustomFieldTypes::TEXT,
  248.                     'config' => [
  249.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  250.                         'type' => CustomFieldTypes::TEXT,
  251.                         'customFieldType' => CustomFieldTypes::TEXT,
  252.                         'customFieldPosition' => 1,
  253.                         'label' => [
  254.                             'en-GB' => 'Abas Feld: Bstnr',
  255.                             'de-DE' => 'Abas Feld: Bstnr',
  256.                         ],
  257.                     ],
  258.                 ],
  259.                 [
  260.                     'name' => 'sms_beco_technic_product_bstnr2',
  261.                     'type' => CustomFieldTypes::TEXT,
  262.                     'config' => [
  263.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  264.                         'type' => CustomFieldTypes::TEXT,
  265.                         'customFieldType' => CustomFieldTypes::TEXT,
  266.                         'customFieldPosition' => 1,
  267.                         'label' => [
  268.                             'en-GB' => 'Abas Feld: Bstnr 2',
  269.                             'de-DE' => 'Abas Feld: Bstnr 2',
  270.                         ],
  271.                     ],
  272.                 ],
  273.                 [
  274.                     'name' => 'sms_beco_technic_product_bstnr3',
  275.                     'type' => CustomFieldTypes::TEXT,
  276.                     'config' => [
  277.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  278.                         'type' => CustomFieldTypes::TEXT,
  279.                         'customFieldType' => CustomFieldTypes::TEXT,
  280.                         'customFieldPosition' => 1,
  281.                         'label' => [
  282.                             'en-GB' => 'Abas Feld: Bstnr 3',
  283.                             'de-DE' => 'Abas Feld: Bstnr 3',
  284.                         ],
  285.                     ],
  286.                 ],
  287.                 [
  288.                     'name' => 'sms_beco_technic_product_ypdf2',
  289.                     'type' => CustomFieldTypes::TEXT,
  290.                     'config' => [
  291.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  292.                         'type' => CustomFieldTypes::TEXT,
  293.                         'customFieldType' => CustomFieldTypes::TEXT,
  294.                         'customFieldPosition' => 2,
  295.                         'label' => [
  296.                             'en-GB' => 'Abas Feld: Pdf2',
  297.                             'de-DE' => 'Abas Feld: Pdf2',
  298.                         ],
  299.                     ],
  300.                 ],
  301.                 [
  302.                     'name' => 'sms_beco_technic_product_ypdf3',
  303.                     'type' => CustomFieldTypes::TEXT,
  304.                     'config' => [
  305.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  306.                         'type' => CustomFieldTypes::TEXT,
  307.                         'customFieldType' => CustomFieldTypes::TEXT,
  308.                         'customFieldPosition' => 3,
  309.                         'label' => [
  310.                             'en-GB' => 'Abas Feld: Pdf3',
  311.                             'de-DE' => 'Abas Feld: Pdf2',
  312.                         ],
  313.                     ],
  314.                 ],
  315.                 [
  316.                     'name' => 'sms_beco_technic_product_ypdf4',
  317.                     'type' => CustomFieldTypes::TEXT,
  318.                     'config' => [
  319.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  320.                         'type' => CustomFieldTypes::TEXT,
  321.                         'customFieldType' => CustomFieldTypes::TEXT,
  322.                         'customFieldPosition' => 4,
  323.                         'label' => [
  324.                             'en-GB' => 'Abas Feld: Pdf4',
  325.                             'de-DE' => 'Abas Feld: Pdf4',
  326.                         ],
  327.                     ],
  328.                 ],
  329.                 [
  330.                     'name' => 'sms_beco_technic_product_ypdf5',
  331.                     'type' => CustomFieldTypes::TEXT,
  332.                     'config' => [
  333.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  334.                         'type' => CustomFieldTypes::TEXT,
  335.                         'customFieldType' => CustomFieldTypes::TEXT,
  336.                         'customFieldPosition' => 5,
  337.                         'label' => [
  338.                             'en-GB' => 'Abas Feld: Pdf5',
  339.                             'de-DE' => 'Abas Feld: Pdf5',
  340.                         ],
  341.                     ],
  342.                 ],
  343.                 [
  344.                     'name' => 'sms_beco_technic_product_ypdf6',
  345.                     'type' => CustomFieldTypes::TEXT,
  346.                     'config' => [
  347.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  348.                         'type' => CustomFieldTypes::TEXT,
  349.                         'customFieldType' => CustomFieldTypes::TEXT,
  350.                         'customFieldPosition' => 6,
  351.                         'label' => [
  352.                             'en-GB' => 'Abas Feld: Pdf6',
  353.                             'de-DE' => 'Abas Feld: Pdf6',
  354.                         ],
  355.                     ],
  356.                 ],
  357.                 [
  358.                     'name' => 'sms_beco_technic_product_ypdf7',
  359.                     'type' => CustomFieldTypes::TEXT,
  360.                     'config' => [
  361.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  362.                         'type' => CustomFieldTypes::TEXT,
  363.                         'customFieldType' => CustomFieldTypes::TEXT,
  364.                         'customFieldPosition' => 7,
  365.                         'label' => [
  366.                             'en-GB' => 'Abas Feld: Pdf7',
  367.                             'de-DE' => 'Abas Feld: Pdf7',
  368.                         ],
  369.                     ],
  370.                 ],
  371.                 [
  372.                     'name' => 'sms_beco_technic_product_ypdf8',
  373.                     'type' => CustomFieldTypes::TEXT,
  374.                     'config' => [
  375.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  376.                         'type' => CustomFieldTypes::TEXT,
  377.                         'customFieldType' => CustomFieldTypes::TEXT,
  378.                         'customFieldPosition' => 8,
  379.                         'label' => [
  380.                             'en-GB' => 'Abas Feld: Pdf8',
  381.                             'de-DE' => 'Abas Feld: Pdf8',
  382.                         ],
  383.                     ],
  384.                 ],
  385.                 [
  386.                     'name' => 'sms_beco_technic_product_ypdf9',
  387.                     'type' => CustomFieldTypes::TEXT,
  388.                     'config' => [
  389.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  390.                         'type' => CustomFieldTypes::TEXT,
  391.                         'customFieldType' => CustomFieldTypes::TEXT,
  392.                         'customFieldPosition' => 9,
  393.                         'label' => [
  394.                             'en-GB' => 'Abas Feld: Pdf9',
  395.                             'de-DE' => 'Abas Feld: Pdf9',
  396.                         ],
  397.                     ],
  398.                 ],
  399.                 [
  400.                     'name' => 'sms_beco_technic_product_ypdf10',
  401.                     'type' => CustomFieldTypes::TEXT,
  402.                     'config' => [
  403.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  404.                         'type' => CustomFieldTypes::TEXT,
  405.                         'customFieldType' => CustomFieldTypes::TEXT,
  406.                         'customFieldPosition' => 10,
  407.                         'label' => [
  408.                             'en-GB' => 'Abas Feld: Pdf10',
  409.                             'de-DE' => 'Abas Feld: Pdf10',
  410.                         ],
  411.                     ],
  412.                 ],
  413.                 [
  414.                     'name' => 'sms_beco_technic_product_catmeta',
  415.                     'type' => CustomFieldTypes::TEXT,
  416.                     'config' => [
  417.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  418.                         'type' => CustomFieldTypes::TEXT,
  419.                         'customFieldType' => CustomFieldTypes::TEXT,
  420.                         'customFieldPosition' => 11,
  421.                         'label' => [
  422.                             'en-GB' => 'Abas Feld: Catmeta',
  423.                             'de-DE' => 'Abas Feld: Catmeta',
  424.                         ],
  425.                     ],
  426.                 ],
  427.                 [
  428.                     'name' => 'sms_beco_technic_product_ykaliberalt',
  429.                     'type' => CustomFieldTypes::TEXT,
  430.                     'config' => [
  431.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  432.                         'type' => CustomFieldTypes::TEXT,
  433.                         'customFieldType' => CustomFieldTypes::TEXT,
  434.                         'customFieldPosition' => 12,
  435.                         'label' => [
  436.                             'en-GB' => 'Abas Feld: ykaliberalt',
  437.                             'de-DE' => 'Abas Feld: ykaliberalt',
  438.                         ],
  439.                     ],
  440.                 ],
  441.                 [
  442.                     'name' => 'sms_beco_technic_product_ywerkreserve1',
  443.                     'type' => CustomFieldTypes::TEXT,
  444.                     'config' => [
  445.                         'componentName' => self::SW_FIELD_COMPONENT_NAME,
  446.                         'type' => CustomFieldTypes::TEXT,
  447.                         'customFieldType' => CustomFieldTypes::TEXT,
  448.                         'customFieldPosition' => 13,
  449.                         'label' => [
  450.                             'en-GB' => 'Abas Feld: ywerkreserve1',
  451.                             'de-DE' => 'Abas Feld: ywerkreserve1',
  452.                         ],
  453.                     ],
  454.                 ]
  455.             ],
  456.             'config' => [
  457.                 'label' => [
  458.                     'en-GB' => 'SMS Beco Product Custom Fields',
  459.                     'de-DE' => 'SMS Beco Product Custom Fields',
  460.                 ],
  461.                 'translated' => true,
  462.             ],
  463.             'relations' => [[
  464.                 'entityName' => 'product'
  465.             ]]
  466.         ],
  467.     ];
  468.     public function install(InstallContext $installContext): void
  469.     {
  470.         parent::install($installContext);
  471.         $this->installOrUpdateCustomFields($installContext);
  472.     }
  473.     public function update(UpdateContext $updateContext): void
  474.     {
  475.         parent::update($updateContext);
  476.         $this->installOrUpdateCustomFields($updateContext);
  477.     }
  478.     /**
  479.      *
  480.      * @param UninstallContext $uninstallContext
  481.      * @throws InconsistentCriteriaIdsException
  482.      */
  483.     public function uninstall(UninstallContext $uninstallContext): void
  484.     {
  485.         parent::uninstall($uninstallContext);
  486.         if ($uninstallContext->keepUserData()) {
  487.             return;
  488.         }
  489.         (new InstallUninstall($this->container))->uninstall($uninstallContext->getContext());
  490.     }
  491.     public function installOrUpdateCustomFields($context)
  492.     {
  493.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  494.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  495.         foreach (self::CUSTOM_FIELDS as $customFieldSet) {
  496.             $criteria = (new Criteria())
  497.                 ->addFilter(new EqualsFilter('name'$customFieldSet["name"]));
  498.             $existingCustomFieldSets $customFieldSetRepository
  499.                 ->search($criteria$context->getContext());
  500.             //var_dump($existingCustomFieldSets->getTotal());
  501.             if ($existingCustomFieldSets->getTotal() >= 1) {
  502.                 $ids $existingCustomFieldSets->getIds();
  503.                 $customFieldSet["id"] = array_key_first($ids);
  504.                 $customFieldSetRepository->delete([$customFieldSet], $context->getContext());
  505. //                foreach($ids as $id){
  506. //                    $key = [0 => $id];
  507. //
  508. //                }
  509.             }
  510.             $customFieldSetRepository->upsert([$customFieldSet], $context->getContext());
  511.         }
  512.     }
  513. }