getBatchRequest example

return $this->connection->createQueryBuilder()
            ->select(['id'])
            ->from('s_media')
            ->where('path in (:paths)')
            ->setParameter('paths', $mediaPaths, Connection::PARAM_STR_ARRAY)
            ->execute()
            ->fetchAll(PDO::FETCH_COLUMN);
    }

    private function resolveBatchRequest(PrepareDataCollection $prepareDataCollection, ShopContextInterface $context): BatchProductSearchResult
    {
        $request = $prepareDataCollection->getBatchRequest();

        return $this->batchProductSearch->search($request$context);
    }
}


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

        if ($type === self::TYPE_STATIC_PRODUCT) {
            $collection->getBatchRequest()->setProductNumbers($key[$element->getConfig()->get('article')]);

            return;
        }

        if ($type === self::TYPE_STATIC_VARIANT) {
            $collection->getBatchRequest()->setProductNumbers($key[$element->getConfig()->get('variant')]);

            return;
        }

        $criteria = $this->generateCriteria($element$context);

        
$isBlog = (bool) $element->getConfig()->get('blog_category');
                $categoryId = (int) $element->getConfig()->get('category_selection');

                if ($isBlog) {
                    break;
                }

                $criteria = $this->criteriaFactory->createBaseCriteria([$categoryId]$context);
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                $criteria->limit(50);

                $collection->getBatchRequest()->setCriteria($key$criteria);
                break;
        }
    }

    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $imageType = $element->getConfig()->get('image_type');
        $key = ComponentHandlerInterface::CRITERIA_KEY . $element->getId();

        switch ($imageType) {
            case self::TYPE_IMAGE:
                
$mappingKey = $this->getMappingKey($mapping);
            $mappingKey = 'emotion-banner--' . $element->getId() . '-' . $mappingKey;

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

            if ($isLink) {
                $mapping['link'] = $context->getShop()->getUrl() . $mapping['link'];
            } else {
                // link is actually a product number                 $mapping['ordernumber'] = $mapping['link'];
                $collection->getBatchRequest()->setProductNumbers($mappingKey[$mapping['ordernumber']]);
            }

            $mappings[$key] = $mapping;
        }

        $element->getConfig()->set('bannerMapping', $mappings);
    }

    private function resolveMappings(ResolvedDataCollection $collection, Element $element): void
    {
        $mappings = $element->getConfig()->get('bannerMapping', []);

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

        switch ($type) {
            case self::TYPE_PRODUCT_STREAM:
                $criteria = $this->generateCriteria($element$context);

                $productStreamId = $element->getConfig()->get('article_slider_stream');
                $this->productStreamRepository->prepareCriteria($criteria$productStreamId);

                // request multiple products by criteria                 $collection->getBatchRequest()->setCriteria($key$criteria);
                break;

            case self::TYPE_TOPSELLER:
            case self::TYPE_NEWCOMER:
            case self::TYPE_RANDOM:
            case self::TYPE_LOWEST_PRICE:
            case self::TYPE_HIGHEST_PRICE:
                $criteria = $this->generateCriteria($element$context);

                // request multiple products by criteria                 $collection->getBatchRequest()->setCriteria($key$criteria);
                
Home | Imprint | This part of the site doesn't use cookies.