From f89da6d6b7d177a644a1b2d5e190109797c35b5d Mon Sep 17 00:00:00 2001 From: Oliver Rivett-Carnac Date: Fri, 4 Jul 2025 14:07:08 +0200 Subject: [PATCH] Fix for 'Integrity constraint violation: 1062 Duplicate entry '11-general' for key' --- src/Migration/Step/Eav/Model/Data.php | 57 ++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/src/Migration/Step/Eav/Model/Data.php b/src/Migration/Step/Eav/Model/Data.php index d0441fc9..082b5a10 100644 --- a/src/Migration/Step/Eav/Model/Data.php +++ b/src/Migration/Step/Eav/Model/Data.php @@ -131,6 +131,25 @@ public function getProductAttributeSets( return $attributeSets; } + public function getEntityAttributeSets( + $mode = self::ATTRIBUTE_SETS_ALL, + $type = self::TYPE_SOURCE, + $entityTypeCode = self::ENTITY_TYPE_PRODUCT_CODE + ) { + $productEntityTypeId = $this->getEntityTypeIdByCode($entityTypeCode, $type); + $attributeSets = []; + foreach ($this->initialData->getAttributeSets($type) as $attributeSet) { + if ($productEntityTypeId == $attributeSet['entity_type_id'] + && (($mode == self::ATTRIBUTE_SETS_DEFAULT && $attributeSet['attribute_set_name'] == 'Default') + || ($mode == self::ATTRIBUTE_SETS_NONE_DEFAULT && $attributeSet['attribute_set_name'] != 'Default') + || ($mode == self::ATTRIBUTE_SETS_ALL)) + ) { + $attributeSets[$attributeSet['attribute_set_id']] = $attributeSet; + } + } + return $attributeSets; + } + /** * Return entity type id by its code * @@ -208,6 +227,30 @@ public function getDefaultProductAttributeGroups() return $attributeGroups; } + public function getDefaultEntityAttributeGroups($entityTypeCode = self::ENTITY_TYPE_PRODUCT_CODE) + { + $defaultProductAttributeSet = $this->getEntityAttributeSets( + self::ATTRIBUTE_SETS_DEFAULT, + self::TYPE_DEST, + $entityTypeCode + ); + + if (!$defaultProductAttributeSet) { + return []; + } + + $defaultProductAttributeSetId = array_shift($defaultProductAttributeSet)['attribute_set_id']; + $attributeGroups = []; + foreach ($this->initialData->getAttributeGroups(self::TYPE_DEST) as $attributeGroup) { + if ($attributeGroup['attribute_set_id'] == $defaultProductAttributeSetId) { + $attributeGroup['attribute_group_id'] = null; + $attributeGroup['attribute_set_id'] = null; + $attributeGroups[] = $attributeGroup; + } + } + return $attributeGroups; + } + /** * Get default product entity attributes * @@ -298,17 +341,11 @@ public function getCustomAttributeGroups($attributeSetId) $sourceAttributeGroupNames = []; $entityTypeCode = $this->getEntityTypeCodeByAttributeSetId($attributeSetId); $excludedAttributeGroups = $this->excludedAttributeGroups[$entityTypeCode] ?? []; - if ($entityTypeCode == self::ENTITY_TYPE_PRODUCT_CODE) { - foreach ($this->getDefaultProductAttributeGroups() as $attributeGroup) { - $defaultAttributeGroupNames[] = $attributeGroup['attribute_group_name']; - } - } else { - foreach ($this->initialData->getAttributeGroups(self::TYPE_DEST) as $attributeGroup) { - if ($attributeGroup['attribute_set_id'] == $attributeSetId) { - $defaultAttributeGroupNames[] = $attributeGroup['attribute_group_name']; - } - } + + foreach ($this->getDefaultEntityAttributeGroups($entityTypeCode) as $attributeGroup) { + $defaultAttributeGroupNames[] = $attributeGroup['attribute_group_name']; } + foreach ($this->initialData->getAttributeGroups(self::TYPE_SOURCE) as $attributeGroup) { if ($attributeGroup['attribute_set_id'] == $attributeSetId) { if (in_array($attributeGroup['attribute_group_name'], $excludedAttributeGroups)) {