<?php
declare(strict_types=1);
namespace Wbfk\ImportExport;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class WbfkImportExport extends Plugin
{
/**
* @param ActivateContext $activateContext
*/
public function activate(ActivateContext $activateContext): void
{
/** @var EntityRepository $customFieldSetRepository */
$customFieldSetRepository = $this->container->get(
'custom_field_set.repository'
);
$fieldSets = $this->getCustomFieldSets();
foreach ($fieldSets as $fieldSet) {
$customFieldSetRepository->upsert(
[$fieldSet],
$activateContext->getContext()
);
}
}
/**
* @return array
*/
private function getCustomFieldSets(): array
{
$fieldsets = [];
$position = 10000;
$fieldsets[] = [
'id' => 'a624bf80beef4696abeb8b09e223e6c5',
'name' => 'wbfk_category_data',
'active' => true,
'global' => true,
'config' => [
'translated' => true,
'label' => [
'en-GB' => 'WBFK Import - Custom fields for categories',
'de-DE' => 'WBFK Import - Freitextfelder für Kategorien',
],
],
'customFields' => [
[
'id' => '9bf2e5f60fd046bf8977998a635ff861',
'name' => 'wbfk_category_oxid_id',
'type' => CustomFieldTypes::TEXT,
'config' => [
'customFieldPosition' => $position++,
'label' => [
'en-GB' => 'Oxid category ID',
'de-DE' => 'Oxid Kategorie ID',
],
],
],
[
'id' => 'be6f3a96eea64bcd924868acc18bb16e',
'name' => 'wbfk_topsellerTreshold',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'customFieldPosition' => $position++,
'label' => [
'en-GB' => 'Number of sold units from which a product is marked as top seller',
'de-DE' => 'Anzahl notwendiger verkaufter Stück, ab denen ein Produkt als Topseller markiert wird',
],
],
],
],
'relations' => [
[
'id' => '438863628a7f499ca6d6c602c4b68d70',
'entityName' => 'category',
],
],
];
$position = 10000;
$fieldsets[] = [
'id' => 'd3939f14c5f545d98ecb02fe06aa0590',
'name' => 'wbfk_customer_data',
'active' => true,
'global' => true,
'config' => [
'translated' => true,
'label' => [
'en-GB' => 'WBFK Import - Custom fields for customers',
'de-DE' => 'WBFK Import - Freitextfelder für Kunden',
],
],
'customFields' => [
[
'id' => '87515dac1402485db3043c30cfc3c9aa',
'name' => 'wbfk_customer_oxid_id',
'type' => CustomFieldTypes::TEXT,
'config' => [
'customFieldPosition' => $position++,
'label' => [
'en-GB' => 'Oxid customer ID',
'de-DE' => 'Oxid Kunden ID',
],
],
],
],
'relations' => [
[
'id' => 'a6f630c1af9f4690887af3ee134de8a1',
'entityName' => 'customer',
],
],
];
return $fieldsets;
}
}