in the attribute Attribute “Manufacturer” we’ve several entries of the brand “LG”, seems it was duplicated over and over during migration or import.
I have to drop all instances of “LG” from the attribute, if products are associated with “LG” they can be deleted.
I tried several ways to create data patch but could not reach success .
my code looks something like that
< ?php
declare(strict_types=1);
namespace DevAllExtensionSettingConfigSetupPatchData;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoEavSetupEavSetup;
use MagentoEavApiAttributeRepositoryInterface;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCatalogModelResourceModelEavAttributeFactory;
class RemoveLGManufacturer implements DataPatchInterface
{
private $eavSetupFactory;
private $eavAttributeRepository;
private $_productVisibility;
private $collectionFactory;
public function __construct(
EavSetup $eavSetupFactory,
AttributeRepositoryInterface $eavAttributeRepositoryInterface,
MagentoCatalogModelProductVisibility $productVisibility,
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory,
MagentoFrameworkViewElementTemplateContext $context,
array $data = []
) {
$this->eavSetupFactory = $eavSetupFactory;
$this->eavAttributeRepository = $eavAttributeRepositoryInterface;
$this->collectionFactory = $collectionFactory;
$this->_productVisibility = $productVisibility;
}
/**
* @inheritDoc
*/
public static function getDependencies()
{
return [];
}
/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
/**
* @return DataPatchInterface|void
* @throws MagentoFrameworkExceptionNoSuchEntityException
*/
public function apply()
{
$collection =$this->collectionFactory->create();
$collection->addAttributeToSelect('manufacturer');
$collection->addFieldToFilter(array(
array('attribute' => 'manufacturer', 'eq' => 'LG'),
));
$collection->setDataToAll('');
}
}
How can I solve the problem ? thanks.