custom/static-plugins/HbHOfflineCart/src/HbHOfflineCart.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace HbHOfflineCart;
  3. use Etagen\ProjectConfig\Installer\CustomFieldInstaller;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. use Shopware\Core\System\CustomField\CustomFieldTypes;
  9. class HbHOfflineCart extends Plugin
  10. {
  11.     public static array $customFieldSets = [
  12.         [
  13.             'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_ID,
  14.             'name' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_NAME,
  15.             'global' => true,
  16.             'config' => [
  17.                 'label' => [
  18.                     'en-GB' => 'Offline cart settings',
  19.                     'de-DE' => 'Offline Warenkorb Einstellungen',
  20.                 ],
  21.             ],
  22.             'relation' => [
  23.                 'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_RELATION_ID,
  24.                 'entityName' => 'customer',
  25.             ],
  26.         ]
  27.     ];
  28.     public static array $customFields = [
  29.         [
  30.             'id' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_OFFLINE_CART_ID,
  31.             'name' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_OFFLINE_CART_NAME,
  32.             'type' => CustomFieldTypes::TEXT,
  33.             'config' => [
  34.                 'label' => [
  35.                     'en_GB' => 'Allow offline cart',
  36.                     'de_DE' => 'Erlaube Offline Warenkorb',
  37.                 ],
  38.                 'componentName' => 'sw-field',
  39.                 'customFieldType' => 'text',
  40.                 'customFieldPosition' => 10,
  41.             ],
  42.             'customFieldSetId' => Defaults::CUSTOM_FIELD_SET_CUSTOMER_SETTING_ID,
  43.         ]
  44.     ];
  45.     public function install(InstallContext $installContext): void
  46.     {
  47.         $customFieldInstaller = new CustomFieldInstaller($this->container);
  48.         $customFieldInstaller->install(self::$customFieldSetsself::$customFields$installContext);
  49.         parent::install($installContext);
  50.     }
  51.     public function update(UpdateContext $updateContext): void
  52.     {
  53.         $customFieldInstaller = new CustomFieldInstaller($this->container);
  54.         $customFieldInstaller->update(self::$customFieldSetsself::$customFields$updateContext);
  55.         parent::update($updateContext);
  56.     }
  57.     public function uninstall(UninstallContext $uninstallContext): void
  58.     {
  59.         $customFieldInstaller = new CustomFieldInstaller($this->container);
  60.         if ($uninstallContext->keepUserData()) {
  61.             $customFieldInstaller->uninstall(self::$customFieldSetsself::$customFields$uninstallContext);
  62.             parent::uninstall($uninstallContext);
  63.             return;
  64.         }
  65.         $customFieldInstaller->remove(self::$customFieldSetsself::$customFields$uninstallContext);
  66.         parent::uninstall($uninstallContext);
  67.     }
  68. }