custom/plugins/AutobatMarktThemePlugin-master/src/AutobatMarktThemePlugin.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Expert\AutobatMarktThemePlugin;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\System\CustomField\CustomFieldTypes;
  10. use Shopware\Storefront\Framework\ThemeInterface;
  11. class AutobatMarktThemePlugin extends Plugin implements ThemeInterface
  12. {
  13.     /**
  14.      * @var $customFieldSetRepository
  15.      */
  16.     private $customFieldSetRepository;
  17.     /**
  18.      * @return string
  19.      */
  20.     public function getThemeConfigPath(): string
  21.     {
  22.         return 'theme.json';
  23.     }
  24.     /**
  25.      * @param InstallContext $context
  26.      */
  27.     public function install(InstallContext $context): void
  28.     {
  29.         parent::install($context);
  30.         $this->addCustomAdditionalInformationFields($context->getContext());
  31.         $this->addCustomAlternateProductFields($context->getContext());
  32.         $this->addCustomSaleNavColor($context->getContext());
  33.         $this->addCategoryHiddenMode($context->getContext());
  34.     }
  35.     /**
  36.      * @param UninstallContext $context
  37.      */
  38.     public function uninstall(UninstallContext $context): void
  39.     {
  40.         parent::uninstall($context);
  41.         $this->deleteCustomFieldsByName($context->getContext(), 'expert_alternate_article_suggestion');
  42.         $this->deleteCustomFieldsByName($context->getContext(), 'expert_additional_article_informations');
  43.         $this->deleteCustomFieldsByName($context->getContext(), 'expert_custom_category_nav_color');
  44.         $this->deleteCustomFieldsByName($context->getContext(), 'expert_categories_hide_mode');
  45.     }
  46.     /**
  47.      * @param Context $context
  48.      */
  49.     public function addCategoryHiddenMode(Context $context)
  50.     {
  51.         $this->customFieldSetRepository $this->container->get('custom_field_set.repository');
  52.         $this->customFieldSetRepository->create([
  53.             [
  54.                 'name' => 'expert_categories_hide_mode',
  55.                 'config' => [
  56.                     'label' => [
  57.                         'en-GB' => 'Activates the "hidden" mode',
  58.                         'de-DE' => 'Aktiviert den "hidden" Modus',
  59.                     ],
  60.                     'translated' => true,
  61.                 ],
  62.                 'customFields' => [
  63.                     [
  64.                         'name' => 'expert_category_item_hide_mode',
  65.                         'type' => CustomFieldTypes::BOOL,
  66.                         'config' => [
  67.                             'componentName' => 'sw-field',
  68.                             'type' => "checkbox",
  69.                             'customFieldType' => 'checkbox',
  70.                             'customFieldPosition' => 1,
  71.                             'label' => [
  72.                                 'en-GB' => 'Activate/Deactivate',
  73.                                 'de-DE' => 'Aktivieren/Deaktivieren',
  74.                             ],
  75.                         ],
  76.                     ],
  77.                 ],
  78.                 'relations' => [
  79.                     [
  80.                         'entityName' => 'category'
  81.                     ]
  82.                 ]
  83.             ],
  84.         ], $context);
  85.     }
  86.     /**
  87.      * @param Context $context
  88.      */
  89.     public function addCustomSaleNavColor(Context $context)
  90.     {
  91.         $this->customFieldSetRepository $this->container->get('custom_field_set.repository');
  92.         $this->customFieldSetRepository->create([
  93.             [
  94.                 'name' => 'expert_custom_category_nav_color',
  95.                 'config' => [
  96.                     'label' => [
  97.                         'en-GB' => 'Custom Color for Navigation Item',
  98.                         'de-DE' => 'Sonderfarbe für Navigations Punkt',
  99.                     ],
  100.                     'translated' => true,
  101.                 ],
  102.                 'customFields' => [
  103.                     [
  104.                         'name' => 'expert_custom_category_nav_item_color',
  105.                         'type' => CustomFieldTypes::TEXT,
  106.                         'config' => [
  107.                             'componentName' => 'sw-field',
  108.                             'type' => "text",
  109.                             'customFieldType' => 'text',
  110.                             'customFieldPosition' => 1,
  111.                             'label' => [
  112.                                 'en-GB' => 'Custom Color for Navigation Item',
  113.                                 'de-DE' => 'Sonderfarbe für Navigations Punkt',
  114.                             ],
  115.                         ],
  116.                     ],
  117.                 ],
  118.                 'relations' => [
  119.                     [
  120.                         'entityName' => 'category'
  121.                     ]
  122.                 ]
  123.             ],
  124.         ], $context);
  125.     }
  126.     /**
  127.      * Installs alternate product
  128.      *
  129.      * @param Context $context
  130.      */
  131.     private function addCustomAlternateProductFields(Context $context)
  132.     {
  133.         $this->customFieldSetRepository $this->container->get('custom_field_set.repository');
  134.         $this->customFieldSetRepository->create([
  135.             [
  136.                 'name' => 'expert_alternate_article_suggestion',
  137.                 'config' => [
  138.                     'label' => [
  139.                         'en-GB' => 'Alternate Article Suggestion',
  140.                         'de-DE' => 'Alternativartikel Vorschlag',
  141.                     ],
  142.                     'translated' => false,
  143.                 ],
  144.                 'customFields' => [
  145.                     [
  146.                         'name' => 'expert_alternate_article_suggestion_activation',
  147.                         'type' => CustomFieldTypes::BOOL,
  148.                         'config' => [
  149.                             'componentName' => 'sw-field',
  150.                             'type' => "checkbox",
  151.                             'customFieldType' => 'checkbox',
  152.                             'customFieldPosition' => 1,
  153.                             'label' => [
  154.                                 'en-GB' => 'Activate alternate product',
  155.                                 'de-DE' => 'Alternativprodukt aktivieren',
  156.                             ],
  157.                         ],
  158.                     ],
  159.                     [
  160.                         'name' => 'expert_alternate_article_suggestion_picture',
  161.                         'type' => CustomFieldTypes::TEXT,
  162.                         'config' => [
  163.                             'componentName' => 'sw-media-field',
  164.                             'customFieldType' => 'media',
  165.                             'customFieldPosition' => 2,
  166.                             'label' => [
  167.                                 'en-GB' => 'Alternate product picture',
  168.                                 'de-DE' => 'Alternativprodukt Bild',
  169.                             ],
  170.                         ],
  171.                     ],
  172.                     [
  173.                         'name' => 'expert_alternate_article_suggestion_name',
  174.                         'type' => CustomFieldTypes::TEXT,
  175.                         'config' => [
  176.                             'componentName' => 'sw-field',
  177.                             'type' => 'text',
  178.                             'customFieldType' => 'text',
  179.                             'customFieldPosition' => 3,
  180.                             'label' => [
  181.                                 'en-GB' => 'Article Name',
  182.                                 'de-DE' => 'Artikel Name',
  183.                             ],
  184.                         ],
  185.                     ],
  186.                     [
  187.                         'name' => 'expert_alternate_article_suggestion_price',
  188.                         'type' => CustomFieldTypes::TEXT,
  189.                         'config' => [
  190.                             'componentName' => 'sw-field',
  191.                             'type' => 'text',
  192.                             'customFieldType' => 'text',
  193.                             'customFieldPosition' => 4,
  194.                             'label' => [
  195.                                 'en-GB' => 'Article Preis',
  196.                                 'de-DE' => 'Artikel Preis',
  197.                             ],
  198.                         ],
  199.                     ],
  200.                     [
  201.                         'name' => 'expert_alternate_article_suggestion_url',
  202.                         'type' => CustomFieldTypes::TEXT,
  203.                         'config' => [
  204.                             'componentName' => 'sw-field',
  205.                             'type' => 'text',
  206.                             'customFieldType' => 'text',
  207.                             'customFieldPosition' => 5,
  208.                             'label' => [
  209.                                 'en-GB' => 'Article Url',
  210.                                 'de-DE' => 'Artikel Url',
  211.                             ]
  212.                         ]
  213.                     ]
  214.                 ],
  215.                 'relations' => [
  216.                     [
  217.                         'entityName' => 'product'
  218.                     ]
  219.                 ]
  220.             ],
  221.         ], $context);
  222.     }
  223.     /**
  224.      * Installs additional product information
  225.      *
  226.      * @param Context $context
  227.      */
  228.     private function addCustomAdditionalInformationFields(Context $context)
  229.     {
  230.         $this->customFieldSetRepository $this->container->get('custom_field_set.repository');
  231.         $this->customFieldSetRepository->create([
  232.             [
  233.                 'name' => 'expert_additional_article_informations',
  234.                 'config' => [
  235.                     'label' => [
  236.                         'en-GB' => 'Additional Article Information',
  237.                         'de-DE' => 'Zusatz Artikel-Informationen',
  238.                     ],
  239.                     'translated' => false,
  240.                 ],
  241.                 'customFields' => [
  242.                     [
  243.                         'name' => 'expert_additional_article_information_activation',
  244.                         'type' => CustomFieldTypes::BOOL,
  245.                         'config' => [
  246.                             'componentName' => 'sw-field',
  247.                             'type' => "checkbox",
  248.                             'customFieldType' => 'checkbox',
  249.                             'customFieldPosition' => 1,
  250.                             'label' => [
  251.                                 'en-GB' => 'Activate additional info',
  252.                                 'de-DE' => 'Zusatzinformationen aktivieren',
  253.                             ],
  254.                         ],
  255.                     ],
  256.                     [
  257.                         'name' => 'expert_additional_article_information_main_headline',
  258.                         'type' => CustomFieldTypes::TEXT,
  259.                         'config' => [
  260.                             'componentName' => 'sw-field',
  261.                             'type' => 'text',
  262.                             'customFieldType' => 'text',
  263.                             'customFieldPosition' => 2,
  264.                             'label' => [
  265.                                 'en-GB' => 'Additional information Main Headline',
  266.                                 'de-DE' => 'Zusatz Info Haupt Überschrift',
  267.                             ],
  268.                         ],
  269.                     ],
  270.                     [
  271.                         'name' => 'expert_additional_article_information_main_subline',
  272.                         'type' => CustomFieldTypes::TEXT,
  273.                         'config' => [
  274.                             'componentName' => 'sw-field',
  275.                             'type' => 'text',
  276.                             'customFieldType' => 'text',
  277.                             'customFieldPosition' => 3,
  278.                             'label' => [
  279.                                 'en-GB' => 'Additional Information Main Subline',
  280.                                 'de-DE' => 'Zusatz Info Haupt (Sub) Überschrift',
  281.                             ],
  282.                         ],
  283.                     ],
  284.                     [
  285.                         'name' => 'expert_additional_article_information_icon1',
  286.                         'type' => CustomFieldTypes::TEXT,
  287.                         'config' => [
  288.                             'componentName' => 'sw-field',
  289.                             'type' => 'text',
  290.                             'customFieldType' => 'text',
  291.                             'customFieldPosition' => 4,
  292.                             'label' => [
  293.                                 'en-GB' => 'Additional Information Icon 1',
  294.                                 'de-DE' => 'Zusatz Info Icon 1',
  295.                             ],
  296.                             'placeholder' => [
  297.                                 'en-GB' => 'la-car',
  298.                                 'de-DE' => 'la-car',
  299.                             ],
  300.                         ],
  301.                     ],
  302.                     [
  303.                         'name' => 'expert_additional_article_information_icon1_text',
  304.                         'type' => CustomFieldTypes::TEXT,
  305.                         'config' => [
  306.                             'componentName' => 'sw-field',
  307.                             'type' => 'text',
  308.                             'customFieldType' => 'text',
  309.                             'customFieldPosition' => 5,
  310.                             'label' => [
  311.                                 'en-GB' => 'Additional Information Icon 1 Text',
  312.                                 'de-DE' => 'Zusatz Info Icon 1 Text',
  313.                             ],
  314.                         ],
  315.                     ],
  316.                     [
  317.                         'name' => 'expert_additional_article_information_icon2',
  318.                         'type' => CustomFieldTypes::TEXT,
  319.                         'config' => [
  320.                             'componentName' => 'sw-field',
  321.                             'type' => 'text',
  322.                             'customFieldType' => 'text',
  323.                             'customFieldPosition' => 6,
  324.                             'label' => [
  325.                                 'en-GB' => 'Additional Information Icon 2',
  326.                                 'de-DE' => 'Zusatz Info Icon 2',
  327.                             ],
  328.                             'placeholder' => [
  329.                                 'en-GB' => 'la-car',
  330.                                 'de-DE' => 'la-car',
  331.                             ],
  332.                         ],
  333.                     ],
  334.                     [
  335.                         'name' => 'expert_additional_article_information_icon2_text',
  336.                         'type' => CustomFieldTypes::TEXT,
  337.                         'config' => [
  338.                             'componentName' => 'sw-field',
  339.                             'type' => 'text',
  340.                             'customFieldType' => 'text',
  341.                             'customFieldPosition' => 7,
  342.                             'label' => [
  343.                                 'en-GB' => 'Additional Information Icon 2 Text',
  344.                                 'de-DE' => 'Zusatz Info Icon 2 Text',
  345.                             ],
  346.                         ],
  347.                     ],
  348.                     [
  349.                         'name' => 'expert_additional_article_information_icon3',
  350.                         'type' => CustomFieldTypes::TEXT,
  351.                         'config' => [
  352.                             'componentName' => 'sw-field',
  353.                             'type' => 'text',
  354.                             'customFieldType' => 'text',
  355.                             'customFieldPosition' => 8,
  356.                             'label' => [
  357.                                 'en-GB' => 'Additional Information Icon 3',
  358.                                 'de-DE' => 'Zusatz Info Icon 3',
  359.                             ],
  360.                             'placeholder' => [
  361.                                 'en-GB' => 'la-car',
  362.                                 'de-DE' => 'la-car',
  363.                             ],
  364.                         ],
  365.                     ],
  366.                     [
  367.                         'name' => 'expert_additional_article_information_icon3_text',
  368.                         'type' => CustomFieldTypes::TEXT,
  369.                         'config' => [
  370.                             'componentName' => 'sw-field',
  371.                             'type' => 'text',
  372.                             'customFieldType' => 'text',
  373.                             'customFieldPosition' => 9,
  374.                             'label' => [
  375.                                 'en-GB' => 'Additional Information Icon 3 Text',
  376.                                 'de-DE' => 'Zusatz Info Icon 3 Text',
  377.                             ],
  378.                         ],
  379.                     ],
  380.                     [
  381.                         'name' => 'expert_additional_article_information_icon4',
  382.                         'type' => CustomFieldTypes::TEXT,
  383.                         'config' => [
  384.                             'componentName' => 'sw-field',
  385.                             'type' => 'text',
  386.                             'customFieldType' => 'text',
  387.                             'customFieldPosition' => 10,
  388.                             'label' => [
  389.                                 'en-GB' => 'Additional Information Icon 4',
  390.                                 'de-DE' => 'Zusatz Info Icon 4',
  391.                             ],
  392.                             'placeholder' => [
  393.                                 'en-GB' => 'la-car',
  394.                                 'de-DE' => 'la-car',
  395.                             ],
  396.                         ],
  397.                     ],
  398.                     [
  399.                         'name' => 'expert_additional_article_information_icon4_text',
  400.                         'type' => CustomFieldTypes::TEXT,
  401.                         'config' => [
  402.                             'componentName' => 'sw-field',
  403.                             'type' => 'text',
  404.                             'customFieldType' => 'text',
  405.                             'customFieldPosition' => 11,
  406.                             'label' => [
  407.                                 'en-GB' => 'Additional Information Icon 4 Text',
  408.                                 'de-DE' => 'Zusatz Info Icon 4 Text',
  409.                             ],
  410.                         ],
  411.                     ],
  412.                     [
  413.                         'name' => 'expert_additional_article_information_icon5',
  414.                         'type' => CustomFieldTypes::TEXT,
  415.                         'config' => [
  416.                             'componentName' => 'sw-field',
  417.                             'type' => 'text',
  418.                             'customFieldType' => 'text',
  419.                             'customFieldPosition' => 12,
  420.                             'label' => [
  421.                                 'en-GB' => 'Additional Information Icon 5',
  422.                                 'de-DE' => 'Zusatz Info Icon 5',
  423.                             ],
  424.                             'placeholder' => [
  425.                                 'en-GB' => 'la-car',
  426.                                 'de-DE' => 'la-car',
  427.                             ],
  428.                         ],
  429.                     ],
  430.                     [
  431.                         'name' => 'expert_additional_article_information_icon5_text',
  432.                         'type' => CustomFieldTypes::TEXT,
  433.                         'config' => [
  434.                             'componentName' => 'sw-field',
  435.                             'type' => 'text',
  436.                             'customFieldType' => 'text',
  437.                             'customFieldPosition' => 13,
  438.                             'label' => [
  439.                                 'en-GB' => 'Additional Information Icon 5 Text',
  440.                                 'de-DE' => 'Zusatz Info Icon 5 Text',
  441.                             ],
  442.                         ],
  443.                     ],
  444.                     [
  445.                         'name' => 'expert_additional_article_information_icon6',
  446.                         'type' => CustomFieldTypes::TEXT,
  447.                         'config' => [
  448.                             'componentName' => 'sw-field',
  449.                             'type' => 'text',
  450.                             'customFieldType' => 'text',
  451.                             'customFieldPosition' => 14,
  452.                             'label' => [
  453.                                 'en-GB' => 'Additional Information Icon 6',
  454.                                 'de-DE' => 'Zusatz Info Icon 6',
  455.                             ],
  456.                             'placeholder' => [
  457.                                 'en-GB' => 'la-car',
  458.                                 'de-DE' => 'la-car',
  459.                             ],
  460.                         ],
  461.                     ],
  462.                     [
  463.                         'name' => 'expert_additional_article_information_icon6_text',
  464.                         'type' => CustomFieldTypes::TEXT,
  465.                         'config' => [
  466.                             'componentName' => 'sw-field',
  467.                             'type' => 'text',
  468.                             'customFieldType' => 'text',
  469.                             'customFieldPosition' => 15,
  470.                             'label' => [
  471.                                 'en-GB' => 'Additional Information Icon 6 Text',
  472.                                 'de-DE' => 'Zusatz Information Icon 6 Text',
  473.                             ],
  474.                         ],
  475.                     ]
  476.                 ],
  477.                 'relations' => [
  478.                     [
  479.                         'entityName' => 'product'
  480.                     ]
  481.                 ]
  482.             ],
  483.         ], $context);
  484.     }
  485.     /**
  486.      * Removes all available plugin custom fields by name
  487.      *
  488.      * @param Context $context
  489.      * @param         $fieldName
  490.      */
  491.     private function deleteCustomFieldsByName(Context $context$fieldName)
  492.     {
  493.         $this->customFieldSetRepository $this->container->get('custom_field_set.repository');
  494.         $criteria = new Criteria();
  495.         $criteria->addFilter(new EqualsFilter('name'$fieldName));
  496.         $ids $this->customFieldSetRepository->searchIds($criteria$context);
  497.         if ($ids) {
  498.             $this->customFieldSetRepository->delete([['id' => $ids->getIds()[0]]], $context);
  499.         }
  500.     }
  501. }