I have a custom product attribute which is under Advanced Pricing
group . I am trying to change attribute group of this attribute via data patch using below code :
<?php
namespace Vendor\Module\Setup\Patch\Data;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class UpdateCustomAttributeGroup implements DataPatchInterface
{
/**
* @var EavSetupFactory
*/
private $eavSetup;
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
public function __construct(
EavSetupFactory $eavSetupFactory,
ModuleDataSetupInterface $moduleDataSetup
)
{
$this->eavSetup = $eavSetupFactory;
$this->moduleDataSetup = $moduleDataSetup;
}
/**
* @inheritDoc
*/
public static function getDependencies()
{
return [];
}
/**
* @inheritDoc
*/
public function getAliases()
{
return [];
}
/**
* @inheritDoc
*/
public function apply()
{
$eavSetup = $this->eavSetup->create(['setup' => $this->moduleDataSetup]);
$eavSetup->updateAttribute(
'catalog_product',
'custom_attribute_code',
'group',
'General'
);
}
}
Above code isn't impacting already assigned group of this attribute. How to update group of any product attribute programatically? Please note, this attribute might be assigned to multiple attribute set.