custom/plugins/FourtwosixThemeExtension/src/FourtwosixThemeExtension.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace FourtwosixThemeExtension;
  3. use FourtwosixThemeExtension\Constant\Constant;
  4. use FourtwosixThemeExtension\Constant\CustomFields;
  5. use Shopware\Core\Content\Product\ProductDefinition;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\Plugin;
  10. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  11. use Shopware\Core\Framework\Uuid\Uuid;
  12. class FourtwosixThemeExtension extends Plugin
  13. {
  14.     public const TEMPLATE_TYPE_NAME_PRODUCT_ON_REQUEST 'FTS - Product on request';
  15.     public const TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST 'fts_product_on_request';
  16.     public const MAIL_TEMPLATE_NAME_MAIL_MISSING 'Missing mail warning e-mail';
  17.     public const FTS_LAYOUT_MODE_SPLIT 'split';
  18.     public const FTS_LAYOUT_MODE_STANDARD 'standard';
  19.     public const FTS_LAYOUT_MODE_EMPTY 'empty';
  20.     public function update(InstallContext $installContext): void
  21.     {
  22.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  23.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  24.         $criteria = new Criteria();
  25.         $criteria->addFilter(new EqualsFilter('technicalName'self::TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST));
  26.         $baseEmail $mailTemplateTypeRepository->search($criteria$installContext->getContext())->first();
  27.         // Create only the first time
  28.         if (!$baseEmail) {
  29.             $missingMailTemplateType = [
  30.                 [
  31.                     'id' => Uuid::randomHex(),
  32.                     'name' => self::TEMPLATE_TYPE_NAME_PRODUCT_ON_REQUEST,
  33.                     'technicalName' => self::TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST,
  34.                     'availableEntities' => [],
  35.                     'templateData' => [],
  36.                 ],
  37.             ];
  38.             $mailTemplateTypeRepository->create($missingMailTemplateType$installContext->getContext());
  39.         }
  40.         // Importing custom fields
  41.         /** @var EntityRepositoryInterface $customFieldsSetRepository */
  42.         $customFieldsSetRepository $this->container->get('custom_field_set.repository');
  43.         $setCriteria = new Criteria();
  44.         $setCriteria->addFilter(new EqualsFilter('name'Constant::FTS_MAIN_NAME));
  45.         $customFieldsSetResult $customFieldsSetRepository->search($setCriteria,
  46.             $installContext->getContext())->first();
  47.         // Create custom fields only if they have not already been created or if the set is created but the CF not
  48.         if (!$customFieldsSetResult) {
  49.             $customFieldsSetRepository->create([
  50.                 $this->createProcuctCF(),
  51.             ], $installContext->getContext());
  52.         }
  53.     }
  54.     /**
  55.      * @return array
  56.      */
  57.     protected function createProcuctCF(): array
  58.     {
  59.         return [
  60.             'name' => Constant::FTS_MAIN_NAME,
  61.             'config' => [
  62.                 'label' => [
  63.                     'en-GB' => 'Akeneo values',
  64.                     'de-DE' => 'Akeneo values',
  65.                     'it-IT' => 'Akeneo values',
  66.                 ],
  67.             ],
  68.             'customFields' => [
  69.                 CustomFields::ARTIKELHERSTELLERBARCODE,
  70.                 CustomFields::ARTIKELHERSTELLEREANGTIN,
  71.                 CustomFields::PACKPALLETMENGE,
  72.                 CustomFields::PACKPALLETMENGEEINHEIT,
  73.                 CustomFields::PREISVERSANDGRUPPE,
  74.                 CustomFields::STATUSINSHOPBESTELLBAR,
  75.                 CustomFields::STATUSINSHOPPREISZEIGEN,
  76.                 CustomFields::AARTIKELSTATUS,
  77.                 CustomFields::STATUSAUFANFRAGELIEFERANT,
  78.                 CustomFields::STATUSLOESCHEN,
  79.                 CustomFields::PACKBOXKG,
  80.                 CustomFields::PACKBOXM,
  81.                 CustomFields::PACKBOXM2,
  82.                 CustomFields::PACKBOXSTK,
  83.                 CustomFields::ZA08_WEIGHT,
  84.                 CustomFields::DIMBREITE,
  85.                 CustomFields::DIMHOEHE,
  86.                 CustomFields::DIMLAENGE,
  87.             ],
  88.             'relations' => [
  89.                 [
  90.                     'id' => Uuid::randomHex(),
  91.                     'customFieldSetId' => Uuid::randomHex(),
  92.                     'entityName' => ProductDefinition::ENTITY_NAME,
  93.                 ],
  94.             ],
  95.         ];
  96.     }
  97. }