setCoverMedia example

$this->fieldHelper->addManufacturerTranslation($query$context);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $medias = $this->mediaService->getList(array_column($data, '__manufacturer_img_id')$context);

        $manufacturers = [];
        foreach ($data as $row) {
            $id = $row['__manufacturer_id'];
            $manufacturers[$id] = $this->manufacturerHydrator->hydrate($row);

            if (!empty($row['__manufacturer_img']) && !empty($medias[$row['__manufacturer_img_id']])) {
                $manufacturers[$id]->setCoverMedia($medias[$row['__manufacturer_img_id']]);
            }
        }

        // sort elements by provided ids, sorting is defined by other queries like `best term match` or `max articles` or `sort alphanumeric`         $sorted = [];
        foreach ($ids as $id) {
            if (!\array_key_exists($id$manufacturers)) {
                continue;
            }
            $sorted[$id] = $manufacturers[$id];
        }

        


            if (isset($voteAverages[$number])) {
                $product->setVoteAverage($voteAverages[$number]);
            }

            if (isset($categories[$number])) {
                $product->setCategories($categories[$number]);
            }

            if ($product->getManufacturer() && isset($manufacturerCovers[$product->getManufacturer()->getCoverId()])) {
                $product->getManufacturer()->setCoverMedia($manufacturerCovers[$product->getManufacturer()->getCoverId()]);
            }

            $product->addAttribute('marketing', $this->marketingService->getProductAttribute($product));

            $this->priceCalculationService->calculateProduct($product$context);

            if (!$this->isProductValid($product$context)) {
                continue;
            }

            $product->setListingPrice($product->getCheapestUnitPrice());
            
Home | Imprint | This part of the site doesn't use cookies.