JsonEntityEncoder example

->first();
        static::assertInstanceOf(MailTemplateEntity::class$mailTemplate);

        $criteria = new Criteria([TestDefaults::SALES_CHANNEL]);
        $criteria->setLimit(1);
        $salesChannel = $this->getContainer()
            ->get('sales_channel.repository')
            ->search($criteria$context)
            ->first();
        static::assertInstanceOf(SalesChannelEntity::class$salesChannel);

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );
        $orderDefinition = $this->getContainer()->get(OrderDefinition::class);
        $orderDecode = $entityEncoder->encode(new Criteria()$orderDefinition$order, '/api');
        array_walk_recursive($orderDecodestatic function D&$value): void {
            if ($value instanceof \stdClass) {
                $value = json_decode((string) json_encode($value), true, 512, \JSON_THROW_ON_ERROR);
            }
        });

        $salesChannelDefinition = $this->getContainer()->get(SalesChannelDefinition::class);
        
$cart = new Cart($this->ids->get('cart'));
        $source = new Source('https://shopware.com', $this->ids->get('shop-id'), '1.0.0');
        $payload = new TaxProviderPayload($cart$salesChannelContext);
        $payload->setSource($source);

        $definitionInstanceRegistry = static::createMock(DefinitionInstanceRegistry::class);
        $definitionInstanceRegistry
            ->method('getByEntityClass')
            ->willReturn(new TaxProviderDefinition());

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );

        $appPayloadServiceHelper = new AppPayloadServiceHelper(
            $definitionInstanceRegistry,
            $entityEncoder,
            static::createMock(ShopIdProvider::class)
        );

        $array = $appPayloadServiceHelper->encode($payload);

        

        $definitionInstanceRegistry = static::createMock(DefinitionInstanceRegistry::class);
        $definitionInstanceRegistry
            ->method('getByEntityClass')
            ->willReturn(new TaxProviderDefinition());

        $shopIdProvider = static::createMock(ShopIdProvider::class);
        $shopIdProvider
            ->method('getShopId')
            ->willReturn($this->ids->get('shop-id'));

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );

        $appPayloadServiceHelper = new AppPayloadServiceHelper(
            $definitionInstanceRegistry,
            $entityEncoder,
            $shopIdProvider
        );

        $url = 'https://example.com/provide-tax';
        $context = new Context(new SystemSource());
        
Home | Imprint | This part of the site doesn't use cookies.