setProducts example

$this->eventDispatcher->dispatch(
            new ProductCrossSellingStreamCriteriaEvent($crossSelling$criteria$context)
        );

        $searchResult = $this->listingLoader->load($criteria$context);

        /** @var ProductCollection $products */
        $products = $searchResult->getEntities();

        $element = new CrossSellingElement();
        $element->setCrossSelling($crossSelling);
        $element->setProducts($products);
        $element->setStreamId($crossSelling->getProductStreamId());

        $element->setTotal($products->count());

        return $element;
    }

    private function loadByIds(ProductCrossSellingEntity $crossSelling, SalesChannelContext $context, Criteria $criteria): CrossSellingElement
    {
        $element = new CrossSellingElement();
        $element->setCrossSelling($crossSelling);
        

        $product1 = new SalesChannelProductEntity();
        $product1->setUniqueIdentifier('product1');

        $product2 = new SalesChannelProductEntity();
        $product2->setUniqueIdentifier('product2');

        $products = new ProductCollection([$product1$product2]);

        $category = new CategoryEntity();
        $category->setUniqueIdentifier('category1');
        $category->setProducts($products);

        $resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class)new Request()$this->createMock(CategoryDefinition::class)$category);

        $fieldConfig = new FieldConfigCollection();
        $fieldConfig->add(new FieldConfig('products', FieldConfig::SOURCE_MAPPED, 'category.products'));

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('product-slider');
        $slot->setFieldConfig($fieldConfig);

        
$struct->setMaxAmount((float) ($data['invoice_amount_max'] ?? 0.0));
        $struct->setAvgProductPrice((float) ($data['product_avg'] ?? 0.0));
        $struct->setFirstOrderTime(isset($data['first_order_time']) ? new DateTime($data['first_order_time']) : null);
        $struct->setLastOrderTime(isset($data['last_order_time']) ? new DateTime($data['last_order_time']) : null);
        $struct->setPayments(array_map('\intval', $this->explodeAndFilter($data['selected_payments'] ?? '')));
        $struct->setShops(array_map('\intval', $this->explodeAndFilter($data['ordered_in_shops'] ?? '')));
        $struct->setDevices($this->explodeAndFilter($data['ordered_with_devices'] ?? ''));
        $struct->setDispatches(array_map('\intval', $this->explodeAndFilter($data['selected_dispachtes'] ?? '')));
        $struct->setWeekdays($this->explodeAndFilter($data['weekdays'] ?? ''));

        if (\array_key_exists('product_numbers', $data)) {
            $struct->setProducts($this->explodeAndFilter($data['product_numbers'] ?? ''));
        }
        if (\array_key_exists('category_ids', $data)) {
            $struct->setCategories(array_map('\intval', $this->explodeAndFilter($data['category_ids'] ?? '')));
        }
        if (\array_key_exists('manufacturer_ids', $data)) {
            $struct->setManufacturers(array_map('\intval', $this->explodeAndFilter($data['manufacturer_ids'] ?? '')));
        }

        return $struct;
    }

    


        if ($productConfig->isStatic()) {
            $this->enrichFromSearch($slider$result, self::STATIC_SEARCH_KEY . '_' . $slot->getUniqueIdentifier()$resolverContext->getSalesChannelContext());
        }

        if ($productConfig->isMapped() && $resolverContext instanceof EntityResolverContext) {
            $products = $this->resolveEntityValue($resolverContext->getEntity()$productConfig->getStringValue());
            if ($products === null) {
                $this->enrichFromSearch($slider$result, self::PRODUCT_SLIDER_ENTITY_FALLBACK . '_' . $slot->getUniqueIdentifier()$resolverContext->getSalesChannelContext());
            } else {
                $slider->setProducts($products);
            }
        }

        if ($productConfig->isProductStream() && $productConfig->getValue()) {
            $entitySearchResult = $result->get(self::PRODUCT_SLIDER_ENTITY_FALLBACK . '_' . $slot->getUniqueIdentifier());
            if ($entitySearchResult === null) {
                return;
            }

            /** @var ProductCollection $streamResult */
            $streamResult = $entitySearchResult->getEntities();

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