getProducts example

new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()])
            );

            $category = $context->getShop()->getCategory()->getId();
            $criteria->addBaseCondition(
                new CategoryCondition([$category])
            );

            $result = Shopware()->Container()->get(ProductSearchInterface::class)
                ->search($criteria$context);

            $products = array_values($result->getProducts());
            $products = array_map(function DListProduct $product) {
                $cheapestPrice = $product->getCheapestPrice();
                if (!$cheapestPrice instanceof Price) {
                    return $product;
                }
                $price = $cheapestPrice->getCalculatedPrice();
                $product = json_decode(json_encode($product, JSON_THROW_ON_ERROR), true);
                $product['cheapestPrice'] = $price;

                return $product;
            }$products);

            
static::assertCount(4, $mapping);

        // test many to many not loaded automatically         $categories = $repository->search(new Criteria([$id1$id2])$context);

        /** @var CategoryEntity $category1 */
        $category1 = $categories->get($id1);
        /** @var CategoryEntity $category2 */
        $category2 = $categories->get($id2);

        static::assertInstanceOf(CategoryEntity::class$category1);
        static::assertNull($category1->getProducts());

        static::assertInstanceOf(CategoryEntity::class$category2);
        static::assertNull($category2->getProducts());
    }

    public function testLoadNestedAssociation(): void
    {
        $manufacturerId = Uuid::randomHex();
        $productId = Uuid::randomHex();
        $categoryId = Uuid::randomHex();

        
private readonly QuantityPriceCalculator $calculator,
        private readonly ProductFeatureBuilder $featureBuilder,
        private readonly AbstractProductPriceCalculator $priceCalculator,
        private readonly EntityCacheKeyGenerator $generator,
        private readonly Connection $connection
    ) {
    }

    public function collect(CartDataCollection $data, Cart $original, SalesChannelContext $context, CartBehavior $behavior): void
    {
        Profiler::trace('cart::product::collect', function D) use ($data$original$context$behavior): void {
            $lineItems = $this->getProducts($original->getLineItems());

            $items = array_column($lineItems, 'item');

            // find products in original cart which requires data from gateway             $ids = $this->getNotCompleted($data$items$context);

            if (!empty($ids)) {
                // fetch missing data over gateway                 $products = $this->productGateway->get($ids$context);

                // add products to data collection
throw RoutingException::missingRequestParameter('number');
            }

            $criteria = new Criteria();
            $criteria->setLimit(1);
            $criteria->addFilter(new EqualsFilter('productNumber', $number));
            $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
                new EqualsFilter('childCount', 0),
                new EqualsFilter('childCount', null),
            ]));

            $data = $this->productListRoute->load($criteria$context)->getProducts()->getIds();

            if (empty($data)) {
                $this->addFlash(self::DANGER, $this->trans(
                    'error.productNotFound',
                    ['%number%' => $this->htmlSanitizer->sanitize($number, null, true)]
                ));

                return $this->createActionResponse($request);
            }

            /** @var string $productId */
            
'invoice_amount_avg' => (float) $customer->getOrderInformation()->getAvgAmount(),
            'invoice_amount_min' => (float) $customer->getOrderInformation()->getMinAmount(),
            'invoice_amount_max' => (float) $customer->getOrderInformation()->getMaxAmount(),
            'first_order_time' => $this->formatDate($customer->getOrderInformation()->getFirstOrderTime()),
            'last_order_time' => $this->formatDate($customer->getOrderInformation()->getLastOrderTime()),
            'has_canceled_orders' => $customer->getOrderInformation()->hasCanceledOrders(),
            'ordered_at_weekdays' => $this->implodeUnique($customer->getOrderInformation()->getWeekdays()),
            'ordered_in_shops' => $this->implodeUnique($customer->getOrderInformation()->getShops()),
            'ordered_on_devices' => $this->implodeUnique($customer->getOrderInformation()->getDevices()),
            'ordered_with_deliveries' => $this->implodeUnique($customer->getOrderInformation()->getDispatches()),
            'ordered_with_payments' => $this->implodeUnique($customer->getOrderInformation()->getPayments()),
            'ordered_products' => $this->implodeUnique($customer->getOrderInformation()->getProducts()),
            'ordered_products_of_categories' => $this->implodeUnique($customer->getOrderInformation()->getCategories()),
            'ordered_products_of_manufacturer' => $this->implodeUnique($customer->getOrderInformation()->getManufacturers()),
        ];

        return $data;
    }

    private function createInsertQuery()
    {
        return $this->connection->prepare(
            'INSERT INTO s_customer_search_index ( id, email, active, accountmode, firstlogin, newsletter, shop_id, default_billing_address_id, title, salutation, firstname, lastname, birthday, customernumber, customer_group_id, customer_group_name, payment_id, company, department, street, zipcode, city, phone, additional_address_line1, additional_address_line2, country_id, country_name, state_id, age, count_orders , invoice_amount_sum, invoice_amount_avg, invoice_amount_min, invoice_amount_max, first_order_time, last_order_time, has_canceled_orders, ordered_at_weekdays, ordered_in_shops, ordered_on_devices, ordered_with_deliveries, ordered_with_payments, product_avg, ordered_products, ordered_products_of_categories, ordered_products_of_manufacturer, index_time ) VALUES ( :id, :email, :active, :accountmode, :firstlogin, :newsletter, :shop_id, :default_billing_address_id, :title, :salutation, :firstname, :lastname, :birthday, :customernumber, :customer_group_id, :customer_group_name, :payment_id, :company, :department, :street, :zipcode, :city, :phone, :additional_address_line1, :additional_address_line2, :country_id, :country_name, :state_id, :age, :count_orders, :invoice_amount_sum, :invoice_amount_avg, :invoice_amount_min, :invoice_amount_max, :first_order_time, :last_order_time, :has_canceled_orders, :ordered_at_weekdays, :ordered_in_shops, :ordered_on_devices, :ordered_with_deliveries, :ordered_with_payments, :product_avg, :ordered_products, :ordered_products_of_categories, :ordered_products_of_manufacturer, NOW() )'
return array_map(EntityCacheKeyGenerator::buildStreamTag(...)$ids);
    }

    /** * @return array<string> */
    private function extractProductIds(ProductCrossSellingRouteResponse $response): array
    {
        $ids = [];

        foreach ($response->getResult() as $element) {
            $ids = [...$ids, ...$element->getProducts()->getIds()];
        }

        $ids = array_unique(array_filter($ids));

        return array_map(EntityCacheKeyGenerator::buildProductTag(...)$ids);
    }
}


    /** * {@inheritdoc} */
    public function search(
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        $numberResult = $this->searchGateway->search($criteria$context);

        $numbers = array_keys($numberResult->getProducts());
        $products = $this->productService->getList($numbers$context);
        $products = $this->assignAttributes($products$numberResult->getProducts());

        $result = new ProductSearchResult(
            $products,
            $numberResult->getTotalCount(),
            $numberResult->getFacets(),
            $criteria,
            $context
        );

        
foreach ($slots as $slot) {
            $slider = $slot->getData();

            if (!$slider instanceof ProductSliderStruct) {
                continue;
            }

            if ($slider->getStreamId() !== null) {
                $streamIds[] = $slider->getStreamId();
            }

            if ($slider->getProducts() === null) {
                continue;
            }
            foreach ($slider->getProducts() as $product) {
                $ids[] = $product->getId();
                $ids[] = $product->getParentId();
            }
        }

        $slots = $page->getElementsOfType('product-box');
        /** @var CmsSlotEntity $slot */
        foreach ($slots as $slot) {
            

    public function search(SearchBundle\Criteria $criteria, ShopContextInterface $context)
    {
        $query = $this->queryBuilderFactory->createProductQuery($criteria$context);

        $products = $this->getProducts($query);

        $total = \count($products);
        if ($criteria->fetchCount()) {
            $total = $this->getTotalCount($query);
        }

        $facets = $this->createFacets($criteria$context);

        return new SearchBundle\ProductNumberSearchResult($products(int) $total$facets);
    }

    

    public function findGroupPackages(array $groupDefinitions, Cart $cart, SalesChannelContext $context): LineItemGroupBuilderResult
    {
        $result = new LineItemGroupBuilderResult();

        // filter out all promotion items         $cartProducts = $this->lineItemProvider->getProducts($cart);

        // split quantities into separate line items         // so we have a real list of products like we would have         // them when holding it in our actual hands.         $restOfCart = $this->splitQuantities($cartProducts$context);

        foreach ($groupDefinitions as $groupDefinition) {
            $sorter = $this->registry->getSorter($groupDefinition->getSorterKey());
            $packager = $this->registry->getPackager($groupDefinition->getPackagerKey());

            // we have to sort our items first

        return 'product';
    }

    /** * {@inheritdoc} * * @throws \Exception */
    public function getUrls(SalesChannelContext $context, int $limit, ?int $offset = null): UrlResult
    {
        $products = $this->getProducts($context$limit$offset);

        if (empty($products)) {
            return new UrlResult([], null);
        }

        $keys = FetchModeHelper::keyPair($products);

        $seoUrls = $this->getSeoUrls(array_values($keys), 'frontend.detail.page', $context$this->connection);

        $seoUrls = FetchModeHelper::groupUnique($seoUrls);

        
$context = $this->contextService->getShopContext();

        $criteria = $this->storeFrontCriteriaFactory->createBaseCriteria([$category]$context);
        $criteria->limit($sLimitChart);

        $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));

        $criteria->setFetchCount(false);

        $result = $this->searchService->search($criteria$context);
        $products = $this->legacyStructConverter->convertListProductStructList($result->getProducts());

        Shopware()->Events()->notify(
            'Shopware_Modules_Articles_GetArticleCharts',
            ['subject' => $this, 'category' => $category, 'articles' => $products]
        );

        return $products;
    }

    /** * Check if a product has an instant download * * @deprecated in 5.5, this function will be removed in 5.7 without replacement * * @param int $id s_articles.id * @param int $detailsID s_articles_details.id * @param bool $realtime * * @return bool */
break;
            case 'topseller':
                $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                break;
            case 'newcomer':
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                break;
        }

        /** @var ProductSearchResult $result */
        $result = Shopware()->Container()->get(ProductSearchInterface::class)->search($criteria$context);
        $data = Shopware()->Container()->get(LegacyStructConverter::class)->convertListProductStructList($result->getProducts());

        $count = $result->getTotalCount();
        if ($limit !== 0) {
            $pages = round($count / $limit);
        } else {
            $pages = 0;
        }

        if ($pages === 0 && $count > 0) {
            $pages = 1;
        }

        

    private function readProductUrlsRecursive(Criteria $criteria)
    {
        $result = [];
        $criteria->limit($this->batchSize);

        $productNumberSearchResult = $this->productNumberSearch->search(
            $criteria,
            $this->contextService->getShopContext()
        );

        $products = $productNumberSearchResult->getProducts();

        if (empty($products)) {
            return $result;
        }

        foreach ($products as $product) {
            $result[] = $product->getId();
        }

        sort($result, SORT_NUMERIC);

        
$context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $criteria = $this->container->get(CriteriaFactoryInterface::class)
            ->createCriteria($this->Request()$context);

        $this->container->get(Repository::class)->prepareCriteria($criteria$streamId);

        $products = $this->container->get(ProductSearchInterface::class)->search($criteria$context);

        $convertedProducts = $this->container->get(LegacyStructConverter::class)
            ->convertListProductStructList($products->getProducts());

        $this->View()->assign(['sArticles' => $convertedProducts, 'articles' => $convertedProducts]);
    }

    /** * Tag cloud by category * * @return void */
    public function tagCloudAction()
    {
        
Home | Imprint | This part of the site doesn't use cookies.