<?php declare(strict_types=1);
namespace Expert\AutobatMarktThemePlugin;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Storefront\Framework\ThemeInterface;
class AutobatMarktThemePlugin extends Plugin implements ThemeInterface
{
/**
* @var $customFieldSetRepository
*/
private $customFieldSetRepository;
/**
* @return string
*/
public function getThemeConfigPath(): string
{
return 'theme.json';
}
/**
* @param InstallContext $context
*/
public function install(InstallContext $context): void
{
parent::install($context);
$this->addCustomAdditionalInformationFields($context->getContext());
$this->addCustomAlternateProductFields($context->getContext());
$this->addCustomSaleNavColor($context->getContext());
$this->addCategoryHiddenMode($context->getContext());
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
$this->deleteCustomFieldsByName($context->getContext(), 'expert_alternate_article_suggestion');
$this->deleteCustomFieldsByName($context->getContext(), 'expert_additional_article_informations');
$this->deleteCustomFieldsByName($context->getContext(), 'expert_custom_category_nav_color');
$this->deleteCustomFieldsByName($context->getContext(), 'expert_categories_hide_mode');
}
/**
* @param Context $context
*/
public function addCategoryHiddenMode(Context $context)
{
$this->customFieldSetRepository = $this->container->get('custom_field_set.repository');
$this->customFieldSetRepository->create([
[
'name' => 'expert_categories_hide_mode',
'config' => [
'label' => [
'en-GB' => 'Activates the "hidden" mode',
'de-DE' => 'Aktiviert den "hidden" Modus',
],
'translated' => true,
],
'customFields' => [
[
'name' => 'expert_category_item_hide_mode',
'type' => CustomFieldTypes::BOOL,
'config' => [
'componentName' => 'sw-field',
'type' => "checkbox",
'customFieldType' => 'checkbox',
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Activate/Deactivate',
'de-DE' => 'Aktivieren/Deaktivieren',
],
],
],
],
'relations' => [
[
'entityName' => 'category'
]
]
],
], $context);
}
/**
* @param Context $context
*/
public function addCustomSaleNavColor(Context $context)
{
$this->customFieldSetRepository = $this->container->get('custom_field_set.repository');
$this->customFieldSetRepository->create([
[
'name' => 'expert_custom_category_nav_color',
'config' => [
'label' => [
'en-GB' => 'Custom Color for Navigation Item',
'de-DE' => 'Sonderfarbe für Navigations Punkt',
],
'translated' => true,
],
'customFields' => [
[
'name' => 'expert_custom_category_nav_item_color',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => "text",
'customFieldType' => 'text',
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Custom Color for Navigation Item',
'de-DE' => 'Sonderfarbe für Navigations Punkt',
],
],
],
],
'relations' => [
[
'entityName' => 'category'
]
]
],
], $context);
}
/**
* Installs alternate product
*
* @param Context $context
*/
private function addCustomAlternateProductFields(Context $context)
{
$this->customFieldSetRepository = $this->container->get('custom_field_set.repository');
$this->customFieldSetRepository->create([
[
'name' => 'expert_alternate_article_suggestion',
'config' => [
'label' => [
'en-GB' => 'Alternate Article Suggestion',
'de-DE' => 'Alternativartikel Vorschlag',
],
'translated' => false,
],
'customFields' => [
[
'name' => 'expert_alternate_article_suggestion_activation',
'type' => CustomFieldTypes::BOOL,
'config' => [
'componentName' => 'sw-field',
'type' => "checkbox",
'customFieldType' => 'checkbox',
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Activate alternate product',
'de-DE' => 'Alternativprodukt aktivieren',
],
],
],
[
'name' => 'expert_alternate_article_suggestion_picture',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-media-field',
'customFieldType' => 'media',
'customFieldPosition' => 2,
'label' => [
'en-GB' => 'Alternate product picture',
'de-DE' => 'Alternativprodukt Bild',
],
],
],
[
'name' => 'expert_alternate_article_suggestion_name',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'label' => [
'en-GB' => 'Article Name',
'de-DE' => 'Artikel Name',
],
],
],
[
'name' => 'expert_alternate_article_suggestion_price',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 4,
'label' => [
'en-GB' => 'Article Preis',
'de-DE' => 'Artikel Preis',
],
],
],
[
'name' => 'expert_alternate_article_suggestion_url',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 5,
'label' => [
'en-GB' => 'Article Url',
'de-DE' => 'Artikel Url',
]
]
]
],
'relations' => [
[
'entityName' => 'product'
]
]
],
], $context);
}
/**
* Installs additional product information
*
* @param Context $context
*/
private function addCustomAdditionalInformationFields(Context $context)
{
$this->customFieldSetRepository = $this->container->get('custom_field_set.repository');
$this->customFieldSetRepository->create([
[
'name' => 'expert_additional_article_informations',
'config' => [
'label' => [
'en-GB' => 'Additional Article Information',
'de-DE' => 'Zusatz Artikel-Informationen',
],
'translated' => false,
],
'customFields' => [
[
'name' => 'expert_additional_article_information_activation',
'type' => CustomFieldTypes::BOOL,
'config' => [
'componentName' => 'sw-field',
'type' => "checkbox",
'customFieldType' => 'checkbox',
'customFieldPosition' => 1,
'label' => [
'en-GB' => 'Activate additional info',
'de-DE' => 'Zusatzinformationen aktivieren',
],
],
],
[
'name' => 'expert_additional_article_information_main_headline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 2,
'label' => [
'en-GB' => 'Additional information Main Headline',
'de-DE' => 'Zusatz Info Haupt Überschrift',
],
],
],
[
'name' => 'expert_additional_article_information_main_subline',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'label' => [
'en-GB' => 'Additional Information Main Subline',
'de-DE' => 'Zusatz Info Haupt (Sub) Überschrift',
],
],
],
[
'name' => 'expert_additional_article_information_icon1',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 4,
'label' => [
'en-GB' => 'Additional Information Icon 1',
'de-DE' => 'Zusatz Info Icon 1',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon1_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 5,
'label' => [
'en-GB' => 'Additional Information Icon 1 Text',
'de-DE' => 'Zusatz Info Icon 1 Text',
],
],
],
[
'name' => 'expert_additional_article_information_icon2',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 6,
'label' => [
'en-GB' => 'Additional Information Icon 2',
'de-DE' => 'Zusatz Info Icon 2',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon2_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 7,
'label' => [
'en-GB' => 'Additional Information Icon 2 Text',
'de-DE' => 'Zusatz Info Icon 2 Text',
],
],
],
[
'name' => 'expert_additional_article_information_icon3',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 8,
'label' => [
'en-GB' => 'Additional Information Icon 3',
'de-DE' => 'Zusatz Info Icon 3',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon3_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 9,
'label' => [
'en-GB' => 'Additional Information Icon 3 Text',
'de-DE' => 'Zusatz Info Icon 3 Text',
],
],
],
[
'name' => 'expert_additional_article_information_icon4',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 10,
'label' => [
'en-GB' => 'Additional Information Icon 4',
'de-DE' => 'Zusatz Info Icon 4',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon4_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 11,
'label' => [
'en-GB' => 'Additional Information Icon 4 Text',
'de-DE' => 'Zusatz Info Icon 4 Text',
],
],
],
[
'name' => 'expert_additional_article_information_icon5',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 12,
'label' => [
'en-GB' => 'Additional Information Icon 5',
'de-DE' => 'Zusatz Info Icon 5',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon5_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 13,
'label' => [
'en-GB' => 'Additional Information Icon 5 Text',
'de-DE' => 'Zusatz Info Icon 5 Text',
],
],
],
[
'name' => 'expert_additional_article_information_icon6',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 14,
'label' => [
'en-GB' => 'Additional Information Icon 6',
'de-DE' => 'Zusatz Info Icon 6',
],
'placeholder' => [
'en-GB' => 'la-car',
'de-DE' => 'la-car',
],
],
],
[
'name' => 'expert_additional_article_information_icon6_text',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'type' => 'text',
'customFieldType' => 'text',
'customFieldPosition' => 15,
'label' => [
'en-GB' => 'Additional Information Icon 6 Text',
'de-DE' => 'Zusatz Information Icon 6 Text',
],
],
]
],
'relations' => [
[
'entityName' => 'product'
]
]
],
], $context);
}
/**
* Removes all available plugin custom fields by name
*
* @param Context $context
* @param $fieldName
*/
private function deleteCustomFieldsByName(Context $context, $fieldName)
{
$this->customFieldSetRepository = $this->container->get('custom_field_set.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', $fieldName));
$ids = $this->customFieldSetRepository->searchIds($criteria, $context);
if ($ids) {
$this->customFieldSetRepository->delete([['id' => $ids->getIds()[0]]], $context);
}
}
}