<?php declare(strict_types=1);
namespace HbHOfflineCart;
use Etagen\ProjectConfig\Installer\CustomFieldInstaller;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\CustomField\CustomFieldTypes;
class HbHOfflineCart extends Plugin
{
public static array $customFieldSets = [
[
'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_ID,
'name' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_NAME,
'global' => true,
'config' => [
'label' => [
'en-GB' => 'Offline cart settings',
'de-DE' => 'Offline Warenkorb Einstellungen',
],
],
'relation' => [
'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_RELATION_ID,
'entityName' => 'customer',
],
]
];
public static array $customFields = [
[
'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_OFFLINE_CART_ID,
'name' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_OFFLINE_CART_NAME,
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'en_GB' => 'Allow offline cart',
'de_DE' => 'Erlaube Offline Warenkorb',
],
'componentName' => 'sw-field',
'customFieldType' => 'text',
'customFieldPosition' => 10,
],
'customFieldSetId' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_ID,
]
];
public function install(InstallContext $installContext): void
{
$customFieldInstaller = new CustomFieldInstaller($this->container);
$customFieldInstaller->install(self::$customFieldSets, self::$customFields, $installContext);
parent::install($installContext);
}
public function update(UpdateContext $updateContext): void
{
$customFieldInstaller = new CustomFieldInstaller($this->container);
$customFieldInstaller->update(self::$customFieldSets, self::$customFields, $updateContext);
parent::update($updateContext);
}
public function uninstall(UninstallContext $uninstallContext): void
{
$customFieldInstaller = new CustomFieldInstaller($this->container);
if ($uninstallContext->keepUserData()) {
$customFieldInstaller->uninstall(self::$customFieldSets, self::$customFields, $uninstallContext);
parent::uninstall($uninstallContext);
return;
}
$customFieldInstaller->remove(self::$customFieldSets, self::$customFields, $uninstallContext);
parent::uninstall($uninstallContext);
}
}