setProductNumbers example

$medias = $this->getMediaQuery(array_column($data, '__blog_id'))
            ->execute()
            ->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_COLUMN);

        $blogs = [];
        foreach ($data as $row) {
            $id = (int) $row['__blog_id'];

            $blog = $this->blogHydrator->hydrate($row);

            if (\array_key_exists($id$articles)) {
                $blog->setProductNumbers($articles[$id]);
            }

            if (\array_key_exists($id$medias)) {
                $blog->setMediaIds($medias[$id]);
            }

            $blogs[$id] = $blog;
        }

        return $blogs;
    }

    
$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', []);

        


    /** * {@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);

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

            case self::TYPE_STATIC_PRODUCT:
                $products = $element->getConfig()->get(self::SELECTED_PRODUCTS, '') ?? '';
                $productNumbers = array_filter(explode('|', $products));
                if (empty($productNumbers)) {
                    $productNumbers = [];
                }

                $collection->getBatchRequest()->setProductNumbers($key$productNumbers);
                break;
            case self::TYPE_STATIC_VARIANT:
                $productVariants = $element->getConfig()->get(self::SELECTED_VARIANTS, '') ?? '';
                $productNumbers = array_filter(explode('|', $productVariants));
                if (empty($productNumbers)) {
                    $productNumbers = [];
                }

                $collection->getBatchRequest()->setProductNumbers($key$productNumbers);
                break;
        }
    }
Home | Imprint | This part of the site doesn't use cookies.