custom/plugins/SwagSocialShopping/src/SwagSocialShopping.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace SwagSocialShopping;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  11. use Shopware\Core\Framework\Plugin;
  12. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  13. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  14. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  15. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  17. use SwagSocialShopping\Installer\CustomFieldInstaller;
  18. use SwagSocialShopping\Installer\SalesChannelInstaller;
  19. class SwagSocialShopping extends Plugin
  20. {
  21.     public const SALES_CHANNEL_TYPE_SOCIAL_SHOPPING '9ce0868f406d47d98cfe4b281e62f098';
  22.     public const SOCIAL_SHOPPING_SALES_CHANNEL_WRITTEN_EVENT 'swag_social_shopping_sales_channel.written';
  23.     private const SWAG_SOCIAL_SHOPPING_SALES_CHANNEL_PRIVILEGE_KEY 'swag_social_shopping_sales_channel:';
  24.     private const SWAG_SOCIAL_SHOPPING_PRODUCT_ERROR_PRIVILEGE_KEY 'swag_social_shopping_product_error:';
  25.     public function activate(ActivateContext $activateContext): void
  26.     {
  27.         parent::activate($activateContext);
  28.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  29.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  30.         (new CustomFieldInstaller($customFieldSetRepository))->activate($activateContext);
  31.         (new SalesChannelInstaller($this->container))->activate($activateContext);
  32.     }
  33.     public function deactivate(DeactivateContext $deactivateContext): void
  34.     {
  35.         parent::deactivate($deactivateContext);
  36.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  37.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  38.         (new CustomFieldInstaller($customFieldSetRepository))->deactivate($deactivateContext);
  39.         (new SalesChannelInstaller($this->container))->deactivate($deactivateContext);
  40.     }
  41.     public function install(InstallContext $installContext): void
  42.     {
  43.         parent::install($installContext);
  44.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  45.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  46.         (new CustomFieldInstaller($customFieldSetRepository))->install($installContext);
  47.         (new SalesChannelInstaller($this->container))->install($installContext);
  48.     }
  49.     public function uninstall(UninstallContext $uninstallContext): void
  50.     {
  51.         parent::uninstall($uninstallContext);
  52.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  53.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  54.         (new CustomFieldInstaller($customFieldSetRepository))->uninstall($uninstallContext);
  55.         (new SalesChannelInstaller($this->container))->uninstall($uninstallContext);
  56.     }
  57.     public function update(UpdateContext $updateContext): void
  58.     {
  59.         parent::update($updateContext);
  60.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  61.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  62.         (new CustomFieldInstaller($customFieldSetRepository))->update($updateContext);
  63.         (new SalesChannelInstaller($this->container))->update($updateContext);
  64.     }
  65.     public function enrichPrivileges(): array
  66.     {
  67.         return [
  68.             'sales_channel.viewer' => [
  69.                 self::SWAG_SOCIAL_SHOPPING_SALES_CHANNEL_PRIVILEGE_KEY 'read',
  70.                 self::SWAG_SOCIAL_SHOPPING_PRODUCT_ERROR_PRIVILEGE_KEY 'read',
  71.                 'seo_url:read',
  72.                 'product_visibility:read',
  73.             ],
  74.             'sales_channel.editor' => [
  75.                 self::SWAG_SOCIAL_SHOPPING_SALES_CHANNEL_PRIVILEGE_KEY 'update',
  76.             ],
  77.             'sales_channel.creator' => [
  78.                 self::SWAG_SOCIAL_SHOPPING_SALES_CHANNEL_PRIVILEGE_KEY 'create',
  79.             ],
  80.         ];
  81.     }
  82. }