getCategoryIds example

static::assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());

        $repo = $this->getContainer()->get(ProductDefinition::ENTITY_NAME . '.repository');
        $criteria = new Criteria([$productId]);

        /** @var ProductEntity $product */
        $product = $repo->search($criteria, Context::createDefaultContext())->getEntities()->first();

        static::assertEquals([
            $categoryId,
        ]$product->getCategoryIds());
    }

    public function testDirectlyAddMappingEntryWithResponse(): void
    {
        $productId = Uuid::randomHex();
        $data = [
            'id' => $productId,
            'productNumber' => Uuid::randomHex(),
            'name' => 'Wool Shirt',
            'tax' => ['name' => 'test', 'taxRate' => 10],
            'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 8300, 'net' => 8300, 'linked' => false]],
            
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(CategoryCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('categoryIds', $criteriaPart->getCategoryIds());
    }
}

    }

    /** * @return int[] */
    private function getFilteredIds(Criteria $criteria): array
    {
        $active = [];
        foreach ($criteria->getUserConditions() as $condition) {
            if ($condition instanceof CategoryCondition) {
                $active = array_merge($active$condition->getCategoryIds());
            }
        }

        return $active;
    }
}
 {
        $categoryCondition = $criteria->getBaseCondition('category');
        if (!$categoryCondition instanceof CategoryCondition) {
            return;
        }

        $search->addSort($this->getSorting($criteriaPart$categoryCondition));
    }

    private function getSorting(ManualSorting $criteriaPart, CategoryCondition $categoryCondition): FieldSort
    {
        $categoryId = $categoryCondition->getCategoryIds()[0];

        // Elasticsearch DSL does not support the new format         // @see: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_nested_sorting_examples         return new FieldSort('manualSorting.position', strtolower($criteriaPart->getDirection())[
            'unmapped_type' => 'integer',
            'nested' => [
                'path' => 'manualSorting',
                'filter' => (new TermsQuery('manualSorting.category_id', [$categoryId]))->toArray(),
            ],
        ]);
    }
}


        return $result;
    }

    /** * @param Emotion[] $emotions */
    private function resolveCategories(array $emotions, ShopContextInterface $context)
    {
        $categoryIds = array_map(function DEmotion $emotion) {
            return $emotion->getCategoryIds();
        }$emotions);

        $categoryIds = array_keys(array_flip(array_merge(...$categoryIds)));
        $categoryIds = array_filter($categoryIds);

        if (empty($categoryIds)) {
            return;
        }

        $categories = $this->categoryService->getList($categoryIds$context);

        
foreach ($customerGroups as $customerGroup) {
            foreach ($currencies as $currency) {
                $contexts[] = $this->contextService->createShopContext($shopId$currency$customerGroup);
            }
        }

        return $contexts;
    }

    private function isValid(Shop $shop$product): bool
    {
        $valid = \in_array($shop->getCategory()->getId()$product->getCategoryIds());
        if (!$valid) {
            return false;
        }

        return true;
    }

    private function getPriceContexts(Shop $shop): array
    {
        $currencies = $this->identifierSelector->getShopCurrencyIds($shop->getId());
        if (!$shop->isMain()) {
            
return $condition instanceof OrderedProductOfCategoryCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(OrderedProductOfCategoryCondition $condition, QueryBuilder $query): void
    {
        $wheres = [];
        foreach ($condition->getCategoryIds() as $i => $id) {
            $wheres[] = 'customer.ordered_products_of_categories LIKE :category' . $i;
            $query->setParameter(':category' . $i, '%|' . $id . '|%');
        }
        $query->andWhere(implode(' OR ', $wheres));
    }
}
return $categoryBreadcrumb;
    }

    public function getProductSeoCategory(ProductEntity $product, SalesChannelContext $context): ?CategoryEntity
    {
        $category = $this->getMainCategory($product$context);

        if ($category !== null) {
            return $category;
        }

        $categoryIds = $product->getCategoryIds() ?? [];
        $productStreamIds = $product->getStreamIds() ?? [];

        if (empty($productStreamIds) && empty($categoryIds)) {
            return null;
        }

        $criteria = new Criteria();
        $criteria->setTitle('breadcrumb-builder');
        $criteria->setLimit(1);
        $criteria->addFilter(new EqualsFilter('active', true));

        
$systemId = $context->getShop()->getCategory()->getId();

        if (!$criteria->hasBaseCondition('category')) {
            $criteria->addBaseCondition(new CategoryCondition([$systemId]));

            return $criteria;
        }

        /** @var CategoryCondition $condition */
        $condition = $criteria->getBaseCondition('category');

        if (!\in_array($systemId$condition->getCategoryIds())) {
            $criteria->removeBaseCondition('category');
            $criteria->addCondition($condition);
            $criteria->addBaseCondition(new CategoryCondition([$systemId]));
        }

        return $criteria;
    }

    /** * @return Criteria */
    
$query->innerJoin(
            'product',
            's_articles_categories_ro',
            $joinName,
            $joinName . ".articleID = product.id AND {$joinName}.categoryID IN (:{$joinName})"
        );

        $query->setParameter(
            ':' . $joinName,
            $condition->getCategoryIds(),
            Connection::PARAM_INT_ARRAY
        );
    }
}

    }

    /** * @return int[] */
    private function getFilteredIds(Criteria $criteria): array
    {
        $active = [];
        foreach ($criteria->getUserConditions() as $condition) {
            if ($condition instanceof CategoryCondition) {
                $active = array_merge($active$condition->getCategoryIds());
            }
        }

        return $active;
    }
}
return $condition instanceof NotOrderedProductOfCategoryCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query): void
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(NotOrderedProductOfCategoryCondition $condition, QueryBuilder $query): void
    {
        $likes = [];
        foreach ($condition->getCategoryIds() as $i => $id) {
            $likes[] = 'ordered_products_of_categories LIKE :category' . $i;
        }

        $query->where('customernumber NOT IN ( SELECT customernumber FROM s_customer_search_index WHERE ' . implode(' OR ', $likes) . ' )'
        );
        foreach ($condition->getCategoryIds() as $i => $id) {
            
'id' => Uuid::randomHex(),
            'productNumber' => Uuid::randomHex(),
            'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => $price, 'net' => $price / $taxRate, 'linked' => true]],
            'purchasePrices' => [['currencyId' => Defaults::CURRENCY, 'gross' => $purchasePrice, 'net' => $purchasePrice / $taxRate, 'linked' => true]],
            'name' => $this->faker->format('productName'),
            'description' => $this->faker->text(),
            'taxId' => $tax->getId(),
            'manufacturerId' => $this->faker->randomElement($manufacturer),
            'active' => true,
            'height' => $this->faker->numberBetween(1, 1000),
            'width' => $this->faker->numberBetween(1, 1000),
            'categories' => $this->getCategoryIds(),
            'tags' => $this->getTags($tags),
            'stock' => $this->faker->numberBetween(1, 50),
        ];
    }

    /** * @param list<string> $rules * * @return list<array<string, mixed>> */
    private function createPrices(array $rules): array
    {
Home | Imprint | This part of the site doesn't use cookies.