custom/plugins/RecentlyViewedProduct-master/src/RecentlyViewedProduct.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace RecentlyViewedProduct;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\Plugin;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. class RecentlyViewedProduct extends Plugin
  11. {
  12.     public const PLUGIN_NAME 'RecentlyViewedProduct';
  13.     public const DEFAULT_MAXIMUM_VIEWED_PRODUCTS 10;
  14.     public const RECENTLY_VIEWED_PRODUCT_TYPE 'recently-viewed-product-slider';
  15.     public function uninstall(UninstallContext $uninstallContext): void
  16.     {
  17.         if ($uninstallContext->keepUserData()) {
  18.             parent::uninstall($uninstallContext);
  19.             return;
  20.         }
  21.         /** @var EntityRepositoryInterface $cmsBlockRepo */
  22.         $cmsBlockRepo $this->container->get('cms_block.repository');
  23.         $context Context::createDefaultContext();
  24.         $criteria = new Criteria();
  25.         $criteria->addFilter(new EqualsFilter('type'self::RECENTLY_VIEWED_PRODUCT_TYPE));
  26.         $cmsBlocks $cmsBlockRepo->searchIds($criteria$context);
  27.         $cmsBlockRepo->delete(array_values($cmsBlocks->getData()), $context);
  28.         $connection $this->container->get(Connection::class);
  29.         $connection->exec('DROP TABLE IF EXISTS recently_viewed_product;');
  30.     }
  31. }