<?php declare(strict_types=1);
namespace FourtwosixThemeExtension;
use FourtwosixThemeExtension\Constant\Constant;
use FourtwosixThemeExtension\Constant\CustomFields;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
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\Uuid\Uuid;
class FourtwosixThemeExtension extends Plugin
{
public const TEMPLATE_TYPE_NAME_PRODUCT_ON_REQUEST = 'FTS - Product on request';
public const TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST = 'fts_product_on_request';
public const MAIL_TEMPLATE_NAME_MAIL_MISSING = 'Missing mail warning e-mail';
public const FTS_LAYOUT_MODE_SPLIT = 'split';
public const FTS_LAYOUT_MODE_STANDARD = 'standard';
public const FTS_LAYOUT_MODE_EMPTY = 'empty';
public function update(InstallContext $installContext): void
{
/** @var EntityRepositoryInterface $mailTemplateTypeRepository */
$mailTemplateTypeRepository = $this->container->get('mail_template_type.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('technicalName', self::TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST));
$baseEmail = $mailTemplateTypeRepository->search($criteria, $installContext->getContext())->first();
// Create only the first time
if (!$baseEmail) {
$missingMailTemplateType = [
[
'id' => Uuid::randomHex(),
'name' => self::TEMPLATE_TYPE_NAME_PRODUCT_ON_REQUEST,
'technicalName' => self::TEMPLATE_TYPE_TECHNICAL_NAME_PRODUCT_ON_REQUEST,
'availableEntities' => [],
'templateData' => [],
],
];
$mailTemplateTypeRepository->create($missingMailTemplateType, $installContext->getContext());
}
// Importing custom fields
/** @var EntityRepositoryInterface $customFieldsSetRepository */
$customFieldsSetRepository = $this->container->get('custom_field_set.repository');
$setCriteria = new Criteria();
$setCriteria->addFilter(new EqualsFilter('name', Constant::FTS_MAIN_NAME));
$customFieldsSetResult = $customFieldsSetRepository->search($setCriteria,
$installContext->getContext())->first();
// Create custom fields only if they have not already been created or if the set is created but the CF not
if (!$customFieldsSetResult) {
$customFieldsSetRepository->create([
$this->createProcuctCF(),
], $installContext->getContext());
}
}
/**
* @return array
*/
protected function createProcuctCF(): array
{
return [
'name' => Constant::FTS_MAIN_NAME,
'config' => [
'label' => [
'en-GB' => 'Akeneo values',
'de-DE' => 'Akeneo values',
'it-IT' => 'Akeneo values',
],
],
'customFields' => [
CustomFields::ARTIKELHERSTELLERBARCODE,
CustomFields::ARTIKELHERSTELLEREANGTIN,
CustomFields::PACKPALLETMENGE,
CustomFields::PACKPALLETMENGEEINHEIT,
CustomFields::PREISVERSANDGRUPPE,
CustomFields::STATUSINSHOPBESTELLBAR,
CustomFields::STATUSINSHOPPREISZEIGEN,
CustomFields::AARTIKELSTATUS,
CustomFields::STATUSAUFANFRAGELIEFERANT,
CustomFields::STATUSLOESCHEN,
CustomFields::PACKBOXKG,
CustomFields::PACKBOXM,
CustomFields::PACKBOXM2,
CustomFields::PACKBOXSTK,
CustomFields::ZA08_WEIGHT,
CustomFields::DIMBREITE,
CustomFields::DIMHOEHE,
CustomFields::DIMLAENGE,
],
'relations' => [
[
'id' => Uuid::randomHex(),
'customFieldSetId' => Uuid::randomHex(),
'entityName' => ProductDefinition::ENTITY_NAME,
],
],
];
}
}