<?php declare(strict_types=1);
namespace fourtwosix\PopupsGenerator;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Context;
class fourtwosixPopupsGenerator extends Plugin
{
public function deactivate(DeactivateContext $context): void
{
$this->deleteCmsElements($context->getContext());
}
private function deleteCmsElements(Context $context) {
//delete all elements of popups
$cmsElementsRepo = $this->container->get('cms_slot.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('type', "fourtwosix-popup"));
$results = $cmsElementsRepo->search($criteria, $context);
if($results != null){
$elements = $results->getEntities();
foreach($elements as $element){
$cmsElementsRepo->delete([['id' => $element->getId()]], $context);
}
}
//delete all blocks of popups
$cmsBlockRepo = $this->container->get('cms_block.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('type', "fourtwosix-popup-block"));
$results = $cmsBlockRepo->search($criteria, $context);
if($results != null){
$blocks = $results->getEntities();
foreach($blocks as $block){
$cmsBlockRepo->delete([['id' => $block->getId()]], $context);
}
}
}
}