Skip to content

Fix for 'Integrity constraint violation: 1062 Duplicate entry '11-general' for key' #929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions src/Migration/Step/Eav/Model/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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)) {
Expand Down