assignAttributes example

/** * @param ListProduct[] $listProducts * * @return BatchProductSearchResult */
    private function mapListProducts(BatchProductNumberSearchResult $searchResult, array $listProducts)
    {
        $result = [];

        foreach ($searchResult->getAll() as $key => $baseProducts) {
            $products = array_intersect_key($listProducts$baseProducts);
            $products = $this->assignAttributes($products$baseProducts);

            $result[$key] = $products;
        }

        return new BatchProductSearchResult($result);
    }

    /** * @param array<string, Struct\ListProduct|null> $products * @param Struct\BaseProduct[] $searchProducts * * @return Struct\ListProduct[] */
/** * {@inheritdoc} */
    public function search(
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        $numberResult = $this->searchGateway->search($criteria$context);

        $numbers = array_keys($numberResult->getProducts());
        $products = $this->productService->getList($numbers$context);
        $products = $this->assignAttributes($products$numberResult->getProducts());

        $result = new ProductSearchResult(
            $products,
            $numberResult->getTotalCount(),
            $numberResult->getFacets(),
            $criteria,
            $context
        );

        $result->addAttributes($numberResult->getAttributes());

        
Home | Imprint | This part of the site doesn't use cookies.