SystemSource example

$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());
        $responseContent = \json_encode([
            'lineItemTaxes' => [
                $this->ids->get('line-item-1') => [
                    [
                        'tax' => 19,
                        'taxRate' => 19,
                        'price' => 100,
                    ],
                ],
            ],
            'deliveryTaxes' => [
                
$productRepository->create($products, Context::createDefaultContext());

        $notGreenFilter = new NotFilter('AND', [new EqualsFilter('product.name', 'green')]);

        $enGbContext = Context::createDefaultContext();
        $criteria = (new Criteria($ids))->addFilter($notGreenFilter);

        /** @var string[] $ids */
        $ids = $productRepository->searchIds($criteria$enGbContext)->getIds();
        static::assertEmpty($ids);

        $rawDeContext = new Context(new SystemSource()[], Defaults::CURRENCY, [$this->getDeDeLanguageId(), Defaults::LANGUAGE_SYSTEM]);
        $criteria = (new Criteria())->addFilter($notGreenFilter);

        /** @var string[] $ids */
        $ids = $productRepository->searchIds($criteria$rawDeContext)->getIds();
        static::assertContains($greenGruenId$ids);
        static::assertCount(1, $ids);

        $deContext = new Context(new SystemSource()[], Defaults::CURRENCY, [$this->getDeDeLanguageId(), Defaults::LANGUAGE_SYSTEM], Defaults::LIVE_VERSION, 1.0, true);
        $criteria = (new Criteria($ids))->addFilter($notGreenFilter);

        /** @var string[] $ids */
        
protected function setUp(): void
    {
        $this->appRepository = $this->getContainer()->get('app.repository');

        $userRepository = $this->getContainer()->get('user.repository');
        $userId = $userRepository->searchIds(new Criteria(), Context::createDefaultContext())->firstId();
        $source = new AdminApiSource($userId);
        $source->setIsAdmin(true);

        $this->appLifecycle = $this->getContainer()->get(AppLifecycle::class);
        $this->context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
    }

    /** * @dataProvider themeProvideData */
    public function testThemeRemovalOnDelete(bool $keepUserData): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../fixtures/Apps/theme/manifest.xml');
        $this->appLifecycle->install($manifest, true, $this->context);

        $apps = $this->appRepository->search(new Criteria()$this->context)->getEntities();
        
private EntityRepository $salesChannelRepository;

    private Context $context;

    protected function setUp(): void
    {
        $this->lifecycleService = $this->getContainer()->get(ExtensionLifecycleService::class);

        $this->appRepository = $this->getContainer()->get('app.repository');
        $this->themeRepository = $this->getContainer()->get('theme.repository', ContainerInterface::NULL_ON_INVALID_REFERENCE);
        $this->salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
        $this->context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
    }

    protected function tearDown(): void
    {
        $this->removeApp(__DIR__ . '/../_fixtures/TestApp');
        $this->removeApp(__DIR__ . '/../_fixtures/TestAppTheme');
        $this->removePlugin(__DIR__ . '/../_fixtures/AppStoreTestPlugin');
    }

    public function testInstallExtension(): void
    {
        


            $this->logger->error($item['error']['reason'] ?? $item['result']);
        }

        return $errors;
    }

    private function createLanguageContext(LanguageEntity $language): Context
    {
        return new Context(
            new SystemSource(),
            [],
            Defaults::CURRENCY,
            array_filter([$language->getId()$language->getParentId(), Defaults::LANGUAGE_SYSTEM])
        );
    }

    private function getLanguageForId(string $languageId): ?LanguageEntity
    {
        $context = Context::createDefaultContext();
        $criteria = new Criteria([$languageId]);

        
'class' => addcslashes($namespacePrefix, '\\_%') . '%']
        )
            ->fetchOne();

        return (int) $result;
    }

    private function createNonStandardLanguageContext(): Context
    {
        $id = $this->addLanguage($this->iso);

        return new Context(new SystemSource()[], Defaults::CURRENCY, [$id]);
    }

    private function createPluginLifecycleService(PluginService $pluginService): PluginLifecycleService
    {
        return new PluginLifecycleService(
            $this->pluginRepo,
            $this->container->get('event_dispatcher'),
            $this->pluginCollection,
            $this->container->get('service_container'),
            $this->container->get(MigrationCollectionLoader::class),
            $this->container->get(AssetService::class),
            
$violations = $exception->getViolations();
        static::assertCount(1, $violations);
        static::assertInstanceOf(ConstraintViolation::class$violations->get(0));
        static::assertStringContainsString('This field is write-protected. (Got: "user" scope and "system" is required)', (string) $violations->get(0)->getMessage());
    }

    public static function writeProtectedFieldsProvider(): \Generator
    {
        yield 'Test write webhook with system source and valid error count' => [
            ['errorCount' => 10],
            new SystemSource(),
            true,
        ];

        yield 'Test write webhook with user source and valid error count' => [
            ['errorCount' => 10],
            new AdminApiSource(Uuid::randomHex()),
            false,
        ];

        yield 'Test write without error count and user source' => [
            [],
            

        ];
        $categoryRepository->create([$category]$this->context);

        /** @var CategoryEntity $catSystem */
        $catSystem = $categoryRepository->search(new Criteria([$category['id']])$this->context)->first();

        static::assertNotNull($catSystem);
        static::assertEquals('system', $catSystem->getName());
        static::assertEquals('system', $catSystem->getTranslated()['name']);

        $deDeContext = new Context(new SystemSource()[], Defaults::CURRENCY, [$this->deLanguageId, Defaults::LANGUAGE_SYSTEM]);
        /** @var CategoryEntity $catDeDe */
        $catDeDe = $categoryRepository->search(new Criteria([$category['id']])$deDeContext)->first();

        static::assertNotNull($catDeDe);
        static::assertNull($catDeDe->getName());
        static::assertEquals('system', $catDeDe->getTranslated()['name']);
    }

    public function testUpsert(): void
    {
        $data = [
            
static::assertSame('US$132,582.99', $formattedCurrency);
    }

    /** * @dataProvider digitProvider */
    public function testDigits(float $price, int $digits, string $expected): void
    {
        $formatter = $this->getContainer()->get(CurrencyFormatter::class);

        $context = new Context(
            new SystemSource(),
            [],
            Defaults::CURRENCY,
            [Defaults::LANGUAGE_SYSTEM],
            Defaults::LIVE_VERSION,
            1,
            true,
            CartPrice::TAX_STATE_GROSS,
            new CashRoundingConfig($digits, 0.01, true)
        );

        $languageId = $this->getDeDeLanguageId();

        
$criteria->addSorting(new FieldSorting(sprintf('price.%s%s.gross', $ids->get($isoCode)$priceType), 'DESC'));

            $result = $this->repository->searchIds($criteria, Context::createDefaultContext());

            static::assertEquals(
                array_values($ids->getList(['c', 'e', 'b', 'd', 'a'])),
                $result->getIds()
            );
        }

        // test context with currency id         $context = new Context(new SystemSource()[]$ids->get($isoCode)[Defaults::LANGUAGE_SYSTEM], Defaults::LIVE_VERSION, $currencyFactor);

        $criteria = new Criteria($ids->all());
        $criteria->addSorting(new FieldSorting('price'));

        $result = $this->repository->searchIds($criteria$context);

        static::assertEquals(
            array_values($ids->getList(['a', 'd', 'b', 'e', 'c'])),
            $result->getIds()
        );
    }

    
static::assertEquals(new NotBlank()$languageIds[0]);
        static::assertEquals(new ArrayOfUuid()$languageIds[1]);
    }

    /** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, string $languageId): void
    {
        $languageIds = ['kyln123', 'kyln456'];
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [$languageId]);

        $salesChannelContext->method('getContext')->willReturn($context);
        $scope = new CheckoutRuleScope($salesChannelContext);
        $this->rule->assign(['languageIds' => $languageIds, 'operator' => $operator]);

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }
if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            static::assertSame((string) $dalProduct->getTranslation('name')$esProduct['name'][Defaults::LANGUAGE_SYSTEM]);
            static::assertSame((string) $dalProduct->getTranslation('description')$esProduct['description'][Defaults::LANGUAGE_SYSTEM]);
            static::assertSame($dalProduct->getTranslation('customFields')$esProduct['customFields'][Defaults::LANGUAGE_SYSTEM]);
        } else {
            static::assertSame((string) $dalProduct->getTranslation('name')$esProduct['name']);
            static::assertSame((string) $dalProduct->getTranslation('description')$esProduct['description']);
            static::assertSame($dalProduct->getTranslation('customFields')$esProduct['customFields']);
        }

        // Fetch: Second language         $languageContext = new Context(new SystemSource()[], Defaults::CURRENCY, [$ids->get('language-1'), Defaults::LANGUAGE_SYSTEM]);
        $languageContext->addExtensions($context->getExtensions());
        $esProducts = $this->definition->fetch([$dal1]$languageContext);

        $esProduct = $esProducts[$ids->get('dal-1')];

        $criteria = new Criteria([$ids->get('dal-1')]);
        $dalProduct = $this->productRepository->search($criteria$languageContext)->first();

        static::assertInstanceOf(ProductEntity::class$dalProduct);
        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            static::assertSame((string) $dalProduct->getTranslation('name')$esProduct['name'][$ids->get('language-1')]);
            
return $this->restore($event->getName()$event->getContext()$stored);
    }

    /** * @param array<string, mixed> $stored * @param array<string, mixed> $data */
    public function restore(string $name, Context $context, array $stored = [], array $data = []): StorableFlow
    {
        $systemContext = new Context(
            new SystemSource(),
            $context->getRuleIds(),
            $context->getCurrencyId(),
            $context->getLanguageIdChain(),
            $context->getVersionId(),
            $context->getCurrencyFactor(),
            $context->considerInheritance(),
            $context->getTaxState(),
            $context->getRounding(),
        );
        $systemContext->setExtensions($context->getExtensions());

        
$source = $appPayloadServiceHelper->buildSource($app, 'https://shopware.com');

        static::assertInstanceOf(Source::class$source);

        static::assertSame('https://shopware.com', $source->getUrl());
        static::assertSame($this->ids->get('shop-id')$source->getShopId());
        static::assertSame('1.0.0', $source->getAppVersion());
    }

    public function testEncode(): void
    {
        $context = new Context(new SystemSource());
        $salesChannelContext = static::createMock(SalesChannelContext::class);
        $salesChannelContext
            ->method('getContext')
            ->willReturn($context);

        $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);
        
protected function setUp(): void
    {
        $this->router = $this->createMock(RouterInterface::class);
        $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
        $this->salesChannelContextService = $this->createMock(SalesChannelContextService::class);
    }

    public function testGenerateUserRecoveryUserNotFound(): void
    {
        $userEmail = 'nonexistent@example.com';
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
        $recoveryEntity = new UserRecoveryEntity();
        $recoveryEntity->setUniqueIdentifier(Uuid::randomHex());

        /** @var StaticEntityRepository<UserCollection> $userRepository */
        $userRepository = new StaticEntityRepository([
            new UserCollection([]),
        ]new UserDefinition());

        /** @var StaticEntityRepository<UserRecoveryCollection> $recoveryRepository */
        $recoveryRepository = new StaticEntityRepository([
            new UserRecoveryCollection([$recoveryEntity]),
            
Home | Imprint | This part of the site doesn't use cookies.