crated data patch but it stucks on setup:upgrade
Running data recurring...
my code is
< ?php
declare(strict_types=1);
namespace DevAllExtensionSettingConfigSetupPatchData;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoFrameworkExceptionStateException;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoEavSetupEavSetup;
use MagentoEavApiAttributeRepositoryInterface;
use MagentoCatalogModelProductRepositoryIn;
use MagentoFrameworkApiSearchCriteriaBuilder;
use MagentoCatalogModelResourceModelProductCollectionFactory;
use MagentoCatalogApiProductRepositoryInterface;
use MagentoFrameworkAppArea;
use MagentoFrameworkAppState;
class RemoveLGManufacturer implements DataPatchInterface
{
private $eavSetupFactory;
private $attributeRepository;
private $_productRepositoryInterface;
private $collectionFactory;
private $state;
private $productCollectionFactory;
private $productRepository;
private $searchCriteriaBuilder;
public function __construct(
State $state,
CollectionFactory $collectionFactory,
SearchCriteriaBuilder $searchCriteriaBuilder,
AttributeRepositoryInterface $attributeRepository,
ProductRepositoryInterface $productRepositoryInterface,
array $data = []
) {
$state->setAreaCode('frontend') ;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->_productRepositoryInterface = $productRepositoryInterface;
$this->attributeRepository = $attributeRepository;
$this->collectionFactory = $collectionFactory;
}
/**
* @inheritDoc
*/
public static function getDependencies()
{
return [];
}
/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
public function apply()
{
//$searchCriteria = $this->searchCriteriaBuilder->addFilter('manufacturer','LG')->create();
$productcollection = $this->collectionFactory->create()->addAttributeToSelect('manufacturer','LG')->load();
foreach ($productcollection as $product) {
try {
$this->_productRepositoryInterface->delete($product);
} catch (StateException $e) {
}
}
}
}
what can be the cause of problem ? how to fix it ?