/** * Remove attribute sets and attribute groups if not exist * * @param array $data * * @return void */ protected function _pruneAttributeSets(array $data) { $entityTypeId = $this->_catalogProductEntityTypeId; $magAttributeSetsName = $this->_getAttributeSetsNameAsArray(); $attributeSetsName = array(); foreach ($data as $attributeSet) { $attributeSetsName[] = $attributeSet['attribute_set_name']; } $attributeSetsToRemove = array_diff($magAttributeSetsName, $attributeSetsName); foreach ($attributeSetsToRemove as $attributeSet) { $this->_setup->removeAttributeSet($entityTypeId, $attributeSet); } foreach ($data as $attributeSet) { $attrSetName = $attributeSet['attribute_set_name']; $attributeGroups = $attributeSet; unset($attributeGroups['attribute_set_name']); unset($attributeGroups['sort_order']); $attrSetId = $this->_setup->getAttributeSet($entityTypeId, $attrSetName, 'attribute_set_id'); $currentGroups = $this->_getAttributeGroups($attrSetId); $groupsToRemove = array_keys(array_diff_key($currentGroups, $attributeGroups)); foreach ($groupsToRemove as $groupToRemoveName) { $this->_setup->removeAttributeGroup($entityTypeId, $attrSetId, $groupToRemoveName); } } }