/** * {@inheritdoc} */ public function normalize($product, $format = null, array $context = []) { $normalizedProduct = $this->productNormalizer->normalize($product, 'json', $context); $oldestLog = $this->versionManager->getOldestLogEntry($product); $newestLog = $this->versionManager->getNewestLogEntry($product); $created = null !== $oldestLog ? $this->versionNormalizer->normalize($oldestLog, 'internal_api') : null; $updated = null !== $newestLog ? $this->versionNormalizer->normalize($newestLog, 'internal_api') : null; $normalizedProduct['meta'] = ['form' => $this->formProvider->getForm($product), 'id' => $product->getId(), 'created' => $created, 'updated' => $updated, 'model_type' => 'product', 'structure_version' => $this->structureVersionProvider->getStructureVersion()] + $this->getLabels($product) + $this->getAssociationMeta($product); return $normalizedProduct; }
/** * {@inheritdoc} */ public function normalize($group, $format = null, array $context = []) { $normalizedGroup = $this->groupNormalizer->normalize($group, 'json', $context); if (isset($normalizedGroup['values'])) { $normalizedGroup['values'] = $this->localizedConverter->convertToLocalizedFormats($normalizedGroup['values'], $context); } $normalizedGroup['products'] = []; foreach ($group->getProducts() as $product) { $normalizedGroup['products'][] = $product->getId(); } $firstVersion = $this->versionManager->getOldestLogEntry($group); $lastVersion = $this->versionManager->getNewestLogEntry($group); $firstVersion = null !== $firstVersion ? $this->versionNormalizer->normalize($firstVersion, 'internal_api') : null; $lastVersion = null !== $lastVersion ? $this->versionNormalizer->normalize($lastVersion, 'internal_api') : null; $normalizedGroup['meta'] = ['id' => $group->getId(), 'form' => 'pim-variant-group-edit-form', 'structure_version' => $this->structureVersionProvider->getStructureVersion(), 'model_type' => 'variant_group', 'created' => $firstVersion, 'updated' => $lastVersion]; return $normalizedGroup; }