custom/static-plugins/AbasConnector/src/AbasConnector.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Abas\AbasConnector;
  4. use Abas\AbasConnector\Service\Core\System\License\DeviceIdCollector;
  5. use Abas\AbasConnector\Service\Mapper\AbasToShopwareMapperEnricherPass;
  6. use Abas\AbasConnector\Service\Mapper\ShopwareToAbasMapperEnricherPass;
  7. use Abas\AbasConnector\Service\Sync\Catalog\CatalogSelector\Enrichers\ProductSelectionEnricherPass;
  8. use Abas\AbasConnector\Service\Sync\Catalog\Product\Enrichers\ProductEnricherPass;
  9. use Abas\AbasConnector\Service\Utils\Installation\CustomerIndexer;
  10. use Shopware\Core\Framework\Context;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  12. use Shopware\Core\Framework\Plugin;
  13. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  14. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  15. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  16. use Shopware\Core\System\SystemConfig\SystemConfigService;
  17. use Symfony\Component\DependencyInjection\ContainerBuilder;
  18. class AbasConnector extends Plugin
  19. {
  20.     /**
  21.      * @param ActivateContext $activateContext
  22.      * @throws InconsistentCriteriaIdsException
  23.      */
  24.     public function activate(ActivateContext $activateContext): void
  25.     {
  26.         $this->installAbasData($activateContext->getContext());
  27.     }
  28.     /**
  29.      * @param UpdateContext $updateContext
  30.      * @return void
  31.      */
  32.     public function postUpdate(UpdateContext $updateContext): void
  33.     {
  34.         $this->installAbasData($updateContext->getContext());
  35.     }
  36.     /**
  37.      * Create abas customergroups
  38.      * Create abas custom fields
  39.      * Set deviceID in config
  40.      *
  41.      * @param Context $context
  42.      * @return void
  43.      * @throws InconsistentCriteriaIdsException
  44.      */
  45.     private function installAbasData(Context $context)
  46.     {
  47.         // TODO: use dependency injection instead of getting container directly
  48.         $registry $this->container->get(CustomerIndexer::class);
  49.         if ($registry !== null) {
  50.             $registry->index();
  51.         }
  52.         $abasCustomerGroupRegistry $this->getAbasCustomerGroupRegistry();
  53.         if ($abasCustomerGroupRegistry !== null) {
  54.             $abasCustomerGroupRegistry->upsertAbasCustomerGroups($context);
  55.         }
  56.         // TODO: use dependency injection instead of getting container directly
  57.         $abasCustomFields $this->container
  58.             ->get('Abas\AbasConnector\Service\Core\System\CustomFields\AbasCustomFields');
  59.         if ($abasCustomFields !== null) {
  60.             $abasCustomFields->create();
  61.         }
  62.         $this->setDeviceIdInPluginConfiguration();
  63.     }
  64.     /**
  65.      * @param UninstallContext $uninstallContext
  66.      * @return void
  67.      * @throws InconsistentCriteriaIdsException
  68.      */
  69.     public function uninstall(UninstallContext $uninstallContext): void
  70.     {
  71.         // TODO: Uninstall abas data - Currently not implemented, because for each abas customer the group needs to be
  72.         // reset to default
  73.     }
  74.     /**
  75.      * Set deviceID in plugin configuration for display purposes.
  76.      *
  77.      * @return void
  78.      */
  79.     private function setDeviceIdInPluginConfiguration()
  80.     {
  81.         $deviceId DeviceIdCollector::getDeviceId();
  82.         $systemConfigService $this->getSystemConfigService();
  83.         if ($systemConfigService instanceof SystemConfigService) {
  84.             $systemConfigService->set('AbasConnector.config.encryptedDeviceId'$deviceId);
  85.         }
  86.     }
  87.     /**
  88.      * @return Service\Core\System\CustomerGroup\AbasCustomerGroupRegistry|object|null
  89.      */
  90.     private function getAbasCustomerGroupRegistry()
  91.     {
  92.         // TODO: use dependency injection instead of getting container directly
  93.         return $this->container->get('Abas\AbasConnector\Service\Core\System\CustomerGroup\AbasCustomerGroupRegistry');
  94.     }
  95.     /**
  96.      * @return object|SystemConfigService|null
  97.      */
  98.     private function getSystemConfigService()
  99.     {
  100.         // TODO: use dependency injection instead of getting container directly
  101.         return $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
  102.     }
  103.     /**
  104.      * @param ContainerBuilder $container
  105.      * @return void
  106.      */
  107.     public function build(ContainerBuilder $container): void
  108.     {
  109.         parent::build($container);
  110.         $container->addCompilerPass(new ProductEnricherPass());
  111.         $container->addCompilerPass(new ProductSelectionEnricherPass());
  112.         $container->addCompilerPass(new AbasToShopwareMapperEnricherPass());
  113.         $container->addCompilerPass(new ShopwareToAbasMapperEnricherPass());
  114.     }
  115. }