custom/plugins/SwkwebHideSoldoutProducts/src/SwkwebHideSoldoutProducts.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swkweb\HideSoldoutProducts;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. final class SwkwebHideSoldoutProducts extends Plugin
  9. {
  10.     public function install(InstallContext $installContext): void
  11.     {
  12.         $this->runIndexer();
  13.     }
  14.     public function uninstall(UninstallContext $uninstallContext): void
  15.     {
  16.         if ($uninstallContext->keepUserData()) {
  17.             return;
  18.         }
  19.         $this->dropSchema();
  20.     }
  21.     private function dropSchema(): void
  22.     {
  23.         /** @var Connection $connection */
  24.         $connection $this->container->get(Connection::class);
  25.         $connection->exec('DROP TABLE IF EXISTS swkweb_hide_soldout_products_product_availability');
  26.     }
  27.     private function runIndexer(): void
  28.     {
  29.         /** @var EntityIndexerRegistry $indexer */
  30.         $indexer $this->container->get(EntityIndexerRegistry::class);
  31.         $indexer->sendIndexingMessage(['product.indexer']);
  32.     }
  33. }