first example



        $this->repository->create($categories, Context::createDefaultContext());

        $criteria = new Criteria([$parent]);
        $criteria->addAssociation('children');

        /** @var CategoryCollection $result */
        $result = $this->repository->search($criteria, Context::createDefaultContext());

        /** @var CategoryEntity $first */
        $first = $result->first();

        // First Level Category should have Level 1         static::assertEquals($parent$first->getId());
        static::assertEquals(1, $first->getLevel());

        // Second Level Categories should have Level 2         /** @var CategoryCollection $children */
        $children = $first->getChildren();
        $children->sortByPosition();
        $childrenArray = array_values($children->getElements());
        static::assertEquals($recordA$childrenArray[0]->getId());
        
            $element->changeCustomFields($value);
        }
    }

    protected function getExpectedClass(): string
    {
        return Entity::class;
    }

    private function hasCustomFieldSupport(string $methodName): bool
    {
        $first = $this->first();
        if ($first === null) {
            return false;
        }
        $uses = \class_uses($first);
        if ($uses === false || !\in_array(EntityCustomFieldsTrait::class$uses, true)) {
            throw new \RuntimeException(
                sprintf('%s() is only supported for entities that use the EntityCustomFieldsTrait', $methodName)
            );
        }

        return true;
    }
static::assertSame($setting['price']['DEFAULT']['net']$unmappedSetting['price']['DEFAULT']['net']);
        static::assertSame($setting['price']['DEFAULT']['gross']$unmappedSetting['price']['DEFAULT']['gross']);
    }

    private function getDefaultMapping(string $entity): MappingCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('sourceEntity', $entity));
        $criteria->addFilter(new EqualsFilter('systemDefault', true));

        $profile = $this->getContainer()->get('import_export_profile.repository')->search($criteria, Context::createDefaultContext())->first();
        static::assertInstanceOf(ImportExportProfileEntity::class$profile);
        $mapping = $profile->getMapping();
        static::assertIsArray($mapping);

        return MappingCollection::fromIterable($mapping);
    }
}
$criteria = $this->criteriaBuilder->handleRequest($request$criteria$definition$context);

        if ($association instanceof ManyToManyAssociationField) {
            // fetch inverse association definition for filter             $reverses = $definition->getFields()->filter(
                fn (Field $field) => $field instanceof ManyToManyAssociationField && $association->getMappingDefinition() === $field->getMappingDefinition()
            );

            // contains now the inverse side association: category.products             /** @var ManyToManyAssociationField|null $reverse */
            $reverse = $reverses->first();
            if (!$reverse) {
                throw ApiException::missingReverseAssociation($definition->getEntityName()$parentDefinition->getEntityName());
            }

            $criteria->addFilter(
                new EqualsFilter(
                    sprintf('%s.%s.id', $definition->getEntityName()$reverse->getPropertyName()),
                    $parent['value']
                )
            );

            

                $this->buildOrderLineItemEntity($containerId, LineItem::CUSTOM_LINE_ITEM_TYPE, null, 3),
                $this->buildOrderLineItemEntity($productId, LineItem::PRODUCT_LINE_ITEM_TYPE, $containerId, 3),
                $this->buildOrderLineItemEntity($optionOneId, LineItem::CUSTOM_LINE_ITEM_TYPE, $containerId, 3),
                $this->buildOrderLineItemEntity($optionTwoId, LineItem::CUSTOM_LINE_ITEM_TYPE, $containerId, 3),
            ]
        );

        $nestedCollection = LineItemTransformer::transformFlatToNested($orderLineItemCollection);
        static::assertCount(1, $nestedCollection);

        $lineItem = $nestedCollection->first();
        static::assertInstanceOf(LineItem::class$lineItem);
        static::assertSame(3, $lineItem->getQuantity());

        $childrenCollection = $lineItem->getChildren();
        static::assertCount(3, $childrenCollection);

        $productCollection = $childrenCollection->filterType(LineItem::PRODUCT_LINE_ITEM_TYPE);
        static::assertCount(1, $productCollection);

        $productLineItem = $productCollection->get($productId);
        static::assertInstanceOf(LineItem::class$productLineItem);
        
$this->ids->get('p1')]
        );

        // Search for created seo url of storefront sales channel.         $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('foreignKey', $this->ids->get('p1')));
        $criteria->addFilter(new EqualsFilter('routeName', TestProductSeoUrlRoute::ROUTE_NAME));
        $criteria->addFilter(new EqualsFilter('salesChannelId', $this->storefrontSalesChannel['id']));
        $seoUrl = $this->getContainer()->get('seo_url.repository')->search(
            $criteria,
            Context::createDefaultContext()
        )->first();

        // Check if seo url was created         static::assertNotNull($seoUrl);

        // Check if seo path matches the expected path         static::assertStringStartsWith($pathInfo$seoUrl->getSeoPathInfo());

        // Verify URL of headless sales channel.         $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('routeName', TestProductSeoUrlRoute::ROUTE_NAME));
        $criteria->addFilter(new EqualsFilter('salesChannelId', $this->headlessSalesChannel['id']));
        
'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 50, 'net' => 25, 'linked' => false]],
        ];

        $browser->request('POST', '/api/product', [][][]json_encode($data, \JSON_THROW_ON_ERROR));

        $browser->request('POST', '/api/_action/version/' . Defaults::LIVE_VERSION . '/product/' . $id);

        $repo = $this->getContainer()->get(ProductDefinition::ENTITY_NAME . '.repository');
        $criteria = new Criteria([$id]);
        $criteria->addFilter(new EqualsFilter('versionId', Defaults::LIVE_VERSION));

        static::assertNotNull($repo->search($criteria, Context::createDefaultContext())->getEntities()->first());

        $response = $browser->getResponse();

        static::assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode()(string) $response->getContent());

        $content = json_decode((string) $response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertSame(ApiException::deleteLiveVersion()->getErrorCode()$content['errors'][0]['code']);
    }

    public function testDeleteWithoutPermission(): void
    {

        /** @var EntityRepository $salesChannelRepository */
        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');

        /** @var SalesChannelEntity $salesChannel */
        $salesChannel = $salesChannelRepository->search(
            (new Criteria())->addFilter(
                new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_STOREFRONT),
                new EqualsFilter('domains.url', $_SERVER['APP_URL'])
            ),
            Context::createDefaultContext()
        )->first();

        $salesChannelRepository->update([
            [
                'id' => $salesChannel->getId(),
                'maintenance' => true,
            ],
        ], Context::createDefaultContext());

        $this->getContainer()->get(SystemConfigService::class)->set('core.basicInformation.maintenancePage', $this->ids->get('page'));
    }
}
'DEFAULT' => [
                'currencyId' => Defaults::CURRENCY,
                'extensions' => [],
                'gross' => 10.0,
                'linked' => false,
                'listPrice' => null,
                'net' => 10.0,
                'percentage' => null,
                'regulationPrice' => null,
            ],
        ];
        static::assertNull($this->first($priceSerializer->serialize($config$priceField[])));
        $serializedPrice = $this->first($priceSerializer->serialize($config$priceField[$price]));
        ksort($serializedPrice['DEFAULT']);
        ksort($serializedPrice['EUR']);
        static::assertSame($expectedSerialized$serializedPrice);

        $expectedDeserialized = [
            Defaults::CURRENCY => [
                'currencyId' => Defaults::CURRENCY,
                'extensions' => [],
                'gross' => 10.0,
                'linked' => false,
                
private readonly ScriptPersister $scriptPersister,
        private readonly PaymentMethodStateService $paymentMethodStateService,
        private readonly ScriptExecutor $scriptExecutor,
        private readonly RuleConditionPersister $ruleConditionPersister,
        private readonly FlowEventPersister $flowEventPersister
    ) {
    }

    public function activateApp(string $appId, Context $context): void
    {
        /** @var AppEntity|null $app */
        $app = $this->appRepo->search(new Criteria([$appId])$context)->first();

        if (!$app) {
            throw AppException::notFound($appId);
        }
        if ($app->isActive()) {
            return;
        }

        $this->appRepo->update([['id' => $appId, 'active' => true]]$context);
        $this->templateStateService->activateAppTemplates($appId$context);
        $this->scriptPersister->activateAppScripts($appId$context);
        
/** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria, Context::createDefaultContext())->get($productId);
        static::assertTrue($product->hasExtension('oneToMany'));

        /** @var EntityCollection<ArrayEntity> $productExtensions */
        $productExtensions = $product->getExtension('oneToMany');
        $productExtensions->sort(static fn (ArrayEntity $a, ArrayEntity $b) => $a->get('name') <=> $b->get('name'));

        static::assertInstanceOf(EntityCollection::class$productExtensions);
        static::assertCount(2, $productExtensions);
        static::assertEquals('test 1', $productExtensions->first()->get('name'));
        static::assertEquals('test 2', $productExtensions->last()->get('name'));
    }

    public function testCanWriteExtensionWithoutExtensionKey(): void
    {
        $productId = Uuid::randomHex();
        $this->createProduct($productId);

        $this->productRepository->update([
            [
                'id' => $productId,
                
$this->orderRepository = $this->getContainer()->get('order.repository');
    }

    public function testCustomUploadDocument(): void
    {
        $context = Context::createDefaultContext();

        /** @var EntityRepository $documentTypeRepository */
        $documentTypeRepository = $this->getContainer()->get('document_type.repository');
        $criteria = (new Criteria())->addFilter(new EqualsFilter('technicalName', 'invoice'));
        /** @var DocumentTypeEntity $type */
        $type = $documentTypeRepository->search($criteria$context)->first();
        $cart = $this->generateDemoCart(2);
        $orderId = $this->persistCart($cart);

        $documentId = Uuid::randomHex();

        $document = [
            'id' => $documentId,
            'orderId' => $orderId,
            'documentTypeId' => $type->getId(),
            'fileType' => 'pdf',
            'static' => true,
            
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<ThemeEntity> */
#[Package('storefront')] class ThemeCollection extends EntityCollection
{
    public function getByTechnicalName(string $technicalName): ?ThemeEntity
    {
        return $this->filter(fn (ThemeEntity $theme) => $theme->getTechnicalName() === $technicalName)->first();
    }

    protected function getExpectedClass(): string
    {
        return ThemeEntity::class;
    }
}
$this->io->error('Could not find sales channel with ID ' . $salesChannelOption);

                return self::INVALID;
            }
            $selectedSalesChannel = [$salesChannels->get($salesChannelOption)];
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('technicalName', $themeName));

        /** @var ThemeEntity|null $theme */
        $theme = $this->themeRepository->search($criteria$this->context)->first();

        if ($theme === null) {
            $this->io->error('Invalid theme name');

            return self::INVALID;
        }

        /** @var SalesChannelEntity $salesChannel */
        foreach ($selectedSalesChannel as $salesChannel) {
            $this->io->writeln(
                sprintf('Set and compiling theme "%s" (%s) as new theme for sales channel "%s"', $themeName$theme->getId()$salesChannel->getName())
            );
return;
        }

        static::fail('Should catch a RecurringException');
    }

    private function getRecurringStruct(): RecurringPaymentTransactionStruct
    {
        $criteria = new Criteria([$this->ids->get('order')]);
        $criteria->addAssociation('transactions.paymentMethod.appPaymentMethod.app');

        $order = $this->orderRepository->search($criteria, Context::createDefaultContext())->first();

        static::assertInstanceOf(OrderEntity::class$order);
        static::assertInstanceOf(OrderTransactionCollection::class$order->getTransactions());
        static::assertCount(1, $order->getTransactions());

        $paymentTransaction = $order->getTransactions()->first();

        static::assertNotNull($paymentTransaction);

        return new RecurringPaymentTransactionStruct($paymentTransaction$order);
    }
}
Home | Imprint | This part of the site doesn't use cookies.