vendor/crehler/product-files/src/CrehlerProductFiles.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Crehler\ProductFiles;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Crehler\ProductFiles\Installer\CustomFieldInstaller;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. class CrehlerProductFiles extends Plugin
  12. {
  13.     const IMPORT_1_PROFILE_ID 'de9264aee0444a7c87facf63e7c0a612';
  14.     const IMPORT_2_PROFILE_ID '032450b4ccb042ee93eb38cac00029af';
  15.     /**
  16.      * @param ActivateContext $activateContext
  17.      */
  18.     public function activate(ActivateContext $activateContext): void
  19.     {
  20.         parent::activate($activateContext);
  21.         (new CustomFieldInstaller($this->container))->upsertCustomFields($activateContext->getContext());
  22.     }
  23.     /**
  24.      * @param UninstallContext $uninstallContext
  25.      */
  26.     public function uninstall(UninstallContext $uninstallContext): void
  27.     {
  28.         parent::uninstall($uninstallContext);
  29.         if ($uninstallContext->keepUserData()) {
  30.             return;
  31.         }
  32.         $connection $this->container->get(Connection::class);
  33.         $connection->executeUpdate('DROP TABLE IF EXISTS `product_files`');
  34.         (new CustomFieldInstaller($this->container))->removeCustomFields($uninstallContext->getContext());
  35.     }
  36.     public function install(InstallContext $installContext): void
  37.     {
  38.         $this->upsertImportExportProfile();
  39.         parent::install($installContext);
  40.     }
  41.     public function update(UpdateContext $updateContext): void
  42.     {
  43.         $this->upsertImportExportProfile();
  44.         parent::update($updateContext);
  45.     }
  46.     private function upsertImportExportProfile()
  47.     {
  48.         $data = [
  49.             [
  50.                 'id' => self::IMPORT_1_PROFILE_ID,
  51.                 'name' => 'Pliki do pobrania - linki',
  52.                 'label' => 'Pliki do pobrania - linki',
  53.                 'systemDefault' => true,
  54.                 'sourceEntity' => 'product_files_links',
  55.                 'fileType' => 'text/csv',
  56.                 'delimiter' => ';',
  57.                 'enclosure' => '"',
  58.                 'mapping' => [
  59.                     [
  60.                         'key' => 'id',
  61.                         'mappedKey' => 'id'
  62.                     ],
  63.                     [
  64.                         'key' => 'productNumber',
  65.                         'mappedKey' => 'kod'
  66.                     ], [
  67.                         'key' => 'name',
  68.                         'mappedKey' => 'name'
  69.                     ], [
  70.                         'key' => 'link',
  71.                         'mappedKey' => 'link'
  72.                     ]
  73.                 ]
  74.             ],
  75.             [
  76.                 'id' => self::IMPORT_2_PROFILE_ID,
  77.                 'name' => 'Pliki do pobrania - pliki',
  78.                 'label' => 'Pliki do pobrania - pliki',
  79.                 'systemDefault' => true,
  80.                 'sourceEntity' => 'product_files',
  81.                 'fileType' => 'text/csv',
  82.                 'delimiter' => ';',
  83.                 'enclosure' => '"',
  84.                 'mapping' => [
  85.                     [
  86.                         'key' => 'id',
  87.                         'mappedKey' => 'id'
  88.                     ],
  89.                     [
  90.                         'key' => 'productNumber',
  91.                         'mappedKey' => 'productNumber'
  92.                     ], [
  93.                         'key' => 'name',
  94.                         'mappedKey' => 'name'
  95.                     ], [
  96.                         'key' => 'link',
  97.                         'mappedKey' => 'link'
  98.                     ]
  99.                 ]
  100.             ]
  101.         ];
  102.         $entityRepository $this->container->get('import_export_profile.repository');
  103.         $entityRepository->upsert($dataContext::createDefaultContext());
  104.     }
  105. }