<?php declare(strict_types=1);
namespace DreiwmBrandstetterPlugin;
use Exception;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Context;
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\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\Aggregate\CustomFieldSet\CustomFieldSetDefinition;
use Shopware\Core\System\CustomField\Aggregate\CustomFieldSet\CustomFieldSetEntity;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Shopware\Storefront\Framework\ThemeInterface;
class DreiwmBrandstetterPlugin extends Plugin implements ThemeInterface
{
public const PROPERTY_GROUP_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a5d';
public const STD = 'STD';
public const VARIANT_NAME_STD = 'std';
public const VARIANT_ID_STD = 'c6a5d1be343d4376ac440d82f838c8f0';
public const VARIANT_NAME_MON = 'mon';
public const VARIANT_ID_MON = '82ca30fe41504de5bbfd3161401e3813';
public const VARIANT_NAME_TUE = 'tue';
public const VARIANT_ID_TUE = '957270d5f121426d9a0b2eb3ce63a39a';
public const VARIANT_NAME_WED = 'wed';
public const VARIANT_ID_WED = '2aee8f873a484a36a1fd0ef366bb8f02';
public const VARIANT_NAME_THU = 'thu';
public const VARIANT_ID_THU = 'ede038e7681e48308faa05152be6b880';
public const VARIANT_NAME_FRI = 'fri';
public const VARIANT_ID_FRI = 'b3fc7149574d4db48e15588788efad63';
public const VARIANT_NAME_SAT = 'sat';
public const VARIANT_ID_SAT = 'f00e21d744ba4290bb8c1a4f26410a03';
public const VARIANT_NAME_SUN = 'sun';
public const VARIANT_ID_SUN = 'bcdcc40a36114067ba79e6bb0187f838';
public const MAXIMUM_FREE_LOCKER = 20;
public const ALLERGENE_SW_NAME = 'enthaltene Allergene';
public const ALLERGENS_PROPERTY_GROUP_ID = '584624366d4a4ccdac467c1215630aa6';
public const ZUSATZSTOFFE_SW_NAME = 'Zusatzstoffe';
public const ZUSATZSTOFFE_ID = '17d768315c2d4fb8bf3a3eeaadb11f88';
public const SPUREN_VON_ALLERGENEN_SW_NAME = 'kann Spuren von folgenden Allergenen enthalten';
public const SPUREN_VON_ALLERGENEN_ID = 'f36da04f7da24034b48615b56c7ea951';
public const ERNAEHRUNGSFORM_SW_NAME = 'Ernährungsform';
public const ERNAEHRUNGSFORM_ID = '152bdcea1b6546808a67d9b4abe741db';
public const LIEFERART_NAME = 'Lieferart';
public const LIEFERART_ID = 'ac610cedc9364216b01ee06a4bc442b2';
public const LIEFERART_POST_ID = self::POST_ID;
public const LIEFERART_RADBOTEN_ID = self::RADBOTEN_ID;
public const LIEFERART_RADBOTEN_PLZ_97070_NAME = 'Radboten, PLZ 97070';
public const LIEFERART_RADBOTEN_PLZ_97070_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a5d';
public const LIEFERART_RADBOTEN_PLZ_97070_EXPRESS_NAME = 'Radboten Express, PLZ 97070';
public const LIEFERART_RADBOTEN_PLZ_97070_EXPRESS_ID = 'e0823808e86f41b89b2f07ad9cb3340e';
public const LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97070';
public const LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_ID = 'c6a468edf5fd43e5bb9c711673486fe8';
public const LIEFERART_RADBOTEN_PLZ_97072_NAME = 'Radboten, PLZ 97072';
public const LIEFERART_RADBOTEN_PLZ_97072_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a5e';
public const LIEFERART_RADBOTEN_PLZ_97072_EXPRESS_NAME = 'Radboten Express, PLZ 97072';
public const LIEFERART_RADBOTEN_PLZ_97072_EXPRESS_ID = '35f8d4f21a8b46658229b0fba6daa909';
public const LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97072';
public const LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_ID = 'a1c6f2fb26dc45c6b09824f6fd657d96';
public const LIEFERART_RADBOTEN_PLZ_97074_NAME = 'Radboten, PLZ 97074';
public const LIEFERART_RADBOTEN_PLZ_97074_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a5f';
public const LIEFERART_RADBOTEN_PLZ_97074_EXPRESS_NAME = 'Radboten Express, PLZ 97074';
public const LIEFERART_RADBOTEN_PLZ_97074_EXPRESS_ID = '73894e97e95b48219f0c47fc3fc781f0';
public const LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97074';
public const LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_ID = '1da4629edb1a4a54856cc93f308bfb4b';
public const LIEFERART_RADBOTEN_PLZ_97076_NAME = 'Radboten, PLZ 97076';
public const LIEFERART_RADBOTEN_PLZ_97076_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a60';
public const LIEFERART_RADBOTEN_PLZ_97076_EXPRESS_NAME = 'Radboten Express, PLZ 97076';
public const LIEFERART_RADBOTEN_PLZ_97076_EXPRESS_ID = '7fa8a41112cf49dcb87d4f1b830f458e';
public const LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97076';
public const LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_ID = 'e931c0fdc2434ddf9e8e0f5b6fbfa4f4';
public const LIEFERART_RADBOTEN_PLZ_97078_NAME = 'Radboten, PLZ 97078';
public const LIEFERART_RADBOTEN_PLZ_97078_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a61';
public const LIEFERART_RADBOTEN_PLZ_97078_EXPRESS_NAME = 'Radboten Express, PLZ 97078';
public const LIEFERART_RADBOTEN_PLZ_97078_EXPRESS_ID = '5205cc7facec45d89e0ffe82ac4014e2';
public const LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97078';
public const LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_ID = 'c316dc1a63334c4e9f9ab0683ae3534b';
public const LIEFERART_RADBOTEN_PLZ_97080_NAME = 'Radboten, PLZ 97080';
public const LIEFERART_RADBOTEN_PLZ_97080_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a62';
public const LIEFERART_RADBOTEN_PLZ_97080_EXPRESS_NAME = 'Radboten Express, PLZ 97080';
public const LIEFERART_RADBOTEN_PLZ_97080_EXPRESS_ID = '58393edb9a0b4328bae68801f28a73f9';
public const LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97080';
public const LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_ID = '3a269ee49b484cb49dacb9191c1e3e91';
public const LIEFERART_RADBOTEN_PLZ_97082_NAME = 'Radboten, PLZ 97082';
public const LIEFERART_RADBOTEN_PLZ_97082_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a63';
public const LIEFERART_RADBOTEN_PLZ_97082_EXPRESS_NAME = 'Radboten Express, PLZ 97082';
public const LIEFERART_RADBOTEN_PLZ_97082_EXPRESS_ID = 'd6ce8df5d0304b5c830749897d9781c1';
public const LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97082';
public const LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_ID = '1662f6023e5947b3894738ee175e4a34';
public const LIEFERART_RADBOTEN_PLZ_97084_NAME = 'Radboten, PLZ 97084';
public const LIEFERART_RADBOTEN_PLZ_97084_ID = 'f9a9a3a3a3a34f6c9a7e0d2c2f8a1a64';
public const LIEFERART_RADBOTEN_PLZ_97084_EXPRESS_NAME = 'Radboten Express, PLZ 97084';
public const LIEFERART_RADBOTEN_PLZ_97084_EXPRESS_ID = 'c92312a3a1c148f6b8d6450dad5ebbd7';
public const LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_NAME = 'Radboten Express Sonntag, PLZ 97084';
public const LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_ID = '52b2f0a567374de5bd78d95ab395b80f';
public const LIEFERART_ABHOLUNG_ID = self::ABHOLUNG_ID;
public const LIEFERART_PAKETSTATION_ID = self::PAKETSTATION_ID;
public const ZUTATEN_NAME = 'Deklaration / Zutaten';
public const ZUTATEN_ID = '7ff79d6c69624d4fabea55f2664d7d7e';
public const ABHOLUNG_ID = 'a3ad016852174f80a82c267ccbe01ef7';
public const ABHOLUNG_NAME = 'Abholung in Hauptfiliale';
public const PAKETSTATION_ID = '4917dec202424ba8987b3972c77e7b89';
public const PAKETSTATION_NAME = 'Packstation';
public const POST_ID = '980b558c95dd4f8086840954d5b149c3';
public const POST_NAME = 'Post';
public const RADBOTEN_ID = '53a70404aeac4a3c8296f13a148c6c53';
public const RADBOTEN_NAME = 'Radboten';
public const DELIVERYTIME_ID = 'eab6ae6cfc344fddbe44cab068802fb5';
const MAIL_TEMPLATE_ID = '0abc616a2bc941a9b12cdcc51dae9e18';
public const SPUREN_VON_ALLERGENEN_CSV_NAME = 'Spuren v.Allergenen';
public const BRENNWERT_KJ_PROPERTY_GROUP_ID = 'eb85dfd0cb194998b342cc573cfca29e';
public const SPUREN_ALLERGENE_PROPERTY_GROUP_ID = '6f0472a9d6824bf2a14b05a17842a517';
public const BRENNWERT_IN_KCAL_CSV = 'KCal / Fertig';
public const FETT_PROPERTY_GROUP_ID = '8265b24ec12c4207a9b68a6b595455d4';
public const ZUSATZSTOFFE_PROPERTY_GROUP_ID = '6f95893400b441808c5859768e708e11';
public const DZUCKER_CSV_NAME = 'DZucker / Fertig';
public const BRENNWERT_IN_KJ_CSV_NAME = 'KJ / Fertig';
public const KCAL_CSV_NAME = 'KCal / Fertig';
public const DZUCKER_PROPERTY_ID = 'a02b6739ede6415883b727256c8cfbb9';
public const KOHLENHYDRATE_PROPERTY_ID = '5b2c3355dd8f4a5fb0a77181334e7074';
public const KH_CSV_NAME = 'KH / Fertig';
public const EISWEISS_PROPERTY_ID = '90c4c7238b704aa5bd23ea617ba868b8';
public const GES_FETT_CSV_NAME = 'Ges.Fett / Fertig';
public const FERTIGGEWICHT_CSV_NAME = 'Fertiggewicht';
public const KCAL_SW_NAME = 'kcal';
public const BRENNWERT_IN_KCAL_PROPERTY_GROUP_ID = '7affa9d53b824e419f90e48cba2d9f88';
public const FETT_CSV_NAME = 'Fett / Fertig';
public const EISWEISS_CSV_NAME = 'Eiweiss / Fertig';
public const GES_FETT_PROPERTY_GROUP_ID = '883ea3f0a87f44f9996209fe07e8331a';
public const ALLERGENE_CSV_NAME = 'Allergene';
const ERNAEHRUNGSFORM_PROPERTY_GROUP_ID = '106be7de8500446d9dfc05506dd8c143';
const KJ_SW_NAME = 'kj';
const FETT_SW_NAME = 'Fett';
const GES_FETT_SW_NAME = 'davon gesättigte Fettsäuren';
const KH_SW_NAME = 'Kohlenhydrate';
const DZUCKER_SW_NAME = 'davon Zucker';
const EISWEISS_SW_NAME = 'Eiweiß';
const SALZ_PROPERTY_ID = 'bf9798bc50f34ba8befeea4b1e3c753c';
const SALZ_SW_NAME = 'Salz';
const SALZ_CSV_NAME = 'Salz / Fertig';
const UNIT_KG_ID = '3565027a088a4406b0ea7a496b782237';
const BACKTAGE_PROPERTY_ID = '2b5bfb9ebdb948bfbd13b9bdf79c67ed';
const BACKTAGE_PROPERTY_NAME = 'Backtage';
public function install(Plugin\Context\InstallContext $installContext): void
{
// hole SystemConfigContainer um Einstellungen zu setzen
$services = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
// definiere Captchas
$basicCaptcha = [
'honeypot' => ['name' => 'honeypot', 'isActive' => true],
'basicCaptcha' => ['name' => 'basicCaptcha', 'isActive' => true],
'googleReCaptchaV2' => ['name' => 'googleReCaptchaV2', 'isActive' => false],
'googleReCaptchaV3' => [
'name' => 'googleReCaptchaV3',
'isActive' => false,
'siteKey' => '',
'secretKey' => '',
'threshold' => 0.5
],
];
// setze Captchas
$services->set('core.basicInformation.activeCaptchasV2', $basicCaptcha);
// setze familienfreundlicher Shop auf true
$services->set('core.basicInformation.familyFriendly', true);
// setze Produktbewertungen auf false. Geht aber leider nicht. Weiß nicht warum.
$services->set('core.productReviews.isActive', false);
// Zusatzfelder installieren
$this->createOrUpdateCustomFields();
try {
// Lieferzeiten installieren
$this->createDeliveryTime();
} catch (Exception $exception) {
// No, we've already installed the fields, it's fine.
}
try {
// Eigenschaften installieren
$this->createPropertiesOld();
} catch (Exception $exception) {
// No, we've already installed the fields, it's fine.
}
try {
// Lieferzeiten installieren
$this->createShippingMethod(self::ABHOLUNG_ID, self::ABHOLUNG_NAME);
} catch (Exception $exception) {
// No, we've already installed the fields, it's fine.
}
try {
// Lieferzeiten installieren
$this->createShippingMethod(self::PAKETSTATION_ID, self::PAKETSTATION_NAME);
} catch (Exception $exception) {
// No, we've already installed the fields, it's fine.
}
$this->initializeShippingMethods();
}
/**
* Erstellt neue Lieferarten
* @param array $shippingMethods Array mit den Lieferarten
* @return void
*/
private function createMultipleShippingMethods(array $shippingMethods): void
{
foreach ($shippingMethods as $method) {
$this->createShippingMethod($method['id'], $method['name']);
}
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
if (version_compare($updateContext->getCurrentPluginVersion(), '1.4.0', '<')) {
/** @var EntityRepositoryInterface $customFieldSetRepository */
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->upsert([
[
// Bestehendes Custom-Field-Set
'id' => '1035f6fe82db4caea82ccc0e8491edae',
'customFields' => [
[
'name' => 'baking_days',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 7,
'label' => [
'de-DE' => 'Backtage',
'en-GB' => 'Baking Days',
],
'helpText' => [
'de-DE' => 'Backtage. Wenn leer, dann wird an allen Tagen gebacken.',
'en-GB' => 'Baking Days',
],
],
],
],
],
], Context::createDefaultContext());
}
// if (version_compare($updateContext->getCurrentPluginVersion(), '1.2.0', '<')) {
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_ID, self::LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_ID, self::LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_ID, self::LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_ID,
// self::LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_ID,
// self::LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_ID,
// self::LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_ID,
// self::LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_NAME);
// $this->createPropertyOption(self::LIEFERART_ID, self::LIEFERART_NAME,
// self::LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_ID, self::LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_NAME);
// }
}
/**
* Initialisiert die Lieferarten
* @return void
*/
private function initializeShippingMethods(): void
{
$shippingMethods = [
[
'id' => self::PAKETSTATION_ID,
'name' => self::PAKETSTATION_NAME
],
[
'id' => self::POST_ID,
'name' => self::POST_NAME
],
[
'id' => self::RADBOTEN_ID,
'name' => self::RADBOTEN_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97070_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97070_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97070_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97070_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97070_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97072_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97072_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97072_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97072_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97072_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97074_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97074_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97074_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97074_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97074_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97076_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97076_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97076_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97076_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97076_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97078_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97078_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97078_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97078_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97078_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97080_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97080_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97080_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97080_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97080_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97082_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97082_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97082_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97082_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97082_SUNDAY_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97084_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97084_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97084_EXPRESS_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97084_EXPRESS_NAME
],
[
'id' => self::LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_ID,
'name' => self::LIEFERART_RADBOTEN_PLZ_97084_SUNDAY_NAME
]
];
$this->createMultipleShippingMethods($shippingMethods);
}
/**
* Beim Aktivieren des Plugins wird das Installationsdatum auf einen festen Wert, der weit in der
* Vergangenheit liegt gesetzt. Dies ist notwendig, damit das 3WM-Plugin immer als erstes geladen wird und andere
* Plugins das 3WM-Plugin nicht überschreiben.
* @param ActivateContext $activateContext
* @return void
*/
public function activate(ActivateContext $activateContext): void
{
// Aufruf der Eltern-Methode um das Plugin zu aktivieren
parent::activate($activateContext);
}
/**
* Diese Methode erstellt eine neue Lieferzeit und weist diese den vom Plugin erstellen Lieferarten zu,
* da Shopware die Lieferzeit braucht, um eine Versandart zu erstellen.
* Es wird eine neue Lieferzeit erstellt, da man keinen Marker für bestehende Lieferzeiten hat
*/
private function createDeliveryTime(): void
{
/** @var EntityRepositoryInterface $deliveryTimeRepository */
// hole das delivery_time.repository
$deliveryTimeRepository = $this->container->get('delivery_time.repository');
$deliveryTimeRepository->upsert([
[
'id' => self::DELIVERYTIME_ID,
'min' => 1,
'max' => 2,
'unit' => 'day',
'translations' => [
[
'languageId' => Defaults::LANGUAGE_SYSTEM,
'name' => '1-2 Tage',
],
],
]
], Context::createDefaultContext());
}
private function getDefaultRuleIdForShippingMethod(): ?string
{
// get a Rule
$criteria = new Criteria();
/** @var EntityRepositoryInterface $ruleRepository */
// hole das rule.repository
$ruleRepository = $this->container->get('rule.repository');
// suche nach dem Namen 'Always valid (Default)' in der Spalte 'name'
$criteria->addFilter(new EqualsFilter('name', 'Always valid (Default)'));
return $ruleRepository->searchIds($criteria, Context::createDefaultContext())->firstId();
}
private function createShippingMethod(string $shippingMethodId, $shippingMethodName): void
{
/** @var EntityRepositoryInterface $shippingMethodRepository */
// hole das custom_field_set.repository
$shippingMethodRepository = $this->container->get('shipping_method.repository');
// Produkte-Zusatzfelder
$shippingMethodData = [
[
'id' => $shippingMethodId,
'active' => true,
'translations' => [
[
'languageId' => Defaults::LANGUAGE_SYSTEM,
'name' => $shippingMethodName,
],
],
'deliveryTimeId' => self::DELIVERYTIME_ID,
'availabilityRuleId' => $this->getDefaultRuleIdForShippingMethod(),
]
];
try {
$shippingMethodRepository->upsert($shippingMethodData, Context::createDefaultContext());
} catch (Exception $exception) {
// No, we've already installed the fields, it's fine.
}
}
/**
* Erstellt die Zusatzfelder
* @return void
*/
private function createOrUpdateCustomFields(): void
{
/** @var EntityRepositoryInterface $customFieldSetRepository */
// hole das custom_field_set.repository
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
// Produkte-Zusatzfelder
$customFieldSetRepository->upsert([
[
'name' => 'brandstetterProducts',
'id' => '1035f6fe82db4caea82ccc0e8491edae',
'config' => [
'label' => [
'de-DE' => 'Brandstetter-Produkte',
],
],
'customFields' => [
[
'name' => 'kontingent',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'number',
'customFieldPosition' => 1,
'label' => [
'de-DE' => 'Kontingent',
],
],
],
[
'name' => 'packstationMultiplier',
'type' => CustomFieldTypes::FLOAT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'number',
'customFieldPosition' => 2,
'label' => [
'de-DE' => 'Packstation-Multiplikator',
],
],
],
[
'name' => 'zutaten',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'label' => [
'de-DE' => 'Deklaration / Zutaten',
],
],
],
[
'name' => 'product_availability_constraints',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 4,
'label' => [
'de-DE' => 'Verfügbarkeitsbeschränkungen',
],
'description' => [
'de-DE' => 'Hier werden die Verfügbarkeitsbeschränkungen für das Produkt aus BIT aus dem Feld "Freigabe" übernommen.',
]
],
],
[
'name' => 'product_available_from',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'date',
'customFieldPosition' => 5,
'label' => [
'de-DE' => 'Produkt verfügbar ab',
],
'description' => [
'de-DE' => 'Interpretiertes Feld aus availability_constraints',
],
'dateType' => 'datetime',
'config' => [
'time_24hr' => true,
],
'type' => 'date',
],
],
[
'name' => 'product_available_until',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'date',
'customFieldPosition' => 6,
'label' => [
'de-DE' => 'Produkt verfügbar bis',
],
'description' => [
'de-DE' => 'Interpretiertes Feld aus availability_constraints',
],
'dateType' => 'datetime',
'config' => [
'time_24hr' => true,
],
'type' => 'date',
],
],
[
'name' => 'baking_days',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 7,
'label' => [
'de-DE' => 'Backtage',
'en-GB' => 'Baking Days',
],
'helpText' => [
'de-DE' => 'Backtage. Wenn leer, werden alle Tage als Backtage angenommen.',
],
],
],
],
'relations' => [
[
'entityName' => 'product',
],
],
],
], Context::createDefaultContext());
// Bestellungen-Zusatzfelder
$customFieldSetRepository->upsert([
[
'name' => 'brandstetter_orders',
'id' => '1035f6fe82db4caea82ccc0e8491edaf',
'config' => [
'label' => [
'de-DE' => 'Brandstetter-Bestellungen',
],
],
'customFields' => [
[
'name' => 'brandstetter_orders_desired_delivery_date',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'date',
'customFieldPosition' => 1,
'label' => [
'de-DE' => 'Gewünschtes Lieferdatum',
],
'dateType' => 'datetime',
'config' => [
'time_24hr' => true,
],
'type' => 'date',
],
],
[
'name' => 'brandstetter_orders_customer_pin',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 2,
'label' => [
'de-DE' => 'Kunden-PIN',
],
],
],
[
'name' => 'brandstetter_orders_merchant_pin',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'label' => [
'de-DE' => 'Händler-PIN',
],
],
],
[
'name' => 'brandstetter_orders_desired_delivery_timeRange_radboten',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 3,
'label' => [
'de-DE' => 'Gewünschte Lieferzeit (Radboten)',
],
],
],
[
'name' => 'brandstetter_orders_desired_dropoff_location',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 4,
'label' => [
'de-DE' => 'Gewünschter Ablageort',
],
],
]
],
'relations' => [
[
'entityName' => 'order',
],
],
],
], Context::createDefaultContext());
}
/**
* Erstellt die Eigenschaften für die Lieferzeit
* @return void
*/
private function createPropertiesOld(): void
{
// Context erstellen
$context = Context::createDefaultContext();
// Ids werden festgelegt, damit diese in allen Umgebungen gleich sind und überall darauf zugegriffen werden kann
$propertyGroup = [
'name' => 'Kontingenttag',
'id' => self::PROPERTY_GROUP_ID,
'displayType' => 'text',
'sortingType' => 'numeric',
'options' => [
[
'id' => self::VARIANT_ID_MON,
'name' => self::VARIANT_NAME_MON,
'position' => 1,
],
[
'id' => self::VARIANT_ID_TUE,
'name' => self::VARIANT_NAME_TUE,
'position' => 2,
],
[
'id' => self::VARIANT_ID_WED,
'name' => self::VARIANT_NAME_WED,
'position' => 3,
],
[
'id' => self::VARIANT_ID_THU,
'name' => self::VARIANT_NAME_THU,
'position' => 4,
],
[
'id' => self::VARIANT_ID_FRI,
'name' => self::VARIANT_NAME_FRI,
'position' => 5,
],
[
'id' => self::VARIANT_ID_SAT,
'name' => self::VARIANT_NAME_SAT,
'position' => 6,
],
[
'id' => self::VARIANT_ID_SUN,
'name' => self::VARIANT_NAME_SUN,
'position' => 7,
],
[
'id' => self::VARIANT_ID_STD,
'name' => self::VARIANT_NAME_STD,
'position' => 8,
]
]
];
// Eigenschafts-Gruppe erstellen oder aktualisieren
$this->container->get('property_group.repository')->upsert([$propertyGroup], $context);
}
/**
* @param string $propertyId ID der Eigenschaft
* @param string $propertyName Name der Eigenschaft
* @param null $optionId
* @param null $optionName
* @return void
*/
private function createPropertyOption(
string $propertyId,
string $propertyName,
$optionId = null,
$optionName = null
): void {
// Context erstellen
$context = Context::createDefaultContext();
// prüfe ob optionId und optionName gesetzt sind. Wenn ja, dann wird die Option mit der ID und dem Namen erstellt
if ($optionId && $optionName) {
$propertyGroup = [
'id' => $propertyId,
'name' => $propertyName,
'displayType' => 'text',
'sortingType' => 'alphanumeric',
'options' => [
[
'id' => $optionId,
'name' => $optionName,
'position' => 1,
]
]
];
} else {
// wenn nicht, dann wird nur die Eigenschaft erstellt
$propertyGroup = [
'id' => $propertyId,
'name' => $propertyName,
'displayType' => 'text',
'sortingType' => 'alphanumeric',
'filterable' => false
];
}
// Ids werden festgelegt, damit diese in allen Umgebungen gleich sind und überall darauf zugegriffen werden kann
// dd($propertyGroup);
// Eigenschafts-Gruppe erstellen oder aktualisieren
$this->container->get('property_group.repository')->upsert([$propertyGroup], $context);
}
private function createUnit(string $shortCode, string $unitName): void
{
$unitRepository = $this->container->get('unit.repository');
$unitRepository->upsert([
[
'id' => self::UNIT_KG_ID,
'name' => $unitName,
'shortCode' => $shortCode,
'unitTranslation' => [
[
'unitId' => self::UNIT_KG_ID,
'languageId' => Defaults::LANGUAGE_SYSTEM,
'shortCode' => $shortCode,
'unitName' => $unitName
]
]
]
], Context::createDefaultContext());
}
private function createSaisonalCustomFieldSetForProducts(): void
{
/** @var EntityRepositoryInterface $customFieldSetRepository */
// hole das custom_field_set.repository
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
// Inserte das CustomFieldSet für die saisonalen Produkte in brandstetterProducts
$customFieldSetRepository->upsert([
[
'name' => 'brandstetterProducts',
'id' => '1035f6fe82db4caea82ccc0e8491edae',
'config' => [
'label' => [
'de-DE' => 'Brandstetter-Produkte',
],
],
'customFields' => [
[
'name' => 'product_availability_constraints',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 4,
'label' => [
'de-DE' => 'Verfügbarkeitsbeschränkungen',
],
'description' => [
'de-DE' => 'Hier werden die Verfügbarkeitsbeschränkungen für das Produkt aus BIT aus dem Feld "Freigabe" übernommen.',
]
],
],
[
'name' => 'product_available_from',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'date',
'customFieldPosition' => 5,
'label' => [
'de-DE' => 'Produkt verfügbar ab',
],
'description' => [
'de-DE' => 'Interpretiertes Feld aus availability_constraints',
],
'dateType' => 'datetime',
'config' => [
'time_24hr' => true,
],
'type' => 'date',
],
],
[
'name' => 'product_available_until',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'date',
'customFieldPosition' => 6,
'label' => [
'de-DE' => 'Produkt verfügbar bis',
],
'description' => [
'de-DE' => 'Interpretiertes Feld aus availability_constraints',
],
'dateType' => 'datetime',
'config' => [
'time_24hr' => true,
],
'type' => 'date',
],
],
],
],
], Context::createDefaultContext());
}
private function createLockerNumberCustomFieldSet(): void
{
$context = Context::createDefaultContext();
/** @var EntityRepositoryInterface $customFieldRepository */
// hole das custom_field_set.repository
$customFieldRepository = $this->container->get('custom_field.repository');
// Custom Field Set existiert, ID abrufen
// Custom Field Set aktualisieren
// dd($customFieldRepository->search(new Criteria(), $context));
$customFieldRepository->upsert([
[
'id' => \Shopware\Core\Framework\Uuid\Uuid::randomHex(),
'name' => 'brandstetter_orders_box_name',
'type' => CustomFieldTypes::TEXT,
'config' => [
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 5,
'label' => [
'de-DE' => 'Fachname',
],
'description' => [
'de-DE' => 'Fachname der Abholstation',
]
],
'customFieldSetId' => '1035f6fe82db4caea82ccc0e8491edaf',
]
], $context);
// Inserte das CustomFieldSet für die saisonalen Produkte in brandstetterProducts
// $customFieldSetRepository->upsert([
// [
// 'id' => '1035f6fe82db4caea82ccc0e8491edaf',
// 'name' => 'brandstetter_orders',
// 'config' => [
// 'label' => [
// 'de-DE' => 'Brandstetter-Bestellungen',
// ],
// ],
// 'customFields' => [
// [
// 'name' => 'brandstetter_orders_order_locker_number',
// 'type' => CustomFieldTypes::TEXT,
// 'config' => [
// 'componentName' => 'sw-field',
// 'customFieldType' => 'text',
// 'customFieldPosition' => 5,
// 'label' => [
// 'de-DE' => 'Fachnummer',
// ],
// 'description' => [
// 'de-DE' => 'Fachnummer der Abholstation',
// ]
// ],
// ],
// ],
// 'relations' => [
// [
// 'entityName' => 'order',
// ]
// ],
// ]
// ], Context::createDefaultContext());
}
}