<?phpdeclare(strict_types=1);namespace Abas\AbasConnector;use Abas\AbasConnector\Service\Core\System\License\DeviceIdCollector;use Abas\AbasConnector\Service\Mapper\AbasToShopwareMapperEnricherPass;use Abas\AbasConnector\Service\Mapper\ShopwareToAbasMapperEnricherPass;use Abas\AbasConnector\Service\Sync\Catalog\CatalogSelector\Enrichers\ProductSelectionEnricherPass;use Abas\AbasConnector\Service\Sync\Catalog\Product\Enrichers\ProductEnricherPass;use Abas\AbasConnector\Service\Utils\Installation\CustomerIndexer;use Shopware\Core\Framework\Context;use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;use Shopware\Core\Framework\Plugin;use Shopware\Core\Framework\Plugin\Context\ActivateContext;use Shopware\Core\Framework\Plugin\Context\UninstallContext;use Shopware\Core\Framework\Plugin\Context\UpdateContext;use Shopware\Core\System\SystemConfig\SystemConfigService;use Symfony\Component\DependencyInjection\ContainerBuilder;class AbasConnector extends Plugin{ /** * @param ActivateContext $activateContext * @throws InconsistentCriteriaIdsException */ public function activate(ActivateContext $activateContext): void { $this->installAbasData($activateContext->getContext()); } /** * @param UpdateContext $updateContext * @return void */ public function postUpdate(UpdateContext $updateContext): void { $this->installAbasData($updateContext->getContext()); } /** * Create abas customergroups * Create abas custom fields * Set deviceID in config * * @param Context $context * @return void * @throws InconsistentCriteriaIdsException */ private function installAbasData(Context $context) { // TODO: use dependency injection instead of getting container directly $registry = $this->container->get(CustomerIndexer::class); if ($registry !== null) { $registry->index(); } $abasCustomerGroupRegistry = $this->getAbasCustomerGroupRegistry(); if ($abasCustomerGroupRegistry !== null) { $abasCustomerGroupRegistry->upsertAbasCustomerGroups($context); } // TODO: use dependency injection instead of getting container directly $abasCustomFields = $this->container ->get('Abas\AbasConnector\Service\Core\System\CustomFields\AbasCustomFields'); if ($abasCustomFields !== null) { $abasCustomFields->create(); } $this->setDeviceIdInPluginConfiguration(); } /** * @param UninstallContext $uninstallContext * @return void * @throws InconsistentCriteriaIdsException */ public function uninstall(UninstallContext $uninstallContext): void { // TODO: Uninstall abas data - Currently not implemented, because for each abas customer the group needs to be // reset to default } /** * Set deviceID in plugin configuration for display purposes. * * @return void */ private function setDeviceIdInPluginConfiguration() { $deviceId = DeviceIdCollector::getDeviceId(); $systemConfigService = $this->getSystemConfigService(); if ($systemConfigService instanceof SystemConfigService) { $systemConfigService->set('AbasConnector.config.encryptedDeviceId', $deviceId); } } /** * @return Service\Core\System\CustomerGroup\AbasCustomerGroupRegistry|object|null */ private function getAbasCustomerGroupRegistry() { // TODO: use dependency injection instead of getting container directly return $this->container->get('Abas\AbasConnector\Service\Core\System\CustomerGroup\AbasCustomerGroupRegistry'); } /** * @return object|SystemConfigService|null */ private function getSystemConfigService() { // TODO: use dependency injection instead of getting container directly return $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService'); } /** * @param ContainerBuilder $container * @return void */ public function build(ContainerBuilder $container): void { parent::build($container); $container->addCompilerPass(new ProductEnricherPass()); $container->addCompilerPass(new ProductSelectionEnricherPass()); $container->addCompilerPass(new AbasToShopwareMapperEnricherPass()); $container->addCompilerPass(new ShopwareToAbasMapperEnricherPass()); }}