0

I have created data patch, After I run setup:upgrade it does the job but never finishes setup upgrade command . https://i.imgur.com/Mhilmgd.png https://i.imgur.com/GtUDbLV.png
the Data patch itself looks like that

<?php

declare(strict_types=1);

namespace DevAll\ExtensionSettingConfig\Setup\Patch\Data;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Catalog\Model\ProductRepositoryIn;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
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) {
            }
        }

    }

}

I tried using return after ending of foreach but nothing happened .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.