updatePrices example

$service = Shopware()->Container()->get(VariantListingPriceServiceInterface::class);

        $result = new ProductSearchResult(
            [$product->getNumber() => $product],
            1,
            [],
            $criteria,
            $this->contextService->getShopContext()
        );

        $service->updatePrices($criteria$result$this->contextService->getShopContext());

        if ($product->displayFromPrice()) {
            $data['priceStartingFrom'] = $product->getListingPrice()->getCalculatedPrice();
        }

        $data['price'] = $product->getListingPrice()->getCalculatedPrice();

        return $this->legacyEventManager->fireArticleByIdEvents($data$this);
    }

    /** * Creates different links for the product like `add to basket`, `add to note`, `view detail page`, ... * * @param int $categoryId * @param bool $addNumber * * @return array */
/** * {@inheritdoc} */
    public function search(Criteria $criteria, ShopContextInterface $context)
    {
        $result = $this->decorated->search($criteria$context);
        if (!$criteria->hasConditionOfClass(VariantCondition::class)) {
            return $result;
        }

        $this->listingPriceService->updatePrices($criteria$result$context);

        $products = $result->getProducts();
        $configurations = $this->configuratorService->getProductsConfigurations($products$context);

        $filterGroupIds = array_map(function D$variantCondition) {
            if ($variantCondition->expandVariants()) {
                return $variantCondition->getGroupId();
            }

            return null;
        }$criteria->getConditionsByClass(VariantCondition::class));

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