Fix to make vendor attribute user-defined, add to Default attribute set
This commit is contained in:
@@ -9,6 +9,7 @@ use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
|
||||
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
|
||||
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
|
||||
|
||||
class InstallData implements InstallDataInterface
|
||||
{
|
||||
@@ -46,6 +47,7 @@ class InstallData implements InstallDataInterface
|
||||
'group' => 'General',
|
||||
'used_in_product_listing' => true,
|
||||
'visible_on_front' => false,
|
||||
'is_user_defined' => true,
|
||||
'option' => [
|
||||
'values' => [
|
||||
'Thermo Fisher',
|
||||
@@ -65,8 +67,29 @@ class InstallData implements InstallDataInterface
|
||||
$attributeSetCollection->addFieldToFilter('entity_type_id', $entityTypeId);
|
||||
|
||||
foreach ($attributeSetCollection as $attributeSet) {
|
||||
$groupId = $eavSetup->getAttributeGroupId($entityTypeId, $attributeSet->getId(), 'General');
|
||||
$eavSetup->addAttributeToGroup($entityTypeId, $attributeSet->getId(), $groupId, $attributeId, null);
|
||||
// Get the General group ID, or fallback to the first available group
|
||||
try {
|
||||
$groupId = $eavSetup->getAttributeGroupId(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId(),
|
||||
'General'
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// If General group doesn't exist, get the default group
|
||||
$groupId = $eavSetup->getDefaultAttributeGroupId(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId()
|
||||
);
|
||||
}
|
||||
|
||||
// Add attribute to the set
|
||||
$eavSetup->addAttributeToGroup(
|
||||
$entityTypeId,
|
||||
$attributeSet->getId(),
|
||||
$groupId,
|
||||
$attributeId,
|
||||
null // Sort order
|
||||
);
|
||||
}
|
||||
|
||||
$setup->endSetup();
|
||||
|
||||
Reference in New Issue
Block a user