buildAdditionalText example

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

        
// If product has variants, we need to append the additional text to the name         if ($product['configurator_set_id'] > 0) {
            $productStruct = new ListProduct(
                (int) $product['id'],
                (int) $product['did'],
                $orderNumber
            );

            $productStruct->setAdditional($product['additionaltext']);

            $context = $this->contextService->getShopContext();
            $productStruct = $this->additionalTextService->buildAdditionalText($productStruct$context);

            if (!$returnAll) {
                return $product['articleName'] . ' ' . $productStruct->getAdditional();
            }

            $product['additionaltext'] = $productStruct->getAdditional();
        }

        if (!$returnAll) {
            return $product['articleName'];
        }

        


            $product = new StoreFrontBundle\Struct\ListProduct(
                $premium['articleID'],
                $premium['variantID'],
                $premium['ordernumber']
            );

            $product->setAdditional($premium['additionaltext']);

            $context = $this->contextService->getShopContext();
            $product = $this->additionalTextService->buildAdditionalText($product$context);
            $premium['additionaltext'] = $product->getAdditional();
        }

        if (!empty($premium['configurator_set_id'])) {
            $number = $premium['ordernumber'];
        } else {
            $number = $premium['ordernumber_export'];
        }

        return $this->db->insert(
            's_order_basket',
            [
if (!empty($row['group_ordernumber'])) {
                        foreach ($row['group_ordernumber'] as $orderNumber) {
                            $product = new ListProduct(
                                (int) $row['articleID'],
                                (int) $row['articledetailsID'],
                                $orderNumber
                            );

                            $product->setAdditional($row['additionaltext']);

                            $product = $this->additionalTextService->buildAdditionalText($product$context);

                            if (\array_key_exists($orderNumber$row['group_additionaltext'])) {
                                $row['group_additionaltext'][$orderNumber] = $product->getAdditional();
                            }
                            if ($orderNumber == $row['ordernumber']) {
                                $row['additionaltext'] = $product->getAdditional();
                            }
                        }
                    }
                }
                $product = new ListProduct(
                    
Home | Imprint | This part of the site doesn't use cookies.