switchPrice example

$products = $element->getConfig()->get(self::SELECTED_VARIANTS, '') ?? '';
                $productNumbers = array_filter(explode('|', $products));
                $listProducts = $collection->getBatchResult()->get($key);
                $listProducts = $this->additionalTextService->buildAdditionalTextLists($listProducts$context);

                $products = [];
                foreach ($productNumbers as $productNumber) {
                    $product = $listProducts[$productNumber];
                    if (!$product instanceof ListProduct) {
                        continue;
                    }
                    $this->switchPrice($product);
                    $products[$productNumber] = $product;
                }

                $element->getData()->set('products', $products);
                break;
        }
    }

    private function switchPrice(ListProduct $product): void
    {
        $prices = array_values($product->getPrices());
        
/** * {@inheritdoc} */
    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $key = ComponentHandlerInterface::CRITERIA_KEY . $element->getId();
        $type = $element->getConfig()->get('article_type');

        $product = current($collection->getBatchResult()->get($key));
        if ($product && $type === self::TYPE_STATIC_VARIANT) {
            $product = $this->additionalTextService->buildAdditionalText($product$context);
            $this->switchPrice($product);
        }
        $element->getData()->set('product', $product);
    }

    private function switchPrice(ListProduct $product): void
    {
        $prices = array_values($product->getPrices());
        $product->setListingPrice($prices[0]);

        $product->setDisplayFromPrice(\count($product->getPrices()) > 1);

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