From 179979342e46056d95c74b804be8294b5b176b43 Mon Sep 17 00:00:00 2001 From: shopkeeperdev Date: Wed, 8 Oct 2025 18:18:37 -0400 Subject: [PATCH] Fix to make vendor attribute user-defined, add to Default attribute set --- Setup/InstallData.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Setup/InstallData.php b/Setup/InstallData.php index 0da752f..92a302b 100644 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -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,10 +67,31 @@ 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(); } -} +} \ No newline at end of file