getCategoryId example

case Shopware\Models\Article\Detail::class:
                $cacheIds[] = 'a' . $entity->getArticleId();
                break;

            case Shopware\Models\Category\Category::class:
                $cacheIds[] = 'c' . $entity->getId();
                break;

            case Shopware\Models\Blog\Blog::class:
            case Shopware\Models\Banner\Banner::class:
                $cacheIds[] = 'c' . $entity->getCategoryId();
                break;

            case Shopware\Models\Emotion\Emotion::class:
                $cacheIds[] = 'e' . $entity->getId();
                break;

            case Shopware\Models\Site\Site::class:
                $cacheIds[] = 's' . $entity->getId();
                break;
            case Shopware\Models\Form\Form::class:
                $cacheIds[] = 'f' . $entity->getId();
                

    public function convertBlogStruct(Blog $blog)
    {
        $data = [
            'id' => $blog->getId(),
            'title' => $blog->getTitle(),
            'authorId' => $blog->getAuthorId(),
            'active' => $blog->isActive(),
            'shortDescription' => $blog->getShortDescription(),
            'description' => $blog->getDescription(),
            'displayDate' => $blog->getDisplayDate(),
            'categoryId' => $blog->getCategoryId(),
            'template' => $blog->getTemplate(),
            'metaKeyWords' => $blog->getMetaKeywords(),
            'metaKeywords' => $blog->getMetaKeywords(),
            'metaDescription' => $blog->getMetaDescription(),
            'metaTitle' => $blog->getMetaTitle(),
            'views' => $blog->getViews(),
            'mediaList' => array_map([$this, 'convertMediaStruct']$blog->getMedias()),
            'attributes' => $blog->getAttributes(),
        ];

        if ($blog->hasAttribute('core')) {
            
$criteria->addFilter(new EqualsFilter('name', 'system'));

        $result = $this->getContainer()->get('category_translation.repository')->search($criteria, Context::createDefaultContext());

        static::assertEquals(1, $result->getTotal());
        static::assertEquals(1, $result->count());

        /** @var CategoryTranslationEntity $translation */
        $translation = $result->first();
        static::assertEquals('system', $translation->getName());
        static::assertEquals(Defaults::LANGUAGE_SYSTEM, $translation->getLanguageId());
        static::assertEquals($id$translation->getCategoryId());
    }

    /** * @dataProvider casesToManyPaginated * * @param list<array<string, mixed>> $data * @param callable(Criteria): void $modifier * @param list<string> $expected */
    public function testLoadToManyPaginated(array $data, callable $modifier, array $expected): void
    {
        
/** * @extends EntityCollection<CategoryTranslationEntity> */
#[Package('content')] class CategoryTranslationCollection extends EntityCollection
{
    /** * @return list<string> */
    public function getCategoryIds(): array
    {
        return $this->fmap(fn (CategoryTranslationEntity $categoryTranslation) => $categoryTranslation->getCategoryId());
    }

    public function filterByCategoryId(string $id): self
    {
        return $this->filter(fn (CategoryTranslationEntity $categoryTranslation) => $categoryTranslation->getCategoryId() === $id);
    }

    /** * @return list<string> */
    public function getLanguageIds(): array
    {
$product = $this->productRepository->search($criteria$salesChannelContext->getContext())->first();

        static::assertNotNull($product->getMainCategories());
        static::assertInstanceOf(MainCategoryCollection::class$product->getMainCategories());
        $mainCategories = $product->getMainCategories();
        static::assertCount(1, $mainCategories);

        $mainCategory = $mainCategories->filterBySalesChannelId($salesChannelId)->first();
        static::assertInstanceOf(MainCategoryEntity::class$mainCategory);
        static::assertEquals($salesChannelId$mainCategory->getSalesChannelId());
        static::assertEquals($categories->firstId()$mainCategory->getCategoryId());
    }

    private function createTestProduct(): string
    {
        $id = Uuid::randomHex();
        $payload = [
            'id' => $id,
            'name' => 'foo bar',
            'manufacturer' => [
                'id' => Uuid::randomHex(),
                'name' => 'amazing brand',
            ],
Home | Imprint | This part of the site doesn't use cookies.