custom/plugins/EnetSubshop/src/EnetSubshop.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EnetSubshop;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\System\CustomField\CustomFieldTypes;
  8. class EnetSubshop extends Plugin
  9. {
  10.     public function install(InstallContext $context): void
  11.     {
  12.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  13.         $customFieldSetRepository->create(
  14.             [
  15.                 [
  16.                     'name' => 'enet_subshop',
  17.                     'config' => [
  18.                         'label' => [
  19.                             'en-GB' => 'Subshop Einstellungen',
  20.                             'de-DE' => 'Subshop Settings'
  21.                         ]
  22.                     ],
  23.                     'customFields' => [
  24.                         [
  25.                             'name' => 'enet_frontendname',
  26.                             'type' => CustomFieldTypes::TEXT,
  27.                             'config' => [
  28.                                 'compoenentName' => 'sw-field',
  29.                                 'customFieldType' => 'text',
  30.                                 'label' => [
  31.                                     'en-GB' => 'Name Frontend',
  32.                                     'de-DE' => 'Name im Frontend'
  33.                                 ]
  34.                             ],
  35.                             'active' => true
  36.                         ],
  37.                         [
  38.                             'name' => 'enet_postalcode',
  39.                             'type' => CustomFieldTypes::TEXT,
  40.                             'config' => [
  41.                                 'compoenentName' => 'sw-field',
  42.                                 'customFieldType' => 'text',
  43.                                 'label' => [
  44.                                     'en-GB' => 'Postal Code',
  45.                                     'de-DE' => 'Postleitzahl'
  46.                                 ]
  47.                             ],
  48.                             'active' => true
  49.                         ],
  50.                         [
  51.                             'name' => 'enet_adress_street',
  52.                             'type' => CustomFieldTypes::TEXT,
  53.                             'config' => [
  54.                                 'componentName' => 'sw-field',
  55.                                 'customFieldType' => 'text',
  56.                                 'label' => [
  57.                                     'en-GB' => 'Adress Street + Number',
  58.                                     'de-DE' => 'Adresse Straße + Nummer'
  59.                                 ],
  60.                             ],
  61.                             'active' => true
  62.                         ],
  63.                         [
  64.                             'name' => 'enet_adress_opentimes',
  65.                             'type' => CustomFieldTypes::HTML,
  66.                             'config' => [
  67.                                 'componentName' => 'sw-field',
  68.                                 'customFieldType' => 'textarea',
  69.                                 'label' => [
  70.                                     'en-GB' => 'Opening Times',
  71.                                     'de-DE' => 'Öffnungszeiten'
  72.                                 ],
  73.                             ],
  74.                             'active' => true
  75.                         ],
  76.                         [
  77.                             'name' => 'enet_adress_showasselection',
  78.                             'type' => CustomFieldTypes::BOOL,
  79.                             'config' => [
  80.                                 'componentName' => 'sw-field',
  81.                                 'customFieldType' => 'switch',
  82.                                 'label' => [
  83.                                     'en-GB' => 'Show in Frontend as Select',
  84.                                     'de-DE' => 'Im Frontend als Auswahl als Subshop'
  85.                                 ],
  86.                             ],
  87.                             'active' => true
  88.                         ],
  89.                         [
  90.                             'name' => 'enet_subshop_gmaps_latlng',
  91.                             'type' => CustomFieldTypes::TEXT,
  92.                             'config' => [
  93.                                 'componentName' => 'sw-field',
  94.                                 'customFieldType' => 'text',
  95.                                 'label' => [
  96.                                     'en-GB' => 'Gooogle Maps Lat Lng (copy from adressline)',
  97.                                     'de-DE' => 'Google Maps Lat Lng (aus der Adresszeile kopieren)'
  98.                                 ],
  99.                             ],
  100.                             'active' => true
  101.                         ],
  102.                         [
  103.                             'name' => 'enet_subshop_logo',
  104.                             'type' => CustomFieldTypes::TEXT,
  105.                             'config' => [
  106.                                 'componentName' => 'sw-field',
  107.                                 'customFieldType' => 'text',
  108.                                 'label' => [
  109.                                     'en-GB' => 'Logo Url',
  110.                                     'de-DE' => 'Logo Url'
  111.                                 ],
  112.                             ],
  113.                             'active' => true
  114.                         ],
  115.                         [
  116.                             'name' => 'enet_subshop_hero',
  117.                             'type' => CustomFieldTypes::TEXT,
  118.                             'config' => [
  119.                                 'componentName' => 'sw-field',
  120.                                 'customFieldType' => 'text',
  121.                                 'label' => [
  122.                                     'en-GB' => 'Hero Image',
  123.                                     'de-DE' => 'Hero Image'
  124.                                 ],
  125.                             ],
  126.                             'active' => true
  127.                         ]
  128.                     ],
  129.                     'relations' => [
  130.                         ['entityName' => 'sales_channel'],
  131.                     ],
  132.                 ]
  133.             ],
  134.             $context->getContext()
  135.         );
  136.     }
  137. // todo: deinstallieren, hier muss eine id mit angegeben werden?
  138. // zum löschen muss die id ermittelt werden und dann kann gelöscht werden
  139. // besser wäre aber etwas wie update anstatt immer nur create
  140. // quelle: https://bitbucket.basecom.de/projects/SHOP (fancyhover)
  141. // democode:
  142. //     protected function removeCustomFieldSet(): void
  143. //    {
  144. //        /** @var EntityRepositoryInterface $customFieldSetRepository */
  145. //        $customFieldSetRepository = $this->container->get('custom_field_set.repository');
  146. //
  147. //        $criteria = new Criteria();
  148. //        $criteria->addFilter(new EqualsFilter('name', 'kuborgh_fancy_hover'));
  149. //        $ids = $customFieldSetRepository->searchIds($criteria, Context::createDefaultContext());
  150. //
  151. //        if ($ids) {
  152. //            $customFieldSetRepository->delete([['id' => $ids->getIds()[0]]], Context::createDefaultContext());
  153. //        }
  154. //    }
  155. //    public function uninstall(UninstallContext $context): void
  156. //    {
  157. //        $customFieldSetRepository = $this->container->get('custom_field_set.repository');
  158. //        $customFieldSetRepository->delete(
  159. //            [
  160. //                [
  161. //                    'name' => 'enet_subshop',
  162. //                    'customFields' => [
  163. //                        ['name' => 'enet_postalcode'],
  164. //                        ['name' => 'enet_adress_street'],
  165. //                    ]
  166. //                ]
  167. //            ],
  168. //            $context->getContext()
  169. //        );
  170. //    }
  171. }