fix(custom-fields) : populate customFields in ModelType structure from relations
getStructure() was returning hardcoded empty customFields arrays after the JSON-to-tables migration. Now reads from the relational CustomField entities via serializeCustomFields() for all three categories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -221,7 +221,7 @@ class ModelType
|
|||||||
return match ($this->category) {
|
return match ($this->category) {
|
||||||
ModelCategory::COMPONENT => $this->getComponentStructureFromRelations(),
|
ModelCategory::COMPONENT => $this->getComponentStructureFromRelations(),
|
||||||
ModelCategory::PIECE => $this->getPieceStructureFromRelations(),
|
ModelCategory::PIECE => $this->getPieceStructureFromRelations(),
|
||||||
ModelCategory::PRODUCT => ['customFields' => []],
|
ModelCategory::PRODUCT => ['customFields' => $this->serializeCustomFields($this->productCustomFields)],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ class ModelType
|
|||||||
|
|
||||||
private function getComponentStructureFromRelations(): array
|
private function getComponentStructureFromRelations(): array
|
||||||
{
|
{
|
||||||
$structure = ['customFields' => [], 'pieces' => [], 'products' => [], 'subcomponents' => []];
|
$structure = ['customFields' => $this->serializeCustomFields($this->customFields), 'pieces' => [], 'products' => [], 'subcomponents' => []];
|
||||||
|
|
||||||
foreach ($this->skeletonPieceRequirements as $req) {
|
foreach ($this->skeletonPieceRequirements as $req) {
|
||||||
$structure['pieces'][] = [
|
$structure['pieces'][] = [
|
||||||
@@ -373,11 +373,34 @@ class ModelType
|
|||||||
private function getPieceStructureFromRelations(): array
|
private function getPieceStructureFromRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'customFields' => [],
|
'customFields' => $this->serializeCustomFields($this->pieceCustomFields),
|
||||||
'products' => array_map(fn (SkeletonProductRequirement $req) => [
|
'products' => array_map(fn (SkeletonProductRequirement $req) => [
|
||||||
'typeProductId' => $req->getTypeProduct()->getId(),
|
'typeProductId' => $req->getTypeProduct()->getId(),
|
||||||
'familyCode' => $req->getFamilyCode(),
|
'familyCode' => $req->getFamilyCode(),
|
||||||
], $this->skeletonProductRequirements->toArray()),
|
], $this->skeletonProductRequirements->toArray()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<int, CustomField> $fields
|
||||||
|
*/
|
||||||
|
private function serializeCustomFields(Collection $fields): array
|
||||||
|
{
|
||||||
|
$items = [];
|
||||||
|
foreach ($fields as $cf) {
|
||||||
|
$items[] = [
|
||||||
|
'id' => $cf->getId(),
|
||||||
|
'name' => $cf->getName(),
|
||||||
|
'type' => $cf->getType(),
|
||||||
|
'required' => $cf->isRequired(),
|
||||||
|
'options' => $cf->getOptions(),
|
||||||
|
'defaultValue' => $cf->getDefaultValue(),
|
||||||
|
'orderIndex' => $cf->getOrderIndex(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($items, static fn (array $a, array $b) => $a['orderIndex'] <=> $b['orderIndex']);
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user