Skip to content

Commit

Permalink
Fixed ClassificationStoreAdapter.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mcop1 committed Jan 17, 2025
1 parent 5b13d69 commit 6b29235
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/DataObject/Data/Adapter/ClassificationStoreAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use function in_array;
use function is_array;

/**
* @internal
Expand Down Expand Up @@ -82,8 +81,16 @@ public function getDataForSetter(
}

$store = $data[$key];
$activeGroups = $store['activeGroups'] ?? [];
if(empty($activeGroups)) {
return null;
}
$groupCollectionMapping = $store['groupCollectionMapping'] ?? [];
$container = $this->getContainer($element, $key, $contextData);
$this->setMapping($container, $store);
if(!empty($groupCollectionMapping)) {
$this->setMapping($container, $store['activeGroups'], $store['groupCollectionMapping']);
}
unset($store['activeGroups'], $store['groupCollectionMapping']);
$this->setStoreValues($element, $fieldDefinition, $container, $store);
$this->cleanupStoreGroups($container);

Expand All @@ -103,6 +110,9 @@ public function normalize(
$validLanguages = $this->getValidLanguages($fieldDefinition);
$resultItems = [];

$resultItems['activeGroups'] = $value->getActiveGroups();
$resultItems['groupCollectionMapping'] = $value->getGroupCollectionMappings();

foreach ($this->getActiveGroups($value) as $groupId => $groupConfig) {
$resultItems[$groupId] = [];
$keys = $this->getClassificationStoreKeysFromGroup($groupId);
Expand Down Expand Up @@ -172,20 +182,17 @@ private function getContainer(
return $container;
}

private function setMapping(Classificationstore $container, array $data): void
private function setMapping(
Classificationstore $container,
array $activeGroups,
array $groupCollectionMapping
): void
{
$activeGroups = array_keys($data);
$mapping = [];

foreach($activeGroups as $activeGroup) {
/* TODO Get group collection id, not to confuse with group id or key definition id.
The mapping should contain the groupId as key and the group collection id as value.
*/

$mapping[$activeGroup] = 1; // 1 = group collection id (e.g. Size)
}
$correctedMapping = array_filter($groupCollectionMapping, static function ($groupId) use ($activeGroups) {
return isset($activeGroups[$groupId]) && $activeGroups[$groupId];
}, ARRAY_FILTER_USE_KEY);

$container->setGroupCollectionMappings($mapping);
$container->setGroupCollectionMappings($correctedMapping);
}

/**
Expand Down

0 comments on commit 6b29235

Please sign in to comment.