getBatchResult example

$media = array_shift($medias);
                    if (!$media instanceof Media) {
                        break;
                    }

                    $element->getData()->set('blog', $blog);
                    $element->getData()->set('image', $media);
                    $element->getData()->set('images', $media->getThumbnails());
                    break;
                }

                $products = $collection->getBatchResult()->get($key);
                shuffle($products);

                $product = reset($products);

                if (!$product instanceof ListProduct || !$product->getCover() instanceof Media) {
                    break;
                }

                $element->getData()->set('image', $product->getCover());
                $element->getData()->set('images', $product->getCover()->getThumbnails());
                break;
        }
        $collection->getBatchRequest()->setCriteria($key$criteria);
    }

    /** * {@inheritdoc} */
    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $key = ComponentHandlerInterface::CRITERIA_KEY . $element->getId();
        $type = $element->getConfig()->get('article_type');

        $product = current($collection->getBatchResult()->get($key));
        if ($product && $type === self::TYPE_STATIC_VARIANT) {
            $product = $this->additionalTextService->buildAdditionalText($product$context);
            $this->switchPrice($product);
        }
        $element->getData()->set('product', $product);
    }

    private function switchPrice(ListProduct $product): void
    {
        $prices = array_values($product->getPrices());
        $product->setListingPrice($prices[0]);

        

        $type = $element->getConfig()->get('article_slider_type', self::TYPE_STATIC_PRODUCT);
        $key = ComponentHandlerInterface::CRITERIA_KEY . $element->getId();

        switch ($type) {
            case self::TYPE_PRODUCT_STREAM:
            case self::TYPE_NEWCOMER:
            case self::TYPE_RANDOM:
            case self::TYPE_TOPSELLER:
            case self::TYPE_HIGHEST_PRICE:
            case self::TYPE_LOWEST_PRICE:
                $requestedProducts = $collection->getBatchResult()->get($key);
                $element->getData()->set('products', $requestedProducts);
                break;

            case self::TYPE_STATIC_PRODUCT:
                $products = $element->getConfig()->get(self::SELECTED_PRODUCTS, '') ?? '';
                $productNumbers = array_filter(explode('|', $products));
                $listProducts = $collection->getBatchResult()->get($key);

                $products = [];
                foreach ($productNumbers as $productNumber) {
                    if (!$listProducts[$productNumber] instanceof ListProduct) {
                        
if (!empty($matches)) {
                continue;
            }

            $isLink = strpos($mapping['link'], '/') === 0;

            if (!$isLink) {
                $mappingKey = $this->getMappingKey($mapping);
                $mappingKey = 'emotion-banner--' . $element->getId() . '-' . $mappingKey;

                $products = $collection->getBatchResult()->get($mappingKey);
                $product = reset($products);
                if (!$product) {
                    continue;
                }

                $mapping['link'] = Shopware()->Container()->get(Shopware_Components_Config::class)->get('baseFile') . '?sViewport=detail&sArticle=' . $product->getId() . '&number=' . $product->getNumber();
            }

            $mappings[$key] = $mapping;
        }

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