encodeEntity example

$array = $payload->jsonSerialize();

        foreach ($array as $propertyName => $property) {
            if ($property instanceof SalesChannelContext) {
                $salesChannelContext = $property->jsonSerialize();

                foreach ($salesChannelContext as $subPropertyName => $subProperty) {
                    if (!$subProperty instanceof Entity) {
                        continue;
                    }

                    $salesChannelContext[$subPropertyName] = $this->encodeEntity($subProperty);
                }

                $array[$propertyName] = $salesChannelContext;
            }

            if (!$property instanceof Entity) {
                continue;
            }

            $array[$propertyName] = $this->encodeEntity($property);
        }

        
$array = $payload->jsonSerialize();

        foreach ($array as $propertyName => $property) {
            if ($property instanceof SalesChannelContext) {
                $salesChannelContext = $property->jsonSerialize();

                foreach ($salesChannelContext as $subPropertyName => $subProperty) {
                    if (!$subProperty instanceof Entity) {
                        continue;
                    }

                    $salesChannelContext[$subPropertyName] = $this->encodeEntity($subProperty);
                }

                $array[$propertyName] = $salesChannelContext;
            }

            if (!$property instanceof Entity) {
                continue;
            }

            $array[$propertyName] = $this->encodeEntity($property);
        }

        

    private function encodeProperty(array $dataType, mixed $property)
    {
        switch ($dataType['type']) {
            case ScalarValueType::TYPE_BOOL:
            case ScalarValueType::TYPE_FLOAT:
            case ScalarValueType::TYPE_INT:
            case ScalarValueType::TYPE_STRING:
                return $property;
            case EntityType::TYPE:
            case EntityCollectionType::TYPE:
                return $this->encodeEntity($dataType$property);
            case ObjectType::TYPE:
                if (\is_array($dataType['data']) && !empty($dataType['data'])) {
                    return $this->encodeType($dataType['data']$property);
                }

                return $property;
            case ArrayType::TYPE:
                return $this->encodeArray($dataType$property);
            default:
                throw new \RuntimeException('Unknown EventDataType: ' . $dataType['type']);
        }
    }
Home | Imprint | This part of the site doesn't use cookies.